Hello,
I'm receiving this log error:
Runtime Error: In Scheduled Event 'SPY: EveryDay: 9', AttributeError : 'NoneType' object has no attribute 'Close' at Rebalance in main.py:line 95 :: if self.CurrentSlice[symbol].Close is not None: AttributeError : 'NoneType' object has no attribute 'Close'.My code is this:
for symbol, previous_d_close in self.previous_d_close.items():
if self.CurrentSlice.ContainsKey(symbol):
if self.CurrentSlice[symbol].Close is not None:
last_price = self.CurrentSlice[symbol].Close
percent_change[symbol] = last_price / previous_d_close
I've looked at multiple forum posts including these:
https://www.quantconnect.com/forum/discussion/8649/attributeerror-039-nonetype-039-object-has-no-attribute-039-assetclassification-039/p1
https://www.quantconnect.com/forum/discussion/8156/039-nonetype-039-object-has-no-attribute-039-open-039-when-plotting-candle-charts/p1
https://www.quantconnect.com/forum/discussion/4918/how-to-generate-the-rolling-window-of-4-tradebars/p1
https://www.quantconnect.com/forum/discussion/8649/attributeerror-039-nonetype-039-object-has-no-attribute-039-assetclassification-039/p0
https://www.quantconnect.com/forum/discussion/4283/using-data-keys-to-check-for-symbols-in-the-slice-object-not-working/p1
However none of these suggestions resolve the issue. Does anyone have a suggestion to fix this?
Frank Giardina
Ryan,
In my case I was passing the ticker instead of the key value so there was no close. I found that using the debugger, user error on my part. Not sure if this will help here is the thread and a good explanation from Derek Melchin on why some of these errors occur
www.quantconnect.com/forum/discussion/9824/runtime-error-attributeerror-039-dataframe-039-object-has-no-attribute-039-close-039/p1
Frank
Ryan Riordon
Hello Frank,
Thank you for the suggestion. My algo works fine except on this specific day or the year giving the error. Thus I don't know how it would be a ticker vs key value issue considering on any other day of the year it produces results without errors. The link you shared brings me to "404 Sorry we couldn't find that page". Is the webpage accessible to you?
Frank Giardina
hmm, when i click on the link in the thread it takes me to the issue, also copied the link and it opened. Sorry i could not help
Ryan Riordon
Odd the link still brings me to a 404 error page.
Here is the algo producing the AttributeError : 'NoneType' object has no attribute 'Close' error. If you change the dates from July 1 to July 7 2020 the error will happen on July 3.
Anyone with suggestions to get rid of the error?
Shile Wen
Hi Ryan,
Sometimes our Slices not have market data (e.g. TradeBars) and instead of auxiliary data (e.g. dividends), which means we check for self.CurrentSlice.Bars.ContainsKey(symbol) instead of self.CurrentSlice.ContainsKey(symbol) for market data. I've shown this fix in the attached backtest.
Best,
Shile Wen
Ryan Riordon
Hi Shile,
Thank you kindly for the response and solution. Have a good day.
Ryan Riordon
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!