Back

Remove Securities That Don't Have Current Data

I'm receiving this in my backtest:

Data for symbol IR has been limited due to numerical precision issues in the factor file. The starting date has been set to 3/9/2020.

 

Then right after, I'm getting this error:

Runtime Error: KeyNotFoundException : 'IR R735QTJ8XC9X' wasn't found in the TradeBars 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("IR R735QTJ8XC9X")

The backtest is for 2016-2019, how can I just remove all securities from my universe that do not have data relative to the timeframe of the backtest.

My logic in my OnData function is the following:

if self.IsWarmingUp:
return

if data.Count < len(self.universe):
self.Debug("Not Ready. Getting data...")
return

self.Debug("Initialized! All data is present.")


# Add to and update all the moving averages
for symbol in self.universe:

if symbol not in self.averages:
# 1. Call history to get an array of day of longest average of history data
history = self.History(symbol, self.longAvg, Resolution.Daily)

#2. Adjust SelectionData to pass in the history result
self.averages[symbol] = SelectionData(history, self.longAvg, self.shortAvg)

self.averages[symbol].update(self.Time, tradeBars[symbol].Close)

Basically, I'm calculating moving averages for every stock in my universe and adding it to a dictionary later, just like in the tutorials. However, when I hit that security, it bugs out at me. 

Is there a HasData property on these security I can check for? 

Update Backtest







0

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.


Hi John,

The data received in OnData represents all the data available at that time slice. Sometimes data for a symbol may not be available for a specific time slice.Since you are using trade bars data, you just need to check if trade bar data is available for that symbol at that time slice with

data.Bars.ContainKey(symbol)

Best
Rahul

0

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.


Is it not available because the data event has not arrived to the OnData event handler or is it because data is missing for that security? If its the former, how do I let make the algorithm wait for the data event to arrive, I already have:

if self.IsWarmingUp:
return

 

0

Update Backtest





0

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.


Loading...

This discussion is closed