Skip to main content

Backtesting

A backtest replays historical bars through a strategy, simulates fills, and reports performance. It answers "would this have worked?" — a useful question, as long as you remember it's not the same as "will this work?"

make backtest
# or
uv run python main.py backtest \
--strategy volume_spike --scanner volume \
--symbols NVDA,META,TSLA --start 2024-01-02 --end 2024-04-01 --capital 100000

Options

OptionDefaultMeaning
--strategyvolume_spikeStrategy to run
--scannervolumeUniverse scanner (none to skip)
--symbolsa 10-name listComma-separated candidates
--start / --endlast 30 daysBacktest window (YYYY-MM-DD)
--capital100000Starting capital

Reading the report

The engine prints a metrics block, for example:

=== Backtest Results ===
Capital $100,000.00 -> $103,420.00
Total Return 3.42%
Buy & Hold Return 2.10%
Sharpe Ratio 1.24
Max Drawdown 4.80%
Total Trades 37
Win Rate 54.05%
Profit Factor 1.61
...
  • Total Return vs Buy & Hold shows whether the strategy beat simply holding the symbols.
  • Sharpe / Max Drawdown / Profit Factor describe risk-adjusted quality.

How fills and P&L are simulated is documented in The Engine; how each metric is computed is in Indicators & Analytics.

Tuning the strategy

Once a backtest runs, search for better parameters with Optimization.