I have been looking on the forums for hours but couldnt find template for this simple algo. There is one from Ekz but it throws a key error. I am referring to -
"Runtime Error: '?SPY' wasn't found in the OptionChains 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("?SPY") in DataDictionary.cs:line 228"
Could someone please help me to resolve the error in this backtest?
Nico Xenox
Hey Nadeem Ahmed,
this error occurs if you try to use the symbol without data. After some debugging I found out that you have to add the following line to the SelectContractByDelta function:
Hope it helps 😊
Nadeem Ahmed
@Nico Xenox
Thank you for your help. Actually the issue was completely different. I changed the resolution to daily in order to make the algorithm faster. And when I do that, it throws the error that I mentioned in my first post. Even after using the code you suggested. I suspect this happens because that particular option contract is not available in the market if you scan the data daily. However, the option contract can appear if you scan on hourly/minute resolution. Do you think that is the issue or am I completely getting it wrong?
Do you have any ideas to make algo faster? It takes forever to run. Even hourly resolution takes forever.
Nico Xenox
Hey Nadeem Ahmed,
yea I see what you mean now, I tried it by checking if the spy symbol, and the option symbol had keys but no results. Maybe you could try to play around with the try and except function.
Nadeem Ahmed
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!