Skip to content

ScheduledUniverse.GetTriggerTimes ignores endTimeUtc's time part #9349

@grubelic

Description

@grubelic

Expected Behavior

The ScheduledUniverse.GetTriggerTimes method should return only the datetimes between its arguments startTimeUtc and endTimeUtc. It should be explicitly noted in the documentation whether the result will include the bounds if they are among the trigger times.

Actual Behavior

The method returns all the trigger times on the endTimeUtc's date, even those after endTimeUtc. The documentation doesn't say whether the bounds are included.

Potential Solution

Please convert the "do-while" loop into a while loop that checks if a time is smaller than (or equal to?) endTimeUtc before yielding it. Something like:

yield return times.Current;
while (times.moveNext() && times.Current <= endTimeUtc)
{
	yield return times.Current;
}

Please update the documentation to specify whether the bounds are included when they are among the trigger times.

Reproducing the Problem

from AlgorithmImports import *
import datetime as dt

class EnergeticRedOrangeTapir(QCAlgorithm):

    def initialize(self):
        self.set_start_date(2024, 9, 23)
        self.set_cash(100000)
        univ = ScheduledUniverse(
            self.date_rules.every_day("SPY"),
            self.time_rules.every(dt.timedelta(minutes=1)),
            lambda _: Universe.UNCHANGED
        )
        self.add_universe(univ)
        dates = list(map(str, univ.get_trigger_times(
            dt.datetime(2025, 1, 1, 10), dt.datetime(2025, 1, 8, 15, 32),
            MarketHoursDatabase.from_data_folder()
        )))
        for date in dates[-5:]:
            self.debug(date)

System Information

QuantConnect Cloud B4-12 backtest node

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions