The history request in question is a minute-resolution 1-bar request for QQQ on 2023/2/15. A few puzzling observations:

  • If I request 1 bar ~a minute after open on 2/15, I get no results. But if I request 2 bars, I do get a list of 2 bars (the last bar of 2/14 and the first bar of 2/15). [see backtest 1 Logs]
  • For 2/16, the request for 2 bars only gets the first bar of 2/16, which is inconsistent with what I would've expected seeing the 2-bar-request-results from 2/15. [see backtest 1 Logs]
  • If I schedule an after-market-open event and start the backtest on 2/15, the 2/15 event executes at 10am. But if I start the backtest on 2/14, the 2/15 event executes at 9:30am. [see backtests 1&2 Logs]
     

Would anyone be able to shed some light on this? Thank you!

 

 

Backtest 1 Log:

2023-02-15 00:00:00 :	Launching analysis for 85d18005dd227a8f543e0e97416eb766 with LEAN Engine v2.5.0.0.16001
2023-02-15 10:00:00 :	Requesting 1 bar:
2023-02-15 10:00:00 :	[]
2023-02-15 10:00:00 :	Requesting 2 bars:
2023-02-15 10:00:00 :	[<QuantConnect.Data.Market.TradeBar object at 0x7f6b4fb96c40>, <QuantConnect.Data.Market.TradeBar object at 0x7f6b4fb96c80>]
2023-02-15 10:00:00 :	list comprehension on 2 bars:
2023-02-15 10:00:00 :	[datetime.datetime(2023, 2, 14, 15, 59), datetime.datetime(2023, 2, 15, 9, 30)]
2023-02-16 09:32:00 :	Requesting 1 bar:
2023-02-16 09:32:00 :	[<QuantConnect.Data.Market.TradeBar object at 0x7f6b4f9e1a00>]
2023-02-16 09:32:00 :	Requesting 2 bars:
2023-02-16 09:32:00 :	[<QuantConnect.Data.Market.TradeBar object at 0x7f6b4f9e1a40>]
2023-02-16 09:32:00 :	list comprehension on 2 bars:
2023-02-16 09:32:00 :	[datetime.datetime(2023, 2, 16, 9, 30)]
2023-02-16 16:00:00 :	Algorithm Id:(85d18005dd227a8f543e0e97416eb766) completed in 0.44 seconds at 2k data points per second. Processing total of 806 data points.

Backtest 2 Log:

2023-02-14 00:00:00 :	Launching analysis for 8a26700719c997759af0743b30ea6893 with LEAN Engine v2.5.0.0.16001
2023-02-14 09:32:00 :	Requesting 1 bar:
2023-02-14 09:32:00 :	[<QuantConnect.Data.Market.TradeBar object at 0x7f23bc581240>]
2023-02-14 09:32:00 :	Requesting 2 bars:
2023-02-14 09:32:00 :	[<QuantConnect.Data.Market.TradeBar object at 0x7f23bbe5efc0>, <QuantConnect.Data.Market.TradeBar object at 0x7f23bbe60040>]
2023-02-14 09:32:00 :	list comprehension on 2 bars:
2023-02-14 09:32:00 :	[datetime.datetime(2023, 2, 13, 15, 59), datetime.datetime(2023, 2, 14, 9, 30)]
2023-02-15 09:32:00 :	Requesting 1 bar:
2023-02-15 09:32:00 :	[]
2023-02-15 09:32:00 :	Requesting 2 bars:
2023-02-15 09:32:00 :	[<QuantConnect.Data.Market.TradeBar object at 0x7f24230ec1c0>, <QuantConnect.Data.Market.TradeBar object at 0x7f24230f5bc0>]
2023-02-15 09:32:00 :	list comprehension on 2 bars:
2023-02-15 09:32:00 :	[datetime.datetime(2023, 2, 14, 15, 59), datetime.datetime(2023, 2, 15, 9, 30)]
2023-02-16 09:32:00 :	Requesting 1 bar:
2023-02-16 09:32:00 :	[<QuantConnect.Data.Market.TradeBar object at 0x7f24230cf100>]
2023-02-16 09:32:00 :	Requesting 2 bars:
2023-02-16 09:32:00 :	[<QuantConnect.Data.Market.TradeBar object at 0x7f24230cf2c0>]
2023-02-16 09:32:00 :	list comprehension on 2 bars:
2023-02-16 09:32:00 :	[datetime.datetime(2023, 2, 16, 9, 30)]
2023-02-16 16:00:00 :	Algorithm Id:(8a26700719c997759af0743b30ea6893) completed in 0.45 seconds at 5k data points per second. Processing total of 2,376 data points.

Code:

# region imports
from AlgorithmImports import *
# endregion

class VirtualGreenCoyote(QCAlgorithm):

    def Initialize(self):
        # Backtest 1
        self.SetStartDate(2023, 2, 15)
        # Backtest 2
        # self.SetStartDate(2023, 2, 14)

        self.SetEndDate(2023, 2, 16)
        self.qqq = self.AddEquity('QQQ', Resolution.Minute)
        self.Schedule.On(self.DateRules.EveryDay(self.qqq.Symbol), self.TimeRules.AfterMarketOpen(self.qqq.Symbol, 1.01), self.get_hist)
    
    def OnData(self, data: Slice):
        pass

    def get_hist(self):
        self.Log('Requesting 1 bar: ')
        self.Log(list(self.History[TradeBar](self.qqq.Symbol, 1, Resolution.Minute, extendedMarketHours = False)))
        self.Log('Requesting 2 bars: ')
        l2 = list(self.History[TradeBar](self.qqq.Symbol, 2, Resolution.Minute, extendedMarketHours = False))
        self.Log(l2)
        self.Log('list comprehension on 2 bars: ')
        self.Log([b.Time for b in l2])