Hi,
I want play with some 0DTE on SPX, I set my filter to IncludeWeeklys(). The last line of the script returns only the monthly expiry.
FYI: I am using this code in Notebook (Research) and I have a free tier account.
qb = QuantBook()
index = qb.add_index('SPX' )
# Request some historical data.
index_history = qb.history(index.symbol, datetime(2024, 5, 1), datetime(2024, 5, 2), Resolution.MINUTE, fill_forward=False, extended_market_hours=False)
index_option = qb.add_index_option(index.symbol, 'SPXW')
index_option.set_filter(lambda u: u.IncludeWeeklys())
option_history = qb.option_history(index.symbol, datetime(2024, 5, 1), \
datetime(2024, 5, 2), Resolution.MINUTE, fill_forward=False, extended_market_hours=False)
df = option_history.data_frame
x = df.reset_index()
pd.unique(x.expiry)
Mia Alissi
To ensure you are getting weekly expiries when using
IncludeWeeklys()
in your code, please follow these steps:Ensure Correct Option Ticker: When adding index options, make sure you specify the correct target option ticker for weekly options. For SPX weekly options, use
"SPXW"
as the target option ticker.Set the Filter Correctly: The
IncludeWeeklys()
method should be used within the filter function. Ensure that you are applying it correctly to filter for weekly options.Verify Option History Request: When requesting option history, ensure you are using the correct symbol and parameters. The
option_history
method should be called with the correct index option symbol, not the underlying index symbol.Here's how you can adjust your code:
Key Adjustments:
"SPXW"
when adding the index option to specify weekly options.include_weeklys()
within the filter function to ensure weekly options are included.add_index_option
for theoption_history
method to ensure you are querying the correct options.By following these steps, you should be able to retrieve weekly expiry options, including 0DTE options, in your research environment. If the issue persists, consider checking the availability of data for the specific date range and resolution you are using.
Sources: Basic Template S P X Weekly Index Options Algorithm, Handling Data - QuantConnect.com, Individual Contracts - QuantConnect.com, Option Expiration Week Effect, Universes - QuantConnect.com
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.
Fari Tigar
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!