Hi,
I am trying to generate a rollingwindow of 4-TradeBars for hourly-time frame. I am getting following Error on BackTest:
Backtest deployed in 14.605 seconds
13 | 17:07:40:
Runtime Error: AttributeError : 'NoneType' object has no attribute 'Open'
at OnData in main.py:line 98
AttributeError : 'NoneType' object has no attribute 'Open' (Open Stacktrace)
14 | 17:07:50:
Algorithm Id:(e619b785f730a393eb8acd9b7f269eee) completed in 10.74 seconds at 0k data points per second. Processing total of 954 data points
Can you please help to fix the issue?
Jing Wu
To obtain the bar open price in OnData(self, data),
def OnData(self, data): if data.Bars.ContainsKey(symbol): open = data[symbol].Open
In your case, you can add a None type check before retrieving the open price like "if object is not None:". For better support, please share the algorithm with the "Attach Backtest".
Pushpendra Kr
Thanks for your suggestion. The check for 'if object is not None' helped.
Though I was wondering what would cause the TradeBar to be None.
Alexandre Catarino
Could you please attach the backest?
We will be able to find out what is the cause for TradeBar being None.
Pushpendra Kr
attached backtest, please take a look for None TradeBars
Jack Simonson
Hi Pushpendra,
We've looked into your algorithm and it looks like the None TradBars is due to SPY paying a dividend -- the dates match up when SPY pays a quarterly dividend, which is the 3rd Friday of every March, June, September, and December. If you see the attached backtest, I've added a line checking for dividends and logging it as such. If you want, our API provides various methods for filtering around specified dates or you can use the slice.Dividends.ContainsKey() method to catch these instances.
Pushpendra Kr
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!