Hello,
I'm following this guide but I'm only getting data for standard index options, and not weekly options. I am trying to work with 0dte option on SPX. I am only getting the chain for 06/16/2023 (SPXW 230616C04175000). It's probably something silly, but I can't find it. Here is the code:
def Initialize(self):
self.SetStartDate(2023, 6, 1)
self.SetEndDate(2023, 6, 1)
self.SetCash(100000)
index_symbol = self.AddIndex("SPX").Symbol
option = self.AddIndexOption(index_symbol, "SPXW")
option.SetFilter(-2, 2, 0, 30)
self.symbol = option.Symbol
self.log_count=0
def OnData(self, data: Slice):
weekly_chain = data.OptionChains.get(self.symbol)
if weekly_chain:
for contract in weekly_chain:
if self.log_count >100:
return
self.Log(f"{contract.Symbol} price at {data.Time}: {contract.LastPrice}")
self.log_count+=1
Mia Alissi
Hello Scott,
From the code you've shared, it seems like you're correctly setting up the weekly options for the SPX index. However, the issue might be related to the date range you're using in
SetStartDate
andSetEndDate
. You've set both to June 1, 2023, which means the algorithm is only running for a single day.If you're looking for 0dte options, you might want to consider expanding the date range to include more trading days. This will give the algorithm more opportunities to find and log the options contracts you're interested in.
Here's how you might adjust the date range:
This will run the algorithm for the entire month of June 2023, which should provide more opportunities to find the 0dte options you're interested in.
For more information on how to work with index options in QuantConnect, you can refer to the documentation.
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.
Scott Taylor
Sorry, that did not help. With more time, it just found more Monthly index options (6/16/23 and 7/21/23). Here is the code, and it's output (I restricted the log to only 9:33am each day to keep the log small).
Ashutosh
Hi Scott Taylor,
You can use IncludeWeeklys() inside the filter method to get weekly options.
Reference: universe-selection.
Attaching backtest for reference.
Reference Output:
Let me know if this helps.
Best,
Ashutosh
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.
Scott Taylor
Thank you Ashutosh,
I'm still stuck. Trying to create the UniverseFunc and correctly setting it up. Any chance you would share how you adjusted my code to get that result?
Scott Taylor
Thank you Ashutosh,
Please ignore the message above. I just learned how to get to the code you supplied. Thank you for being so thorough in your answer. It is appreciated.
Scott Taylor
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!