def OnData(self, data):
for symbol in self.stock_symbol_list:
if self.previous_5_day_volumes.get(symbol) is None:
self.previous_5_day_volumes[symbol] = RollingWindow[float](self.lookback_period)
if data.ContainsKey(symbol):
self.previous_5_day_volumes[symbol].Add(data[symbol].Volume)
Im getting the below error can someone please help with what im doing wrong. Many thanks in advance
Runtime Error: 'NoneType' object has no attribute 'Volume'
at OnData
self.previous_5_day_volumes[symbol].Add(data[symbol].Volume)
at Python.Runtime.PythonException.ThrowLastAsClrException()
at Python.Runtime.PyObject.Invoke(PyTuple args in main.py: line 30
Mia Alissi
The error message
'NoneType' object has no attribute 'Volume'
typically occurs when you're trying to access theVolume
attribute of aNone
object. In this case, it seems likedata[symbol]
isNone
.This can happen if there's no data available for the given
symbol
at the current time step. You're already checking if the symbol is in the data withif data.ContainsKey(symbol):
, but it seems like the data for the symbol isNone
.To fix this, you can add an additional check to ensure that
data[symbol]
is notNone
before trying to access itsVolume
attribute. Here's how you can modify your code:This way, you're ensuring that
data[symbol]
exists and is notNone
before trying to access itsVolume
attribute.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.
Ferjo Ombwayo
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!