Lean icon indicating copy to clipboard operation
Lean copied to clipboard

Backtest Log Time != IAlgorithm.Time

Open AlexCatarino opened this issue 1 month ago • 2 comments

Expected Behavior

The timestamps match

Actual Behavior

Image

Potential Solution

N/A

Reproducing the Problem

class EnergeticSkyBlueButterfly(QCAlgorithm):
    def initialize(self):
        self.set_start_date(2025, 10, 29)
        self.set_cash(100000)
        self.add_equity("SPY", Resolution.MINUTE) 
        #self.schedule.on(self.date_rules.every_day('SPY'),self.time_rules.after_market_open('SPY', 10),self._market_open)
        self.schedule.on(self.date_rules.every_day('SPY'),self.time_rules.after_market_open('SPY', 11),self._market_open)
        self.schedule.on(self.date_rules.every_day('SPY'),self.time_rules.after_market_open('SPY', 12),self._market_open)
        self.schedule.on(self.date_rules.every_day('SPY'),self.time_rules.after_market_open('SPY', 13),self._market_open)
    def on_data(self, data: Slice):
        if not self.portfolio.invested:
            self.set_holdings("SPY", 1)
    def _market_open(self):
        self.log(str(self.Time))

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 28 '25 16:11 AlexCatarino

There are often times when the log timestamps are just not even remotely correct. I am not sure how to easily reproduce this... but here is screenshot of an example where i am occasionally outputting the real time, but log times are just stuck.

Image

Is there an remote chance that this bug actually gets address any time soon? It makes it very difficult to debug when going through logs like this.

saghassy avatar Nov 30 '25 06:11 saghassy

Hi @saghassy ,

Meanwhile, please add self.time to the self.log call:

message =  "TSLA: Buy 2, 300@..."
self.log(f'{self.time} :: {message}')

AlexCatarino avatar Dec 02 '25 16:12 AlexCatarino