Skip to content

OptionChain

QuantConnect.Data.Market.OptionChain

OptionChain(
    canonical_option_symbol: Union[
        Symbol, str, BaseContract
    ],
    time: Union[datetime, date],
    flatten: bool = True,
)
OptionChain(
    canonical_option_symbol: Union[
        Symbol, str, BaseContract
    ],
    time: Union[datetime, date],
    contracts: List[OptionUniverse],
    symbol_properties: SymbolProperties,
    flatten: bool = True,
)

Bases: BaseChain[OptionContract, OptionContracts]

Represents an entire chain of option contracts for a single underlying security. This type is IEnumerable{OptionContract}

Signature descriptions:

  • Initializes a new instance of the OptionChain class

  • Initializes a new option chain for a list of contracts as OptionUniverse instances

Parameters:

Name Type Description Default
canonical_option_symbol Union[Symbol, str, BaseContract]

The symbol for this chain.

required
time Union[datetime, date]

The time of this chain

required
flatten bool

Whether to flatten the data frame

True
contracts Optional[List[OptionUniverse]]

The list of contracts data

None
symbol_properties Optional[SymbolProperties]

The option symbol properties

None

symbol

symbol: Symbol

Symbol representation for underlying Security

data_type

data_type: MarketDataType

Market Data Type of this data - does it come in individual price packets or is it grouped into OHLC.

time

time: datetime

Current time marker of this data packet.

end_time

end_time: datetime

The end time of this data. Some data covers spans (trade bars) and as such we want to know the entire time span covered

value

value: float

Value representation of this data packet. All data requires a representative value for this moment in time. For streams of data this is the price now, for OHLC packets this is the closing price.

price

price: float

As this is a backtesting platform we'll provide an alias of value as price.

ALL_RESOLUTIONS

ALL_RESOLUTIONS: List[Resolution] = ...

A list of all Resolution

This codeEntityType is protected.

DAILY_RESOLUTION

DAILY_RESOLUTION: List[Resolution] = ...

A list of Resolution.DAILY

This codeEntityType is protected.

MINUTE_RESOLUTION

MINUTE_RESOLUTION: List[Resolution] = ...

A list of Resolution.MINUTE

This codeEntityType is protected.

HIGH_RESOLUTION

HIGH_RESOLUTION: List[Resolution] = ...

A list of high Resolution, including minute, second, and tick.

This codeEntityType is protected.

OPTION_RESOLUTIONS

OPTION_RESOLUTIONS: List[Resolution] = ...

A list of resolutions support by Options

This codeEntityType is protected.

is_fill_forward

is_fill_forward: bool

True if this is a fill forward piece of data

underlying

underlying: BaseData

Gets the most recent trade information for the underlying. This may be a Tick or a TradeBar

ticks

ticks: Ticks

Gets all ticks for every option contract in this chain, keyed by option symbol

trade_bars

trade_bars: TradeBars

Gets all trade bars for every option contract in this chain, keyed by option symbol

quote_bars

quote_bars: QuoteBars

Gets all quote bars for every option contract in this chain, keyed by option symbol

contracts

contracts: (
    QuantConnect_Data_Market_BaseChain_TContractsCollection
)

Gets all contracts in the chain, keyed by option symbol

filtered_contracts

filtered_contracts: HashSet[Symbol]

Gets the set of symbols that passed the Option.ContractFilter

data_frame

data_frame: Any

The data frame representation of the option chain

count

count: int

The number of contracts in this chain

clone

clone() -> BaseData

Return a new instance clone of this object, used in fill forward

Returns:

Type Description
BaseData

A clone of the current object.

reader

reader(
    config: SubscriptionDataConfig,
    line: str,
    date: datetime,
    is_live_mode: bool,
) -> BaseData

Reader converts each line of the data source into BaseData objects. Each data type creates its own factory method, and returns a new instance of the object each time it is called. The returned object is assumed to be time stamped in the config.ExchangeTimeZone.

Parameters:

Name Type Description Default
config SubscriptionDataConfig

Subscription data config setup object

required
line str

Line of the source document

required
date datetime

Date of the requested data

required
is_live_mode bool

true if we're in live mode, false for backtesting mode

required

Returns:

Type Description
BaseData

Instance of the T:BaseData object generated by this line of the CSV.

requires_mapping

requires_mapping() -> bool

Indicates if there is support for mapping

Returns:

Type Description
bool

True indicates mapping should be used.

data_time_zone

data_time_zone() -> Any

Specifies the data time zone for this data type. This is useful for custom data types

Returns:

Type Description
Any

The DateTimeZone of this data type.

default_resolution

default_resolution() -> Resolution

Gets the default resolution for this data and security type

deserialize_message

deserialize_message(serialized: str) -> Iterable[BaseData]

Deserialize the message from the data server

Parameters:

Name Type Description Default
serialized str

The data server's message

required

Returns:

Type Description
Iterable[BaseData]

An enumerable of base data, if unsuccessful, returns an empty enumerable.

get_source

get_source(
    config: SubscriptionDataConfig,
    date: datetime,
    is_live_mode: bool,
) -> SubscriptionDataSource

Return the URL string source of the file. This will be converted to a stream

Parameters:

Name Type Description Default
config SubscriptionDataConfig

Configuration object

required
date datetime

Date of this source file

required
is_live_mode bool

true if we're in live mode, false for backtesting mode

required

Returns:

Type Description
SubscriptionDataSource

String URL of source file.

is_sparse_data

is_sparse_data() -> bool

Indicates that the data set is expected to be sparse

Returns:

Type Description
bool

True if the data set represented by this type is expected to be sparse.

should_cache_to_security

should_cache_to_security() -> bool

Indicates whether this contains data that should be stored in the security cache

Returns:

Type Description
bool

Whether this contains data that should be stored in the security cache.

supported_resolutions

supported_resolutions() -> List[Resolution]

Gets the supported resolution for this data and security type

to_string

to_string() -> str

Formats a string with the symbol and value.

Returns:

Type Description
str

string - a string formatted as SPY: 167.753.

update

update(
    last_trade: float,
    bid_price: float,
    ask_price: float,
    volume: float,
    bid_size: float,
    ask_size: float,
) -> None

Update routine to build a bar/tick from a data update.

Parameters:

Name Type Description Default
last_trade float

The last trade price

required
bid_price float

Current bid price

required
ask_price float

Current asking price

required
volume float

Volume of this trade

required
bid_size float

The size of the current bid, if available

required
ask_size float

The size of the current ask, if available

required

update_ask

update_ask(ask_price: float, ask_size: float) -> None

Updates this base data with the new quote ask information

Parameters:

Name Type Description Default
ask_price float

The current ask price

required
ask_size float

The current ask size

required

update_bid

update_bid(bid_price: float, bid_size: float) -> None

Updates this base data with the new quote bid information

Parameters:

Name Type Description Default
bid_price float

The current bid price

required
bid_size float

The current bid size

required

update_quote

update_quote(
    bid_price: float,
    bid_size: float,
    ask_price: float,
    ask_size: float,
) -> None

Updates this base data with new quote information

Parameters:

Name Type Description Default
bid_price float

The current bid price

required
bid_size float

The current bid size

required
ask_price float

The current ask price

required
ask_size float

The current ask size

required

update_trade

update_trade(last_trade: float, trade_size: float) -> None

Updates this base data with a new trade

Parameters:

Name Type Description Default
last_trade float

The price of the last trade

required
trade_size float

The quantity traded

required

__contains__

__contains__(key: Union[Symbol, str, BaseContract]) -> bool

Checks if the chain contains a contract with the specified symbol

Parameters:

Name Type Description Default
key Union[Symbol, str, BaseContract]

The symbol of the contract to check for

required

Returns:

Type Description
bool

True if the chain contains a contract with the specified symbol; otherwise, false.

__iter__

__iter__() -> (
    Iterator[QuantConnect_Data_Market_BaseChain_T]
)

__len__

__len__() -> int

contains_key

contains_key(key: Symbol) -> bool

Checks if the chain contains a contract with the specified symbol

Parameters:

Name Type Description Default
key Symbol

The symbol of the contract to check for

required

Returns:

Type Description
bool

True if the chain contains a contract with the specified symbol; otherwise, false.

get_enumerator

get_enumerator() -> (
    IEnumerator[QuantConnect_Data_Market_BaseChain_T]
)

Returns an enumerator that iterates through the collection.

Returns:

Type Description
IEnumerator[QuantConnect_Data_Market_BaseChain_T]

An enumerator that can be used to iterate through the collection.