Skip to content

7. Backtest and replay from the command line

Backtest

"$BIN"/tutorial-backtest --config configs/backtest-example.toml --data synthetic \
  --strategy first_mm --param edge_bps=0.002 --seed 7 --duration 60 \
  --out runs/tutorial/backtest --journal-out runs/tutorial/backtest.fmj
  • --config configs/backtest-example.toml supplies the synthetic market, fees, risk limits and the fill model. Its strategy is basic_mm; --strategy first_mm replaces it and ignores its [strategy.params].
  • --param edge_bps=0.002 sets a parameter; repeat --param for more. An unknown name is an error (exit codes).
  • --seed 7 --duration 60 seeds the synthetic market and the simulated venue and runs 60 s of simulated time. The engine's random generator keeps [engine] rng_seed (1 in this file).
tutorial-backtest: note: ignoring [strategy.params] of 'basic_mm' for --strategy first_mm
backtest first_mm  seed=7  md_events=16752  steps=18441  wall=0.03s
  net pnl                        -25.8169
  fills (maker / taker)          491 (491 / 0)
  ...
  outbound messages / sha256     1198 / 72b6e437ae296cb2bb1472f3a77e244dd6ce8da08690c8704ebe023cf857d75a

where the PnL came from (quote currency, 25823.54 traded notional)
  gross spread capture                 0.0066  +0.003 bps of 25823.54, mid at the fill
  fees paid                          -25.8235
  = net                              -25.8169
  ...
results written to runs/tutorial/backtest/{equity,fills,orders}.csv and summary.json
session journal: runs/tutorial/backtest.fmj
File Content
summary.json the metrics of the summary table
equity.csv one row per 1 s bar: realised and unrealised PnL, fees, position, mid, which sides were quoted
fills.csv one row per fill: time, side, price, quantity, fee, liquidity, the mid and the touch at the fill, the queue position, and the mid at each markout horizon
orders.csv one row per order message sent: new, cancel or replace

Prices, quantities, fees and PnL in the CSV files are decimals in quote currency or base units; ts_ns columns are nanoseconds since the epoch. An empty markout column means the run ended before that horizon (Backtesting).

Report

python3 tools/report.py runs/tutorial/backtest --config configs/backtest-example.toml
runs/tutorial/backtest/report.html

Open the file in a browser. It shows the equity curve and the inventory on one time axis, the PnL split into spread capture, mid drift and fees, the markouts, the fill quality and the configuration (Run report).

--config is optional; it names the instrument's currencies. With the Python package installed, fastmm report runs/tutorial/backtest is the same command.

Replay

"$BIN"/tutorial-replay --journal runs/tutorial/backtest.fmj --verify
journal  runs/tutorial/backtest.fmj: format v6, 19709 messages (16752 market data, 1198 outbound), rng_seed 1, strategy 'first_mm'
session  epoch 1, quoting enabled, cancel-replace venues 0, engine clock recorded
config   embedded in the journal (hash 13a9e3befa82d661)
replay   strategy=first_mm events=18447
recorded outbound 1198 msgs sha256 72b6e437ae296cb2bb1472f3a77e244dd6ce8da08690c8704ebe023cf857d75a
replayed outbound 1198 msgs sha256 72b6e437ae296cb2bb1472f3a77e244dd6ce8da08690c8704ebe023cf857d75a
replay MATCH

The journal holds the events the engine consumed and the configuration after the command-line overrides, so the replay needs no configuration file. rng_seed in the first line is the recorded [engine] rng_seed; the replayed strategy's logs go to stderr.

--verify compares each order message the replayed engine sends with the recorded copy. On the first difference it prints it and exits with code 1. A mismatch with the same binary means the strategy used something that is not an engine input (Determinism).

Next: 8. Trade on the simulated exchange