Hi everyone,
I keep on getting:
"Runtime Error: 'NoneType' object has no attribute 'Reset' at OnSecuritiesChanged symbolData.Reset() at Python.Runtime.PythonException.ThrowLastAsClrException() at Python.Runtime.PyObject.Invoke(PyTuple args in portfolio.py: line 130"
between 2017-2018 in my backtests. Does anyone know how I could fix this error or continue through the backtest by skipping that data point?
Mia Alissi
The error message "Runtime Error: 'NoneType' object has no attribute 'Reset'" typically means that you're trying to call the
Reset
method on an object that isNone
. This could happen if thesymbolData
object is not properly initialized before theReset
method is called.In the
OnSecuritiesChanged
method, you should check ifsymbolData
isNone
before callingReset
. Here is an example of how you can do this:In this code,
symbolData
is checked if it'sNone
before callingReset
. If it'sNone
, a newSymbolData
object is created and added tosymbolDataBySymbol
dictionary. If it's notNone
, meaning the security was already initialized and re-added, theReset
method is called.Please ensure that your code follows a similar pattern to avoid calling methods on
None
objects.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.
David L
Hi Mia, Thanks for the quick response! I should've attached the code earlier.
David L
David L
Unfortunately, I still get a run error at a specific point in time. When I use the code you replied I get a different run error:
Mia Alissi
Hi David,
The error you're encountering is due to the fact that you're trying to call the
Reset
method on an object that isNone
. This happens when thepop
method doesn't find theremoved.Symbol
in theself.symbolDataBySymbol
dictionary and returnsNone
as a default value.To fix this, you should check if
symbolData
isNone
before callingReset
. Here's how you can modify your code:In this modified code,
symbolData
is checked if it'sNone
before callingReset
. If it'sNone
, the code simply skips theReset
call. This should prevent the error you're seeing.Remember to ensure that your securities are correctly initialized and added to the
self.symbolDataBySymbol
dictionary to avoid similar issues in the future.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.
Mia Alissi
The error message "Runtime Error: 'NoneType' object has no attribute 'Reset'" typically means that you're trying to call the
Reset
method on an object that isNone
. This could happen if thesymbolData
object is not properly initialized before theReset
method is called.In your
OnSecuritiesChanged
method, you are callingReset
onsymbolData
without checking if it'sNone
. Here is the problematic part of your code:You should check if
symbolData
isNone
before callingReset
. Here is an example of how you can do this:In this code,
symbolData
is checked if it'sNone
before callingReset
. If it's notNone
, theReset
method is called. This should help you avoid calling methods onNone
objects and fix your error.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.
David L
Thank you very much! I will try to fit this into my code. I think I understand now.
David L
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!