Lean.Brokerages.InteractiveBrokers icon indicating copy to clipboard operation
Lean.Brokerages.InteractiveBrokers copied to clipboard

Two Option Data Events Within One Minute

Open AlexCatarino opened this issue 1 year ago • 0 comments

Expected Behavior

When subscribing to minute-resolution data, we receive one data point per minute.

Actual Behavior

Algorithm has consistently received one bar at the zeroth second and at the 54th:

2024-11-26 15**:16:03** : Time: 2024-11-26 10:16:01.419949 | Option: TSLA 241129P00332500 | Strike: 332.5 | BidPrice: 2.64 | AskPrice: 2.7 | UnderlyingPrice: 341.66 | Delta: -0.268349463384532 2024-11-26 15**:16:54** : Time: 2024-11-26 10:16:54.800595 | Option: TSLA 241129P00332500 | Strike: 332.5 | BidPrice: 0.0 | AskPrice: 0.0 | UnderlyingPrice: 341.57 | Delta: -0.268349463384532 2024-11-26 15**:17:00** : Time: 2024-11-26 10:17:00.023992 | Option: TSLA 241129P00332500 | Strike: 332.5 | BidPrice: 2.6 | AskPrice: 2.66 | UnderlyingPrice: 341.72 | Delta: -0.266020143338156 2024-11-26 15**:17:54** : Time: 2024-11-26 10:17:54.801257 | Option: TSLA 241129P00332500 | Strike: 332.5 | BidPrice: 0.0 | AskPrice: 0.0 | UnderlyingPrice: 341.64 | Delta: -0.266020143338156 2024-11-26 15**:18:00** : Time: 2024-11-26 10:18:00.002957 | Option: TSLA 241129P00332500 | Strike: 332.5 | BidPrice: 2.9 | AskPrice: 2.99 | UnderlyingPrice: 340.63 | Delta: -0.287038025529599 2024-11-26 15**:18:54** : Time: 2024-11-26 10:18:54.800301 | Option: TSLA 241129P00332500 | Strike: 332.5 | BidPrice: 0.0 | AskPrice: 0.0 | UnderlyingPrice: 340.81 | Delta: -0.287038025529599 2024-11-26 15**:19:00** : Time: 2024-11-26 10:19:00.068202 | Option: TSLA 241129P00332500 | Strike: 332.5 | BidPrice: 2.78 | AskPrice: 2.83 | UnderlyingPrice: 341.12 | Delta: -0.280001342839822

EDIT: Additional logging:

2024-11-27 14:46:00 : Time: 2024-11-27 09:46:00.042342 | Option: TSLA 241220C00340000 | Strike: 340.0 | BidPrice: 17.9 | AskPrice: 18.05 | UnderlyingPrice: 339.39 | Delta: 0.528016374631765Underlying TradeBar FF: False | Underlying QuoteBar FF: False | Option QuoteBar FF: False | 2024-11-27 14:46:54 : Time: 2024-11-27 09:46:54.800524 | Option: TSLA 241220C00340000 | Strike: 340.0 | BidPrice: 0.0 | AskPrice: 0.0 | UnderlyingPrice: 339.35 | Delta: 0.528016374631765Option TradeBar FF: True | 2024-11-27 14:47:00 : Time: 2024-11-27 09:47:00.072929 | Option: TSLA 241220C00340000 | Strike: 340.0 | BidPrice: 18.25 | AskPrice: 18.4 | UnderlyingPrice: 340.29 | Delta: 0.535756540535007Underlying TradeBar FF: False | Underlying QuoteBar FF: False | Option TradeBar FF: False | Option QuoteBar FF: False | 2024-11-27 14:48:00 : Time: 2024-11-27 09:48:00.004858 | Option: TSLA 241220C00340000 | Strike: 340.0 | BidPrice: 17.75 | AskPrice: 17.95 | UnderlyingPrice: 339.3 | Delta: 0.526544367034253Underlying TradeBar FF: False | Underlying QuoteBar FF: False | Option TradeBar FF: False | Option QuoteBar FF: False | 2024-11-27 14:49:00 : Time: 2024-11-27 09:49:00.020808 | Option: TSLA 241220C00340000 | Strike: 340.0 | BidPrice: 17.45 | AskPrice: 17.65 | UnderlyingPrice: 338.84 | Delta: 0.522526986378076Underlying TradeBar FF: False | Underlying QuoteBar FF: False | Option TradeBar FF: False | Option QuoteBar FF: False | 2024-11-27 14:50:00 : Time: 2024-11-27 09:50:00.036178 | Option: TSLA 241220C00340000 | Strike: 340.0 | BidPrice: 17.55 | AskPrice: 17.7 | UnderlyingPrice: 339.05 | Delta: 0.523696513196978Underlying TradeBar FF: False | Underlying QuoteBar FF: False | Option TradeBar FF: False | Option QuoteBar FF: False | 2024-11-27 14:51:00 : Time: 2024-11-27 09:51:00.075431 | Option: TSLA 241220C00340000 | Strike: 340.0 | BidPrice: 17.7 | AskPrice: 17.85 | UnderlyingPrice: 339.32 | Delta: 0.526679317994741Underlying TradeBar FF: False | Underlying QuoteBar FF: False | Option QuoteBar FF: False | 2024-11-27 14:51:54 : Time: 2024-11-27 09:51:54.800155 | Option: TSLA 241220C00340000 | Strike: 340.0 | BidPrice: 0.0 | AskPrice: 0.0 | UnderlyingPrice: 339.22 | Delta: 0.526679317994741Option TradeBar FF: True |

We can see it's not frequent (twice in 5 minutes). The option data was fill forwarded: "Option TradeBar FF: True |", and slice didn't have TradeBar and QuoteBar for the Underlying or QuoteBar for the Option.

2024-11-27 14:46:54 : Time: 2024-11-27 09:46:54.800524 | Option: TSLA 241220C00340000 | Strike: 340.0 | BidPrice: 0.0 | AskPrice: 0.0 | UnderlyingPrice: 339.35 | Delta: 0.528016374631765Option TradeBar FF: True |

Potential Solution

N/A

Reproducing the Problem

Deploy algorithm with TSLA's options:

from AlgorithmImports import *

class TestOptions(QCAlgorithm):

    def Initialize(self):
        # Configuración inicial
        self.SetStartDate(2024, 11, 18)  
        self.SetEndDate(2024, 11, 19)  
        self.SetCash(100000)          
        self.underlying = None
        self.option = None
        self.option_contract = None

        self.SetBrokerageModel(BrokerageName.InteractiveBrokersBrokerage, AccountType.Margin) 

        self.underlying = self.AddEquity("TSLA", Resolution.Minute)
        self.underlying.SetDataNormalizationMode(DataNormalizationMode.RAW)
        self.option = self.AddOption("TSLA", Resolution.Minute)
        self.option.SetDataNormalizationMode(DataNormalizationMode.RAW)
        # Let0s just select the ATM call
        self.option.SetFilter(lambda x: x.CallsOnly().FrontMonth().Strikes(0, 0))
        
    def OnData(self, slice):

        chains = slice.OptionChains.get(self.option.Symbol)
        if chains is None:
            return

        # First contract by deafult
        option = [contract for contract in chains][0]
         
        if option:
            msg = f"Time: {self.Time} | " \
                f"Option: {option.Symbol} | " \
                f"Strike: {option.Strike} | " \
                f"BidPrice: {option.BidPrice} | " \
                f"AskPrice: {option.AskPrice} | " \
                f"UnderlyingPrice: {option.UnderlyingLastPrice} | " \
                f"Delta: {option.Greeks.Delta}"
            trade_bar, quote_bar = slice.bars.get("TSLA"), slice.quote_bars.get("TSLA")
            trade_option, quote_option = slice.bars.get(option.Symbol), slice.quote_bars.get(option.Symbol)
            if trade_bar:
                msg += f"Underlying TradeBar FF: {trade_bar.is_fill_forward} | "
            if quote_bar:
                msg += f"Underlying QuoteBar FF: {quote_bar.is_fill_forward} | "
            if trade_option:
                msg += f"Option TradeBar FF: {trade_option.is_fill_forward} | "
            if quote_option:
                msg += f"Option QuoteBar FF: {quote_option.is_fill_forward} | "

            if self.live_mode:
                self.Log(msg)

System Information

QuantConnect Cloud.

Checklist

  • [x] I have completely filled out this template
  • [x] I have confirmed that this issue exists on the current master branch
  • [x] I have confirmed that this is not a duplicate issue by searching issues
  • [x] I have provided detailed steps to reproduce the issue

AlexCatarino avatar Nov 26 '24 19:11 AlexCatarino