I have this option set in my code, according to the documentation I believe, but it is throwing this error:
Runtime Error: 'OptionContract' object has no attribute 'IsTradable'
at <listcomp>
tradable_call_contracts = [contract for contract at chain if contract.Right == OptionRight.Call and contract.IsTradable]
in main.py: line 119
at OnData
tradable_call_contracts = [contract for contract at chain if contract.Right == OptionRight.Call and contract.IsTradable]
at Python.Runtime.PythonException.ThrowLastAsClrException()
The algo is skipping a lot of trades because:
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:
underlying = self.AddIndex("SPX", Resolution.Minute)
options = self.AddIndexOption(underlying.Symbol, "SPXW", Resolution.Minute)
options.SetFilter(lambda u: u.IncludeWeeklys().Strikes(-1, 1).Expiration(0, 0))
and this in OnData:
+ Expand
chain = slice.OptionChains.get(self.symbol)
if not chain: return
# Filter call contracts
call_contracts = [contract for contract in chain if contract.Right == OptionRight.Call]
# We sort the call contracts to find at the money (ATM) contract with closest expiration
contracts = sorted(sorted(sorted(call_contracts, \
key=lambda x: x.Expiry), \
key=lambda x: abs(chain.Underlying.Price - x.Strike)), \
key=lambda x: x.Right, reverse=True)
# If found, buy it
if len(contracts) == 0: return
symbol = contracts[0].Symbol
self.MarketOrder(symbol, 1)
Matt
looking closer at the debug console, the algo may not be skipping the trades… but for whatever reason it is reporting this as an error.
just a very confusing thing, apparently
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
Matt
Then who knows what is going on?
The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.
To unlock posting to the community forums please complete at least 30% of Boot Camp.
You can continue your Boot Camp training progress from the terminal. We hope to see you in the community soon!