You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Only contracts with deltas between the filtered values should be made available to on_data()
Actual Behavior
Contracts with deltas both above and below the range are returned.
Potential Solution
Not a solution, but current work around is to remove the universe delta filter and post filter data slices in on_data{}. This is less efficient but filters by delta directly.
Reproducing the Problem
# region imports
from AlgorithmImports import *
# endregion
class SPX3delta(QCAlgorithm):
def initialize(self):
self.SetStartDate(2024, 10, 8)
self.SetEndDate(2024, 10, 8)
self.SetCash(800000)
index = self.add_index('SPX')
index_option = self.add_index_option(index.symbol, 'SPXW',)
index_option.set_filter(lambda u: u.include_weeklys().expiration(0, 0).delta(0.025, 0.035))
self._symbol = index_option.symbol
def on_data(self, data: Slice):
if self.portfolio.invested:
return
self.log(f"DATA TIME: {data.time}")
chain = data.option_chains.get(self._symbol)
if not chain:
self.log("NO CONTRACTS FOUND")
return
contracts = [x for x in chain]
self.log(f"CONTRACTS: {len(contracts)}")
for idx, contract in enumerate(contracts):
self.log(f"IDX: {idx}")
self.log(f"SYMBOL: {contract.symbol}")
self.log(f"STRIKE: {contract.strike}")
self.log(f"EXPIRY: {contract.expiry}")
self.log(f"DELTA: {contract.greeks.delta}")
self.market_order(contracts[0].symbol, -1)
Run the backtest code above and then observe the logged deltas are out of range
System Information
Running locally on MacOS
The text was updated successfully, but these errors were encountered:
This is expected because the options are filtered using our pre-calculated daily greeks but the ones in the contracts in Slice.OptionChains are modeled and calculated every time using QuantLib. Our pre-calculated greeks are calculated using our indicators (e.g. https://github.com/QuantConnect/Lean/blob/master/Indicators/Delta.cs). We plan on implementing intraday pre-calculated greeks in the future #8440
Note that even after intraday precalculated greeks are implemented there might still be slight differences since prices (and time till expiry) will change after midnight and so intraday greeks could still have values outside the filter range.
Expected Behavior
Given a filter such as:
Only contracts with deltas between the filtered values should be made available to
on_data()
Actual Behavior
Contracts with deltas both above and below the range are returned.
Potential Solution
Not a solution, but current work around is to remove the universe delta filter and post filter data slices in
on_data{}
. This is less efficient but filters by delta directly.Reproducing the Problem
Run the backtest code above and then observe the logged deltas are out of range
System Information
Running locally on MacOS
The text was updated successfully, but these errors were encountered: