I tried cloning this out-of-the-box strategy to learn more about QC, but after running a while the backtest fails with “Object reference not set to an instance of an object. in PythonException.cs:line 52”.
I'm surprised that the code given by QC itself fails, and also I don't know how to get a more useful error message. The stack trace doesn't show any user code, just this generic exception.
Mia Alissi
To help Eric resolve the "Object reference not set to an instance of an object" error, the following steps and information may be useful:
Debugging Tools:
self.log()
orself.debug()
to add messages in your code for tracking execution flow and state changes.Understanding Coding Errors:
Error Message and Stack Trace:
Code Validation:
PEP 8 Code Correction:
By applying detailed logging, using the debugger, and examining the potential areas where objects might be improperly referenced or initialized, Eric should be able to pinpoint and resolve the runtime error.
Sources: Debugging - QuantConnect.com, Debugging Tools - QuantConnect.com
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.
Eric Nichols
I've never seen any debug log messages actually showing up in QC. How do I see these when the backtest fails?
Note that the code runs fine for several periods, and fails later, during the backtest, so it's not easy to step through to find the error; it takes a long time to reach the fail point.
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!