org.marketcetera.strategy.util
Class OptionChain

java.lang.Object
  extended by org.marketcetera.strategy.util.OptionChain

@ThreadSafe
public final class OptionChain
extends Object

Represents the option chain of a given underlying instrument.

This object maintains an in-memory representation of the option chain of an underlying instrument and its market data. To use OptionChain, create a new OptionChain (may use any instrument as the underlying instrument of the option chain):

 Equity theEquity = new Equity("GOOG");
 OptionChain theChain = new OptionChain(theEquity);
 
Set up market data for the underlying instrument as normal. As market data events arrive, pass the appropriate ones to the OptionChain:
 public void onAsk(AskEvent ask)
 {
     theChain.process(ask);
 }
 
Note that if the AskEvent is not relevant to the OptionChain, it will be discarded. To take full advantage of the OptionChain object, add similar code to onBid, onTrade, onMarketstat, and onDividend.

The data stored in the OptionChain object can be retrieved as follows:

 List<OptionContractPair> optionChain = theChain.getOptionChain();
 for(OptionContractPair contractPair : optionChain) {
     OptionContract putSide = contractPair.getPut();
     // do something with the put contract
     OptionContract callSide = contractPair.getCall();
     // do something with the call contract
 }
 
As new market data events come in, the option chain view is updated as the events are added to the OptionChain object with process(Event).

Dividends for the underlying instrument of the OptionChain object are available in a similar fashion:

 List<DividendEvent> dividends = theChain.getDividends();
 
The OptionChain also tracks market data for the underlying instrument and each OptionContract.
 // the latest ask for the option chain underlying instrument 
 AskEvent ask = theChain.getLatestUnderlyingAsk();
 for(OptionContractPair contractPair : optionChain) {
     // the latest ask for the put side of one of the entries in the option chain
     ask = contractPair.getPut().getLatestAsk();
 }
 

Since:
2.0.0
Version:
$Id: OptionChain.java 16154 2012-07-14 16:34:05Z colin $
Author:
Colin DuPlantis

Constructor Summary
OptionChain(Instrument inUnderlyingInstrument)
          Create a new OptionChain instance.
 
Method Summary
 List<DividendEvent> getDividends()
          Gets a live, unmodifiable view of the dividends for the underlying instrument.
 AskEvent getLatestUnderlyingAsk()
          Gets the latest Ask for the underlying instrument.
 BidEvent getLatestUnderlyingBid()
          Gets the latest Bid for the underlying instrument.
 MarketstatEvent getLatestUnderlyingMarketstat()
          Gets the latest Marketstat for the underlying instrument.
 TradeEvent getLatestUnderlyingTrade()
          Gets the latest Trade for the underlying instrument.
 Collection<OptionContractPair> getOptionChain()
          Gets a live, unmodifiable view of the option chain.
 Instrument getUnderlyingInstrument()
          Gets the underlying instrument for this OptionChain.
 boolean process(Event inEvent)
          Attempts to apply the given event to this OptionChain.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

OptionChain

public OptionChain(Instrument inUnderlyingInstrument)
Create a new OptionChain instance.

Parameters:
inUnderlyingInstrument - an Instrument value indicating the Instrument for which to create the OptionChain
Throws:
NullPointerException - if inUnderlyingInstrument is null
Method Detail

getOptionChain

public Collection<OptionContractPair> getOptionChain()
Gets a live, unmodifiable view of the option chain.

Updates to the option chain will be visible in this view. The elements in the option chain will be sorted according to the OptionContractPair natural order.

This view is populated when Event objects are passed to process(Event).

Returns:
a Collection<OptionContractPair> value

getDividends

public List<DividendEvent> getDividends()
Gets a live, unmodifiable view of the dividends for the underlying instrument.

Updates to the dividend data for the underlying instrument will be visible in this view. The elements in the list are sorted in the order that the corresponding DividendEvent objects are received.

This view is populated when DividendEvent objects are passed to process(Event).

Returns:
a List<DividendEvent> value

getUnderlyingInstrument

public Instrument getUnderlyingInstrument()
Gets the underlying instrument for this OptionChain.

Returns:
an Instrument value

getLatestUnderlyingAsk

public AskEvent getLatestUnderlyingAsk()
Gets the latest Ask for the underlying instrument.

This data is populated when AskEvent objects are passed to process(Event).

Returns:
an AskEvent or null

getLatestUnderlyingBid

public BidEvent getLatestUnderlyingBid()
Gets the latest Bid for the underlying instrument.

This data is populated when BidEvent objects are passed to process(Event).

Returns:
a BidEvent or null

getLatestUnderlyingTrade

public TradeEvent getLatestUnderlyingTrade()
Gets the latest Trade for the underlying instrument.

This data is populated when TradeEvent objects are passed to process(Event).

Returns:
a TradeEvent or null

getLatestUnderlyingMarketstat

public MarketstatEvent getLatestUnderlyingMarketstat()
Gets the latest Marketstat for the underlying instrument.

This data is populated when MarketstatEvent objects are passed to process(Event).

Returns:
a BidEvent or null

process

public boolean process(Event inEvent)
Attempts to apply the given event to this OptionChain.

Parameters:
inEvent - an Event value
Returns:
a boolean value which, if true, indicates that the given event was successfully applied to the option chain. If false, the event was not applicable.

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2012. All Rights Reserved.