Hi
I am really struggling with a runtime error that is too difficult for me to resolve. It looks like a bug to me, but I don't have the expertise to know for sure. Backtest attached.
The error is:
Runtime Error: NullReferenceException : Object reference not set to an instance of an object.at QuantConnect.Symbol.GetAlias(SecurityIdentifier securityIdentifier, Symbol underlying) in /LeanCloud/CI.Builder/bin/Debug/src/QuantConnect/Lean/Common/Symbol.cs:line 665 at QuantConnect.Symbol..ctor(SecurityIdentifier sid, String value) in /LeanCloud/CI.Builder/bin/Debug/src/QuantConnect/Lean/Common/Symbol.cs:line 318 at QuantConnect.SymbolCache.Cache.TryGetSymbol(String ticker, Symbol& symbol) in /LeanCloud/CI.Builder/bin/Debug/src/QuantConnect/Lean/Common/SymbolCache.cs:line 192 at QuantConnect.SymbolCache.TryGetSymbol(String ticker) in /LeanCloud/CI.Builder/bin/Debug/src/QuantConnect/Lean/Common/SymbolCache.cs:line 136 at QuantConnect.SymbolCache.TryGetSymbol(String ticker, Symbol& symbol) in /LeanCloud/CI.Builder/bin/Debug/src/QuantConnect/Lean/Common/SymbolCache.cs:line 77 at mapperkvp = SymbolCache.TryGetSymbol(key in PandasMapper.py: line 38 (Open Stacktrace)
In Debug mode, the error occurs at line 208 in floor_ceiling.py. However, it makes no sense to me.
Firstly, this method runs many times without error during the algorithm initialisation. After the first data arrives, it is called from OnData() via FloorCeiling.update_regime() and the error occurs.
Secondly, the error refers to “Symbol.cs “ and “SymbolCache.cs “, but there is no symbol involved. During initialisation, the method processes data in a Pandas DataFrame that is copied from history price data, then after new data is available it is updated with a Series copied from data in OnData(). I don’t see how it is linked to a symbol in any way.
Finally, this code works fine when run in my local Python (not Lean).
To see the error, uncomment line 426 in floor_ceiling.py.
During debugging, breakpoints need to see set as follows to avoid stopping during initialisation.
- Set a breakpoint at line 426 in floor_ceiling.py
- self.update_regime_row()
- Run it until that breakpoint is reached.
- While it is stopped, set another breakpoint at line 208 in floor_ceiling.py
- self.fc_df.loc[current_idx][regime_col] = self.fc_df.loc[prior_idx][regime_col]
- Run it again. From there you can set relevant Watches.
A Watch on self.fc_df.loc[current_idx][regime_col], which is about to be assigned to, should show NaN, but shows the same or very similar error as the runtime error.
I recognise that this code could be more efficient, but it should work as is.
I’d appreciate any help with this.
Louis Szeto
Hi Tony
The attached backtest does not include any file named floor_ceiling.py. Please attached a backtest with that for further assistance.
Best
Louis Szeto
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.
Tony Shacklock
Hi Louis
Thanks for looking at this. I don't know why floor_ceiling.py was not included. The backtest couldn't have run without it.
Since I reported this, I've changed the code significantly, which caused the error to occur in a different part of the code. Again, it runs in my local Python, but not on QuantConnect.
I don't want to muck you guys around with this, so my plan now is to do more of my development locally outside of Lean, then when it's more stable try QuantConnect again. Don't spend time on this at the moment, please. I will ask for help with it again if I need it.
Thanks, again.
Tony Shacklock
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!