Skip to content

Strategy Lifecycle Flow

AQE owns a StrategyState and runs the strategy in a predictable order:

  1. on_start(ctx) for one-time startup.
  2. universe(ctx) for static or inline symbol selection.
  3. registered universe models for modular symbol selection.
  4. asset metadata loading for the final merged universe.
  5. init(ctx, asset) once for each tradable asset.
  6. per-bar history updates, indicators, alpha models, strategy callbacks, and insight pipes.
  7. on_teardown(ctx) for shutdown cleanup.

Lifecycle logic blocks wrap the generated or inline strategy lifecycle methods. Universe models contribute symbols to the final universe.

The runtime backtest flow follows the implementation in StrategyState::run_backtest:

aq-engine/src/core/strategy/mod.rs
// 1. strategy.on_start(ctx)
// 2. load_universe() -> strategy.universe() -> broker.get_ticker_info()
// 3. alpha.start() per alpha
// 4. load_init() -> OnInit lifecycle logic -> strategy.init per asset
// 5. alpha.init(asset) per alpha per asset
// 6. broker.load_backtest_data()
// 7. loop: broker step -> on_bar() -> optional insight generation -> run_insight_pipeline()
// 8. strategy.on_teardown(ctx)
// 9. return BacktestResults

Generated AQS projects follow the same runtime order. The difference is that AQS generates parts of the strategy body from the node graph before AQE executes the strategy.