Hello everyone,
I have a simple strategy which works smoothly in a backtest. But when I deploy it to live, I'm consistently getting the following error:
Runtime Error: KeyNotFoundException : 'NOW' wasn't found in the Slice object, likely because there was no-data at this moment in time and it wasn't possible to fillforward historical data. Please check the data exists before accessing it with data.ContainsKey("NOW") ...
As you might see in the attached backtest with the code snippet, I'm indeed using ContainsKey statement at the beginning. The error rises in line 24 in the attached code snippet. Is it the problem of live mode? I'm using QC data stream there. Would be glad to hear recommendations.
Varad Kabade
Hi Kirill T,
The following method:
self.algo.CurrentSlice.ContainsKey checks whether the current slice object contains data for the given symbol. The data can be trade(trade bars) or non-trade data(splits, dividends) etc.
To resolve the issue we can replace the above with
if self.algo.CurrentSlice.ContainsKey(self.symbol) and self.algo.CurrentSlice[self.symbol] is not None:
to resolve the issue. Refer to the attached backtest. Note that we can make their algorithm more efficient by removing the daily History calls in favor of a consolidator. If this doesn't solve the issue, please contact support@quantconnect.com for issues with live algorithms.
Best,
Varad Kabade
Kirill
Hi Varad,
Thank you for the advice but unfortunately it didn't help. Seems really strange.
Varad Kabade
Hi Kirill T,
Here is a simplified version of the given strategy. Here we do not use CurrentSlice. Refer to the attached backtest.
Best,
Varad Kabade
Kirill
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!