backtest_lib.backtest.schedule.make_decision_schedule#
- backtest_lib.backtest.schedule.make_decision_schedule(schedule: str, start: datetime, end: datetime | None = None, *, inclusive_end: bool = True) DecisionSchedule[datetime]#
- backtest_lib.backtest.schedule.make_decision_schedule(schedule: Iterable[I], start: I | None = None, end: I | None = None, *, inclusive_end: bool = True) DecisionSchedule[I]
Create a decision schedule from an iterable or time-based string.
The schedule can be a re-iterable of comparable values or a string interval (e.g.,
"2h") or cron expression (e.g.,"0 * * * *") when paired with adatetimestart.Example
>>> import datetime as dt >>> from backtest_lib.backtest.schedule import make_decision_schedule >>> schedule = make_decision_schedule( ... "2h", ... start=dt.datetime(2021, 11, 13), ... ) >>> it = iter(schedule) >>> next(it) datetime.datetime(2021, 11, 13, 0, 0) >>> next(it) datetime.datetime(2021, 11, 13, 2, 0)
>>> cron_schedule = make_decision_schedule( ... "0 * * * *", ... start=dt.datetime(2025, 2, 1), ... ) >>> cron_it = iter(cron_schedule) >>> next(cron_it) datetime.datetime(2025, 2, 1, 1, 0) >>> next(cron_it) datetime.datetime(2025, 2, 1, 2, 0)
>>> schedule = make_decision_schedule( ... [dt.datetime(2025, 1, 1), dt.datetime(2025, 1, 2)] ... ) >>> list(schedule) [datetime.datetime(2025, 1, 1, 0, 0), datetime.datetime(2025, 1, 2, 0, 0)]
- Parameters:
schedule – Iterable of schedule values, interval string, or cron string.
start – Start value (required for string schedules).
end – Optional end value used to truncate the schedule.
inclusive_end – Whether the end bound is inclusive.
- Returns:
DecisionSchedule for the provided specification.