I'm having an issue with my algorithm requesting historical data.
The error: "GOOG 190705C01185000: 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."
I'm not sure why this is happening since I'm requesting the historical data, rather than using a warm-up period since I have no technical indicators yet, but I tried fixing it using "self.SetWarmUp(100)" and that same function using timedelta instead of trading bars, but both gave me "the object you're referencing has no instance," or some error like that even though I imported timedelta from datetime at the beginning of my algo and put the warm-up period code in the initialize section (not shown in this code).
Should I just ignore this error, or how can I fix it.
Thanks,
Noah
Derek Melchin
Hi Noah,
This error occurs when we are placing a trade for a security the algorithm doesn't have price data for yet. This happens because in the TradeOptions method, the algorithm calls AddOptionContract and Buy/Sell in the same time step. The algorithm won't have the data needed to trade until the next time step.
for contract in self.trade_contracts:
self.AddOptionContract(contract, Resolution.Minute)
self.Buy(itm_call_lower, 1)
self.Sell(itm_call_upper, 1)
self.Sell(otm_call_lower, 1)
self.Buy(otm_call_upper, 1)
To resolve this, we can set the market price of the contracts to the last known price from the history provider by adding the following line to the Initialize method.
self.SetSecurityInitializer(lambda x: x.SetMarketPrice(self.GetLastKnownPrice(x)))
See the attached algorithm for reference. Going forward, I'd recommend navigating the options chain when making options strategies because then the algorithm won't run into this error. See the Iron Condor tutorial for an example.
Best,
Derek Melchin
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.
Brian Christopher
Derek Melchin you mean instead of using `optionchainprovider` use `slice.OptionChains`?
Derek Melchin
Hi Brian,
Yes, refer to Iron Condor tutorial linked above for an example.
Best,
Derek Melchin
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.
Aaron
Hi Derek, (or anyone else)
(sorry know this is an old thread but didn't want to create duplicate)
I'm getting similar errors in my code in equities not options, is the reason the same or different?
also if I set the market price of the 'security' to the last known price from the history provider won't this not be the correct price and therefore will get incorrect returns on that trade?
e.g.:
“NB R735QTJ8XC9X: 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.”
Aaron
actually is still happening once I extended backtest time
Jack Pizza
same nobody cares anymore dude place is basically a ghost town lol
Noah price
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!