def Initialize(self):

self.option_filter_ran = False

self.SetStartDate(2021, 3, 18) # Set Start Date

self.SetCash(100000) # Set Strategy Cash

es = self.AddFuture(Futures.Indices.SP500EMini, Resolution.Minute, Market.CME)

es.SetFilter(lambda futureFilter: futureFilter.Expiration(0, 365))

self.AddFutureOption(es.Symbol, self.OptionContractUniverseFilterFunction)

self.symbol = es.Symbol

def OptionContractUniverseFilterFunction(

self, universe: OptionFilterUniverse

) -> OptionFilterUniverse:

self.option_filter_ran = True

return universe.IncludeWeeklys().Expiration(

timedelta(40), timedelta(60)

)

def OnData(self, data: Slice):

# self.Debug(f"Has data? : {data.HasData}")

if not data.HasData:

return

for i in data.OptionChains: # only one option chain in this case, which is ES

optionchain: OptionChain = i.Value

if len([x for x in optionchain]) == 0:

continue

self.Debug("underlying price:" + str(optionchain.Underlying.Price))

140890_1634181455.jpg