I have this option set in my code, according to the documentation I believe, but it is throwing this error:

  1. Runtime Error: 'OptionContract' object has no attribute 'IsTradable'
  2.  at <listcomp>
  3.    tradable_call_contracts = [contract for contract at chain if contract.Right == OptionRight.Call and contract.IsTradable]
  4. in main.py: line 119
  5.  at OnData
  6.    tradable_call_contracts = [contract for contract at chain if contract.Right == OptionRight.Call and contract.IsTradable]
  7.   at Python.Runtime.PythonException.ThrowLastAsClrException()

The algo is skipping a lot of trades because: 

  1. The security with symbol 'SPXW 221221C03875000' is marked as non-tradable.

So I am trying to figure out how to get it to select an option that is tradeable.. I'm using this in the initialize:

  1. underlying = self.AddIndex("SPX", Resolution.Minute)
  2. options = self.AddIndexOption(underlying.Symbol, "SPXW", Resolution.Minute)
  3. options.SetFilter(lambda u: u.IncludeWeeklys().Strikes(-1, 1).Expiration(0, 0))

and this in OnData:

  1. chain = slice.OptionChains.get(self.symbol)
  2. if not chain: return
  3. # Filter call contracts
  4. call_contracts = [contract for contract in chain if contract.Right == OptionRight.Call]
  5. # We sort the call contracts to find at the money (ATM) contract with closest expiration
  6. contracts = sorted(sorted(sorted(call_contracts, \
  7. key=lambda x: x.Expiry), \
  8. key=lambda x: abs(chain.Underlying.Price - x.Strike)), \
  9. key=lambda x: x.Right, reverse=True)
  10. # If found, buy it
  11. if len(contracts) == 0: return
  12. symbol = contracts[0].Symbol
  13. self.MarketOrder(symbol, 1)
+ Expand

Author

Matt

March 2023