Filtered contracts contain two extraneous strikes below and above:
2022-09-14 10:45:00 symbol MU, price 53.335, strikes [52.5, 53.0, 54.0, 55.0]
Potential Solution
Unknown
Reproducing the Problem
from AlgorithmImports import *
class Issue(QCAlgorithm):
def Initialize(self):
self.SetStartDate(datetime(2022, 9, 14))
self.SetEndDate(datetime(2022, 9, 14))
self.udl = self.AddEquity('MU', Resolution.Minute, dataNormalizationMode=DataNormalizationMode.Raw)
self.option = self.AddOption(self.udl.Symbol)
self.option.SetFilter(-1, +1, timedelta(days=0), timedelta(days=7))
def OnData(self, slice):
if self.Time.time() != time(10, 45):
return
oc = slice.OptionChains.GetValue(self.option.Symbol)
if oc is None:
return
strikes = sorted(set(c.Strike for _, c in oc.Contracts.items()))
self.Debug(f"{self.Time} symbol {self.udl.Symbol}, price {oc.Underlying.Price}, strikes {strikes}")
Comments
Further to the above, filtering with
a) Strikes(-1, 0) results in
2022-09-14 10:45:00 symbol MU, price 53.335, strikes [52.5, 53.0, 54.0, 55.0]
b) Strikes(0, +1) results in
2022-09-14 10:45:00 symbol MU, price 53.335, strikes [53.0, 54.0, 55.0, 56.0]
c) Strikes(0, 0) results in
2022-09-14 10:45:00 symbol MU, price 53.335, strikes [53.0, 54.0, 55.0]
d) Strikes(-1, -1) results in
2022-09-14 10:45:00 symbol MU, price 53.335, strikes [52.5, 53.0, 54.0]
From the documentation it is not clear what the expected output for a) b) c) or d) would be.
IMO, Strikes(-1, 0) should return a single strike below the price, Strikes(0, +1) should return a single strike above the price and Strikes(0, 0) should return none at all.
d) and any negative parameter value should result in an error.
The special case of price being exactly equal to a strike needs consideration and should be well-defined, e.g. Strikes(-1, +1) returning either that single strike only, or Strikes(-1, +1) returning that single strike plus one each below and above, if available. The wording of the comment in OptionFilterUniverse.cs:84 would support the latter.
Filtering option contracts with
Strikes(-1, +1)
Expected Behavior
Filtered contracts contain two strikes, one below and one above the underlying's price:
2022-09-14 10:45:00 symbol MU, price 53.335, strikes [53.0, 54.0]
as per the docs at https://www.quantconnect.com/docs/v2/writing-algorithms/universes/equity-options#11-Filter-ContractsActual Behavior
Filtered contracts contain two extraneous strikes below and above:
2022-09-14 10:45:00 symbol MU, price 53.335, strikes [52.5, 53.0, 54.0, 55.0]
Potential Solution
Unknown
Reproducing the Problem
Comments
Further to the above, filtering with a)
Strikes(-1, 0)
results in2022-09-14 10:45:00 symbol MU, price 53.335, strikes [52.5, 53.0, 54.0, 55.0]
b)Strikes(0, +1)
results in2022-09-14 10:45:00 symbol MU, price 53.335, strikes [53.0, 54.0, 55.0, 56.0]
c)Strikes(0, 0)
results in2022-09-14 10:45:00 symbol MU, price 53.335, strikes [53.0, 54.0, 55.0]
d)Strikes(-1, -1)
results in2022-09-14 10:45:00 symbol MU, price 53.335, strikes [52.5, 53.0, 54.0]
From the documentation it is not clear what the expected output for a) b) c) or d) would be.
Strikes(-1, 0)
should return a single strike below the price,Strikes(0, +1)
should return a single strike above the price andStrikes(0, 0)
should return none at all.Strikes(-1, +1)
returning either that single strike only, orStrikes(-1, +1)
returning that single strike plus one each below and above, if available. The wording of the comment in OptionFilterUniverse.cs:84 would support the latter.System Information
master, Lean Version: 2.5.0.0.14632, cloud environment
Checklist
master
branch