I am trying to run LEAN using my own local data with a universe of all SP500 stocks, and observe the following error. If I reduce the number of symbols this error disappears.
Backtest Handled Error: AAPL: The security does not have an accurate price as it has not yet received a bar of data. Before placing a trade (or using SetHoldings) warm up your algorithm with SetWarmup, or use slice.Contains(symbol) to confirm the Slice object has price before using the data. Data does not necessarily all arrive at the same time so your algorithm should confirm the data is ready before using it. In live trading this can mean you do not have an active subscription to the asset class you're trying to trade. If using custom data make sure you've set the 'Value' property.
Example:
for symbol in tickers: #450+ symbols causes backtest error
equities[symbol] = self.AddEquity(symbol, self.resolution, fillDataForward = True, leverage = 0, extendedMarketHours = False)
for symbol in tickers[:350]: #350 symbols no error
equities[symbol] = self.AddEquity(symbol, self.resolution, fillDataForward = True, leverage = 0, extendedMarketHours = False)
I've observed the same using:
equities = [Symbol.Create(symbol, SecurityType.Equity, Market.USA) for symbol in tickers]
self.SetUniverseSelection(ManualUniverseSelectionModel(equities))
CAPOCAPITAL
SetWarmup does not appear to fix this error
Fred Painchaud
Hi CAPO,
It looks like your algo is trying to trade an asset before some data as been given to your algo for that asset. Here, it is AAPL.
Depending on how your algo is laid out, it can happen. “You start trading too soon” is the long story short.
Usually culprit is lacking of sanity checks in OnData. Another one is if you are not subscribed to AAPL anymore but still want to trade it. If you are not invested in AAPL and AAPL leaves your Universe, you won't be subscribed anymore to it. If your algo keeps a ref to AAPL and trades it - bang!
Without code, it is difficult to tell you more, anything more precise…
Fred
CAPOCAPITAL
Attaching Backtest 1 of 2,
The error appears to be related to the number of securities being added to the universe, and I suspect is related to the RAM or CPU limitations of the backtest node, because on my local lean I can handle up to 350 symbols without getting the error, while on quantconnect cloud it required far less symbols before the error appeared. In this example the error occurs since I am adding too many equities. The same happens if I create symbols instead and use manualuniverse selection.
Backtest Handled Error: AAPL: The security does not have an accurate price as it has not yet received a bar of data. Before placing a trade (or using SetHoldings) warm up your algorithm with SetWarmup, or use slice.Contains(symbol) to confirm the Slice object has price before using the data. Data does not necessarily all arrive at the same time so your algorithm should confirm the data is ready before using it. In live trading this can mean you do not have an active subscription to the asset class you're trying to trade. If using custom data make sure you've set the 'Value' property.
CAPOCAPITAL
Attaching Backtest 2 of 2,
In this second example the error does not appear since I only add equities from tickers[:10] instead of the full list of 450 tickers. I believe there is some type of RAM/CPU limitation that I would like to understand. If someone has a deeper understanding of what causes this issue, beyond just recommending I use less symbols in my universe, that would be appreciated. I've also tried checking for data (if not data.ContainsKey(s): # Check for symbol) and that only causes my trading logic to no longer execute .setholdings. There is nothing in the code that removes the security, it seems like there is a data limitation against so many equities added.
Fred Painchaud
Hi CAPO,
I tried running the following code but there seems to be a problem right now. Have you tried running this?:
Fred
CAPOCAPITAL
Thank you Fred, the logic in your above code seems to prevent the bactest handling error with the full amount of tickers, thank you! I'll need to change my trading logic a bit in order to repeat this when looping over all the symbols, but this appears to work.
CAPOCAPITAL
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!