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
Resetmethod on an object that isNone. This could happen if thesymbolDataobject is not properly initialized before theResetmethod is called.In the
OnSecuritiesChangedmethod, you should check ifsymbolDataisNonebefore callingReset. Here is an example of how you can do this:In this code,
symbolDatais checked if it'sNonebefore callingReset. If it'sNone, a newSymbolDataobject is created and added tosymbolDataBySymboldictionary. If it's notNone, meaning the security was already initialized and re-added, theResetmethod is called.Please ensure that your code follows a similar pattern to avoid calling methods on
Noneobjects.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
Resetmethod on an object that isNone. This happens when thepopmethod doesn't find theremoved.Symbolin theself.symbolDataBySymboldictionary and returnsNoneas a default value.To fix this, you should check if
symbolDataisNonebefore callingReset. Here's how you can modify your code:In this modified code,
symbolDatais checked if it'sNonebefore callingReset. If it'sNone, the code simply skips theResetcall. This should prevent the error you're seeing.Remember to ensure that your securities are correctly initialized and added to the
self.symbolDataBySymboldictionary 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
Resetmethod on an object that isNone. This could happen if thesymbolDataobject is not properly initialized before theResetmethod is called.In your
OnSecuritiesChangedmethod, you are callingResetonsymbolDatawithout checking if it'sNone. Here is the problematic part of your code:You should check if
symbolDataisNonebefore callingReset. Here is an example of how you can do this:In this code,
symbolDatais checked if it'sNonebefore callingReset. If it's notNone, theResetmethod is called. This should help you avoid calling methods onNoneobjects 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!