Important: This issue only appears when setting the start date to 2022-01-26. Setting the start date equal to the end date (2022-01-28) results in options being filtered as expected (i.e. no 2022-01-26 expirations are returned).
Note using the Strikes() filter is not required to reproduce the issue, it just serves to reduce the log output.
I can reproduce the issue with other end dates, e.g. 2022-01-31
When testing many different start/end dates, the issue is mostly not present, but can reliably be reproduced with the start and end dates in the code below. Not a heisenbug.
from AlgorithmImports import *
from datetime import datetime, time, timedelta
class Issue(QCAlgorithm):
def Initialize(self):
self.SetStartDate(2022, 1, 26)
self.SetEndDate(2022, 1, 28)
self.udl = self.AddEquity('SPY', Resolution.Minute, dataNormalizationMode=DataNormalizationMode.Raw)
self.option = self.AddOption(self.udl.Symbol)
self.option.SetFilter(lambda u: u.IncludeWeeklys().Expiration(timedelta(days=0), timedelta(days=0)).Strikes(-5, +5))
def OnData(self, slice):
if self.Time.time() != time(9, 45):
return
oc = slice.OptionChains.GetValue(self.option.Symbol)
if oc is None:
return
expirations = set(c.Value.Expiry.date() for c in oc.Contracts)
self.Debug(f'{self.Time}, expirations with 0-DTE filter: {expirations}')
for c in oc.Contracts:
self.Debug(f' {c.Key} {c.Value.Expiry} {c.Value.Strike} {c.Value.Right}')
Filtering for 0-DTE options results in expired options being returned. Possibly related to #6235 ?
Expected Behavior
When using a filter of
Expiration(timedelta(days=0), timedelta(days=0))
on 2022-01-28, only SPY options expiring on 2022-01-28 should be returnedActual Behavior
When using a filter of
Expiration(timedelta(days=0), timedelta(days=0))
on 2022-01-28, SPY options expiring on 2022-01-28 and 2022-01-26 are returnedLog excerpt:
Potential Solution
Unknown
Reproducing the Problem
System Information
master, Lean Version: 2.5.0.0.14637, cloud environment
Checklist
master
branch