This is a refactoring of the QCAlgorithm.OptionChain() API for fetching an option chain:
Changed return type from DataHistory<OptionUniverse> to OptionChain:
Added DataFrame property to OptionChain to convert the option chain into a Pandas DataFrame.
Added the QCAlgorithm.OptionChains() method to fetch option chains for multiple symbols:
Added DataFrame property to OptionChains to convert the option chain into a Pandas DataFrame. This dataframe will have a multi-index which first level is the canonical option. Indexing by the canonical symbol will result in a sub data frame equivalent to the one generated for a single OptionChain.
Additional changes:
Fix for list of base data convertion into Pandas DataFrame:
This makes sure PandasConverter.GetDataFrame<T>(IEnumerable<T> data) doesn't assume the data is for a single symbol. For instance, if an option chain (IEnumerable<ContractData>) is to be converted to a data frame, each item will correspond to a single symbol, that is, each contract.
This is fixed generically so that a single list can hold data for multiple symbols, regardless of the number of items for each symbol contained in the list.
Dataframes are now indexed by Symbol instances, instead of the symbol ID/Value string. This way, users can access it and use the Symbol directly for other operations, like manually adding option contracts.
Description
This is a refactoring of the
QCAlgorithm.OptionChain()
API for fetching an option chain:DataHistory<OptionUniverse>
toOptionChain
:DataFrame
property toOptionChain
to convert the option chain into a PandasDataFrame
.QCAlgorithm.OptionChains()
method to fetch option chains for multiple symbols:DataFrame
property toOptionChains
to convert the option chain into a PandasDataFrame
. This dataframe will have a multi-index which first level is the canonical option. Indexing by the canonical symbol will result in a sub data frame equivalent to the one generated for a singleOptionChain
.Additional changes:
PandasConverter.GetDataFrame<T>(IEnumerable<T> data)
doesn't assume the data is for a single symbol. For instance, if an option chain (IEnumerable<ContractData>
) is to be converted to a data frame, each item will correspond to a single symbol, that is, each contract.Symbol
instances, instead of the symbol ID/Value string. This way, users can access it and use theSymbol
directly for other operations, like manually adding option contracts.Data frame before:
Sample:
Data frame after (single option chain):
Sample:
Data frame after (multiple option chains):
Sample:
Related Issue
Closes #8331
Motivation and Context
Requires Documentation Change
How Has This Been Tested?
Types of changes
Checklist:
bug-<issue#>-<description>
orfeature-<issue#>-<description>