Lean icon indicating copy to clipboard operation
Lean copied to clipboard

Empty Option Chains for Future Options

Open AlexCatarino opened this issue 1 year ago • 1 comments

Expected Behavior

No need to define SetFilter for the underlying future. The option chain should have the mapped contract.

Actual Behavior

If we need to set the filter.

Potential Solution

N/A

Reproducing the Problem

# region imports
from AlgorithmImports import *
# endregion

class BasicFutureOptionAlgorithm(QCAlgorithm):
    def initialize(self):
        self.set_start_date(2023,1,1)
        self._future = self.add_future(Futures.Indices.SP_500_E_MINI,
            extended_market_hours=True,
            data_mapping_mode=DataMappingMode.OPEN_INTEREST,
            data_normalization_mode=DataNormalizationMode.BACKWARDS_RATIO,
            contract_depth_offset=0)
        #self._future.set_filter(0, 182)   # < --uncomment to get options

        self.add_future_option(self._future.symbol, lambda u: u.strikes(-1, 1))
    
    def on_data(self, data):
        # Iterate all Option chains to find the desired future and future options contracts 
        for canonical_symbol, chain in data.option_chains.items():
            future_contract = canonical_symbol.underlying
            for symbol, contract in chain.contracts.items():
                contract.strike

        # Get the Option chain for the mapped contract 
        chain = data.option_chains.get(Symbol.create_canonical_option(self._future.mapped))
        if chain:
            for symbol, contract in chain.contracts.items():
                contract.strike

Checklist

  • [x] I have completely filled out this template
  • [x] I have confirmed that this issue exists on the current master branch
  • [x] I have confirmed that this is not a duplicate issue by searching issues
  • [x] I have provided detailed steps to reproduce the issue

AlexCatarino avatar Aug 23 '24 16:08 AlexCatarino

By the way, it would be nice to be able to get the chain with the underlying symbol:

chain = data.option_chains.get(self._future.mapped)

AlexCatarino avatar Aug 23 '24 16:08 AlexCatarino