Skip to main content
Use scheduled functions when your strategy should run at specific times instead of on every bar. Use controls to enforce simple risk rules before orders are accepted.

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.
In daily simulations, the time_rule is ignored by the current scheduler because there is only one bar per session. In minute simulations, both date and time rules matter.

Date rules

Import from ziplime.utils.events or ziplime.api.
Examples:

Time rules

Offsets must be between 1 minute and 12 hours. Examples:

Calendars

schedule_function accepts calendar=calendars.US_EQUITIES or calendar=calendars.US_FUTURES.
If calendar is omitted, Ziplime uses the simulation trading calendar.

before_trading_start vs scheduled callbacks

Use before_trading_start for daily preparation that should happen before trading logic. Use scheduled callbacks for trading actions that should occur at a specific session time.

Trading controls

Controls are usually configured in initialize.

Long-only

Maximum leverage

run_simulation(..., max_leverage=...) also registers a leverage control.

Maximum position size

Pass an asset to limit only that asset. Use asset=None to apply the limit globally.

Maximum order size

Maximum order count

Error behavior

Most controls accept on_error="fail" by default. Depending on the control implementation, "fail" raises when a rule is violated. Use non-failing modes only when you intentionally want violations to be logged or ignored by that control.

Asset restrictions

context.set_asset_restrictions(restrictions, on_error="fail") registers a restricted list. Restriction classes are available from ziplime.finance.asset_restrictions and through ziplime.api:

Cancel policies

Import from ziplime.finance.cancel_policy or ziplime.api.

Commission and slippage setup

Backtest fill models are most commonly configured in run_simulation(...):
Zipline-style context.set_commission(...) and context.set_slippage(...) are available during initialization. Use them only when your exchange/blotter setup is designed to read those context-level models. For standard run_simulation usage, prefer the explicit runner parameters.