Lean
Lean copied to clipboard
Backtest Log Time != IAlgorithm.Time
Expected Behavior
The timestamps match
Actual Behavior
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
masterbranch - [x] I have confirmed that this is not a duplicate issue by searching issues
- [x] I have provided detailed steps to reproduce the issue
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.
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.
Hi @saghassy ,
Meanwhile, please add self.time to the self.log call:
message = "TSLA: Buy 2, 300@..."
self.log(f'{self.time} :: {message}')