Backtesting
Running a backtest
bash
matchstick run --strategy src/strategy.json --data data/sample_data.csv --capital 100000Flags
| Flag | Required | Default | Description |
|---|---|---|---|
--strategy | Yes | - | Path to strategy file |
--data | No | generated | Path to CSV market data |
--mode | No | backtest | Execution mode |
--capital | No | 100000 | Initial capital ($) |
Without data
If you omit --data, the engine generates 1440 bars of synthetic data (30 days of 1-minute bars) using deterministic sine/cosine price movement.
Strategy logic
v0.1.0 uses a hardcoded mean reversion strategy:
- Calculate SMA(20) on the most recent 20 bars
- Entry: Buy when price drops 1% below SMA
- Exit: Sell when price returns to SMA
- Position size determined by FixedRisk method (1% risk per trade)
- Risk manager validates each trade against limits
Custom strategy loading is planned for a future release.
Data format
CSV with header row:
timestamp,symbol,open,high,low,close,volume
2024-01-02 09:30:00,AAPL,185.50,186.20,185.10,185.80,1500000Supported timestamp formats:
2024-01-02T09:30:00Z(ISO 8601)2024-01-02 09:30:002024-01-02
Output metrics
| Metric | Description |
|---|---|
| Final P&L | Absolute dollar profit/loss |
| Return | Percentage return on initial capital |
| Total Trades | Number of completed round trips |
| Win Rate | Percentage of profitable trades |
| Sharpe Ratio | Annualized risk-adjusted return (252 trading days) |
| Max Drawdown | Largest peak-to-trough decline |
Components used
The backtest engine uses all 5 library crates:
- core-types: OhlcvBar, Position, Timeframe
- indicators: IndicatorEngine for SMA calculation
- orders: OrderManager (initialized, used for tracking)
- risk: RiskManager for position sizing and trade validation
- strategy: StrategyManager for strategy lifecycle