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.