Skip to content

Backtest And Live Runs

AQE exposes execution brokers and market-data providers through UnifiedBroker.

Common combinations are:

  • PaperBroker + YahooFinanceDataFeed for local historical backtests.
  • PaperBroker + Mt5DataFeed when you want MT5 candles with simulated backtest execution.
  • Mt5Broker + Mt5DataFeed for live MetaTrader 5 execution.
aq-engine/src/core/broker/mod.rs
let execution = PaperBroker::new(AccountType::Paper, 100_000.0, 1);
let data = YahooFinanceDataFeed::new();
let broker = UnifiedBroker::new_backtest(execution, data);

For broker-specific setup, see Brokers & Datafeeds.

The backtest runner follows the current StrategyState::run_backtest implementation:

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 runs save artifacts to disk under:

  • backtests/<run_id>/backtest.db

AQE writes the SQLite artifact with trade logs, round trips, account history, insights, and bars. You can inspect those results in AlgoQuant Studio through Backtest Results, or with any SQLite reader.

Live mode uses the same strategy/runtime structure but subscribes to live data and trade updates.

You can run AQE live:

  • with AQS, by passing auth and enabling live sync
  • without AQS, by running run_live(None)
aq-engine/src/node/codegen.rs
if let Err(e) = state.run_live(auth).await {
eprintln!("Live execution failed: {:?}", e);
std::process::exit(1);
}

When auth is provided, AQE writes live state into AQS-scoped tables such as:

  • insights
  • strategy_accounts
  • strategy_equity_points
  • strategy_live_metrics
  • strategy_events

When auth is omitted, AQE can still run live locally without synchronising into AQS.

When AQE is compiled with the runtime and tui features and the process is attached to an interactive terminal, backtest and live runs open a Ratatui interface automatically. The TUI mirrors metrics, active insights, strategy variables, watched variable paths, AQS sync status, and runtime events.

Use --no-tui when you want the plain console log stream:

Terminal window
cargo run --features runtime,tui --release -- --no-tui

Read Terminal UI for the panel layout, controls, and live-run shutdown behaviour.