Hi everyone,
In my python code when accessing data['MSFT'].Ask.Close, I receive the following stacktrace:
"'MSFT' wasn't found in the QuoteBars 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(''MSFT'')"
This error only happens during demo trading with Interactive Brokers accounts. Backtesting with the same code works fine. As a data source I use QuantConnect provider.
OnData is set to Resolution.Second.
Could anyone please advise on the issues?
Thanks, Grigori.
Derek Melchin
Hi Grigori Gustin,
This error can occur when no trades were executed within the data slice passed to OnData. So, for example, if MSFT didn’t have a trade within the second beginning at 12:30:00PM, the data slice for that second would not have a closing ask price. As the error message pointed out, we can ensure this situation does not cause problems in our algorithms by guarding the execution of OnData with
if not data.ContainsKey("MSFT"): return
See the attached backtest for a full working example.
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.
Grigori Gustin
Hi Derek,
Thanks for your reply!
I have added the condition to check the QuoteBars by data.QuoteBars.ContainsKey('MSFT'), and it is always evaluated as False.
Per my understanding, QuoteBars should have data every second (Ask and Bid), while TradeBars only on trades - so I'm interested in QuoteBars.
Strange thing is that during backtesting QuoteBars have Ask and Bid data, while when I deploy the same code on IB paper trading with QC data feed, there is no data.
Do you have any tips on why it may happen?
Grigori
Derek Melchin
Hi Grigori,
It is correct that QuoteBars at the second resolution should have data every second there is liquidity in the market. However, QuoteBars are not available for equities in live mode yet. We have been working on the infrastructure updates to support it.
Best,
Derek
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.
Grigori Gustin
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!