Hi,
I am following an options tutorial listed here but can't seem to get the code working. I am new to coding/programming so apologies if this seems like an easy/silly question.
I keep getting the below error;
Runtime Error: TypeError : 'NoneType' object is not iterable
at OnData
df = pd.DataFrame([[x.Right in main.py:line 24
TypeError : 'NoneType' object is not iterable (Open Stacktrace)
I believe the relevant bit of code where this error is occurring is here;
def OnData(self,slice):
optionchain = None
for i in slice.OptionChains:
if i.Key != self.symbol: continue
optionchain = i.Value
self.Log("underlying price:" + str(optionchain.Underlying.Price))
df = pd.DataFrame([[x.Right,float(x.Strike),x.Expiry,float(x.BidPrice),float(x.AskPrice)] for x in optionchain],
index=[x.Symbol.Value for x in optionchain],
columns=['type(call 0, put 1)', 'strike', 'expiry', 'ask price', 'bid price'])
self.Log(str(df))
What am I doing wrong?
Thanks in advance for any help.
Cheers.
Tomas Rampas
Hi IkIcho
I'm not sure if the sample code snippets on the page you are referencing are formatted correctly. I guess that not. Anyway if you need to get rid off your issue you will need to add outside check of optionchain for being not equal to None so the code snippet looks lie this.
def OnData(self,slice): optionchain = None for i in slice.OptionChains: if i.Key != self.symbol: continue optionchain = i.Value self.Log("underlying price:" + str(optionchain.Underlying.Price)) if optionchain is not None: df = pd.DataFrame([[x.Right,float(x.Strike),x.Expiry,float(x.BidPrice),float(x.AskPrice)] for x in optionchain], index=[x.Symbol.Value for x in optionchain], columns=['type(call 0, put 1)', 'strike', 'expiry', 'ask price', 'bid price']) self.Log(str(df))
Hope that helps.
Regards
Tomas
Iklcho
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!