Calendar gates
The simplest way to rebalance weekly or monthly is a gate at the top ofhandle_data:
Scheduling callbacks
context.schedule_function(func, date_rule=None, time_rule=None, half_days=True, calendar=None)
Register an async callback with the same signature as handle_data.
date_ruledefaults to every trading day.time_ruleworks at any intraday emission rate — 1 minute, 5 minutes, an hour. On a daily run there is one bar per session, so the time rule is ignored.- Pass the time rule by keyword. A time rule in the
date_ruleposition is accepted with a warning.
Date rules
Time rules
Offsets must be between 1 minute and 12 hours.
Calendars
schedule_function uses the simulation’s trading calendar unless you pass calendar=calendars.US_EQUITIES or calendar=calendars.US_FUTURES:
Which hook for what
Trading controls
Controls are configured ininitialize and checked against every order before it is placed. Since 2.10.3 they are enforced — earlier versions accepted the limits and enforced none.
Error behavior
Withon_error="fail" (the default) a violating order raises TradingControlViolation. With on_error="log" the violation is logged as an error and the order goes through.
Asset restrictions
False from data.can_trade.
Cancel policies
Commission and slippage
Costs belong to the run, not to the strategy: pass them torun_simulation(...) or the CLI. See Costs & Commissions.