I have been trying to access 0DTE options data for SPX/SPY and I have not been able to find a way to access it in a research notebook. I have copy pasted the code that I am using to get options data for SPY and SPX.

 

  1. import numpy as np
  2. import pandas as pd
  3. qb = QuantBook()
  4. index_symbol = qb.AddIndex("SPX", Resolution.Minute).Symbol
  5. option = qb.AddIndexOption(index_symbol)
  6. eq_symbol = qb.AddEquity("SPY", Resolution.Minute).Symbol
  7. eq_option = qb.AddOption(eq_symbol)
  8. start_time = datetime.fromtimestamp((datetime.today().timestamp()//86400)*86400) - timedelta(days=4)
  9. end_time = start_time + timedelta(days=3)
  10. start_date = datetime(2022, 12, 31)
  11. canonical_symbol = Symbol.CreateCanonicalOption(eq_symbol, "SPY", Market.USA, "?SPY")
  12. contract_symbols = qb.OptionChainProvider.GetOptionContractList(canonical_symbol, start_date)
  13. op = qb.History(TradeBar, contract_symbols, start_time, end_time)
  14. display(op)
  15. print(np.sort(op.index.get_level_values('expiry').unique()))
  16. start_date = datetime(2022, 12, 31)
  17. canonical_symbol = Symbol.CreateCanonicalOption(index_symbol, "SPXW", Market.USA, "?SPXW")
  18. contract_symbols = qb.OptionChainProvider.GetOptionContractList(canonical_symbol, start_date)
  19. op = qb.History(TradeBar, contract_symbols, start_time, end_time)
  20. display(op)
  21. print(np.sort(op.index.get_level_values('expiry').unique()))
+ Expand

 

From the output of print(np.sort(op.index.get_level_values('expiry').unique())), it is clear that the expires are either weekly or monthly. I would be grateful if someone could tell me if quantconnect has historical data on 0DTE options. If yes, what changes can I make in the code attached above to access this data for SPY or SPX or for both. Thanks.

Author

Kshitij Kapoor

April 2023