Skip to main content
An algorithm file is an ordinary Python module. The engine imports it, so you can import numpy, polars, talib or anything else installed, and it calls the functions it finds by name:
  • context stores your strategy state and exposes the trading API.
  • data gives access to current and historical market data.
  • Lifecycle functions tell the engine when to set up, trade, prepare a session and report.
Most strategy work happens in two functions:

Mental model

initialize is your setup block. Look up assets, store parameters, register scheduled callbacks, configure controls, mount datasets. handle_data is your trading block. It runs on every emitted bar, reads data, checks portfolio state, places orders and records metrics. before_trading_start is an optional daily preparation hook. Use it for universe selection or pipeline output. Do not place orders there. compute_signals is an optional vectorized hook, computed once over the whole history before the first bar. See Vectorized Signals. analyze is an optional reporting hook after the backtest finishes.

Minimal algorithm

Main objects

Async rule of thumb

Everything that touches the engine is awaited:
A missing await does not raise. The strategy silently places no orders, which reads as a strategy that found no signal. ziplime mcp’s check_strategy_code flags missing awaits before a run.

API map

  1. Algorithm file
  2. Context API
  3. Market data
  4. Orders
  5. Portfolio and recording
  6. Scheduling and controls
  7. Futures, options and bonds
  8. Point-in-time datasets
  9. Vectorized signals
  10. Venues and calendars
  11. Pipelines
  12. Migrating from classic Zipline