Backtesting framework · Python
On synthetic random-walk prices, the backtester correctly finds no edge
This run is a control. On synthetic random-walk prices with regime-switching drift, a trend rule should not show reliable skill, and the walk-forward, bootstrap and deflated-Sharpe checks should say so. They do. SMA crossover's out-of-sample Sharpe is −0.33, with a 95 % interval from −1.06 to 0.47; its deflated Sharpe probability is 0.00 after 28 trials.
Synthetic data: seed 20240611, generated by make_fixture.py. These are not market prices.One asset (SYN0), 2014-01-02 to 2023-08-30Next-bar-open fills
Out-of-sample Sharpe, pooled over all test windows, with its 95 % bootstrap interval. The vertical rule at zero means no edge.
Is there an edge?
SMA crossover shows no edge out of sample: Sharpe −0.33, deflated probability 0.00 after 28 trials
Each year, parameters are chosen on the previous three years and scored on the next one. Pooled over 7 test windows, the 95 % bootstrap interval runs from −1.06 to 0.47. Deflating for 28 trials leaves a probability of 0.00 that the Sharpe is real, against 0.95 needed.
Every one-year window's interval includes zero
Annualized Sharpe per test window · dot = estimate, line = 95 % bootstrap interval, vertical rule = zero
| Test window | Chosen parameters | Sharpe | 95 % interval | Return | Buy-and-hold |
|---|---|---|---|---|---|
| 2016-11-25 to 2017-11-13 | SMA 50/100 | 0.33 | −1.61 to 2.78 | 0.8 % | 6.5 % |
| 2017-11-14 to 2018-10-31 | SMA 50/100 | −0.99 | −2.68 to 0.89 | −1.6 % | −26.1 % |
| 2018-11-01 to 2019-10-18 | SMA 20/100 | 0.68 | −1.98 to 2.94 | 0.7 % | −1.8 % |
| 2019-10-21 to 2020-10-06 | SMA 20/100 | −1.63 | −3.66 to 0.64 | −1.5 % | 2.9 % |
| 2020-10-07 to 2021-09-23 | SMA 20/100 | −1.08 | −3.19 to 0.67 | −1.1 % | −5.2 % |
| 2021-09-24 to 2022-09-12 | SMA 20/100 | −0.58 | −2.08 to 1.13 | −1.2 % | −2.2 % |
| 2022-09-13 to 2023-08-30 | SMA 50/200 | 0.18 | −2.22 to 2.57 | 0.2 % | 6.6 % |
Did it beat buy-and-hold?
It lost 3.6 % while buy-and-hold lost 19.3 %, mostly by holding cash
The strategy held the asset on 53 % of out-of-sample days and sat in cash otherwise, so a falling market hurt it less. Losing less in a synthetic drawdown is not an edge; the Sharpe interval above is the test of that.
Strategy equity stays near flat while buy-and-hold swings
Equity (USD) from $100,000 · stitched out-of-sample windows · 2016-11-25 to 2023-08-30
| Test window | Strategy return | Buy-and-hold return |
|---|---|---|
| 2016-11-25 to 2017-11-13 | 0.8 % | 6.5 % |
| 2017-11-14 to 2018-10-31 | −1.6 % | −26.1 % |
| 2018-11-01 to 2019-10-18 | 0.7 % | −1.8 % |
| 2019-10-21 to 2020-10-06 | −1.5 % | 2.9 % |
| 2020-10-07 to 2021-09-23 | −1.1 % | −5.2 % |
| 2021-09-24 to 2022-09-12 | −1.2 % | −2.2 % |
| 2022-09-13 to 2023-08-30 | 0.2 % | 6.6 % |
| All 7 windows | −3.6 % | −19.3 % |
Do fills and costs change the answer?
Look-ahead fills overstate return by 1.3 pp, and costs only lower Sharpe further
These two checks use the full sample (2014-01-02 to 2023-08-30) with fixed parameters (SMA 20/100), not the walk-forward windows. The −3.6 % here equals the walk-forward return by coincidence; the samples differ.
| Check (full sample, fixed parameters) | Value |
|---|---|
| Return, next-bar-open fills | −4.9 % |
| Return, same-bar fills (look-ahead) | −3.6 % |
| Look-ahead gap | 1.3 pp |
| Trades | 30 |
| Sharpe at 0 bps per trade | −0.36 |
| Sharpe at 5 bps per trade | −0.37 |
| Sharpe at 10 bps per trade | −0.38 |
| Sharpe at 25 bps per trade | −0.42 |
The look-ahead test is weak on this data. Bars are rebuilt from closes, so each open equals the previous close. Real open prices would show a larger gap.
Is there an edge?
Time-series momentum shows no edge out of sample: Sharpe −0.36, deflated probability 0.00 after 14 trials
Each year, parameters are chosen on the previous three years and scored on the next one. Pooled over 7 test windows, the 95 % bootstrap interval runs from −0.97 to 0.34. Deflating for 14 trials leaves a probability of 0.00 that the Sharpe is real, against 0.95 needed.
Every one-year window's interval includes zero
Annualized Sharpe per test window · dot = estimate, line = 95 % bootstrap interval, vertical rule = zero
| Test window | Chosen parameters | Sharpe | 95 % interval | Return | Buy-and-hold |
|---|---|---|---|---|---|
| 2016-11-25 to 2017-11-13 | 126-day lookback, skip 21 | 0.19 | −1.67 to 2.57 | 0.4 % | 6.5 % |
| 2017-11-14 to 2018-10-31 | 252-day lookback, skip 21 | −0.88 | −2.41 to 0.59 | −1.6 % | −26.1 % |
| 2018-11-01 to 2019-10-18 | 252-day lookback, skip 21 | 0.00 | 0.00 to 0.00 | 0.0 % | −1.8 % |
| 2019-10-21 to 2020-10-06 | 126-day lookback, skip 21 | −0.27 | −1.86 to 1.58 | −0.2 % | 2.9 % |
| 2020-10-07 to 2021-09-23 | 126-day lookback, skip 21 | −0.19 | −2.34 to 1.74 | −0.2 % | −5.2 % |
| 2021-09-24 to 2022-09-12 | 126-day lookback, skip 21 | −0.83 | −2.53 to 0.87 | −1.9 % | −2.2 % |
| 2022-09-13 to 2023-08-30 | 252-day lookback, skip 21 | −0.49 | −2.59 to 1.59 | −0.4 % | 6.6 % |
Did it beat buy-and-hold?
It lost 3.9 % while buy-and-hold lost 19.3 %, mostly by holding cash
The strategy held the asset on 48 % of out-of-sample days and sat in cash otherwise, so a falling market hurt it less. Losing less in a synthetic drawdown is not an edge; the Sharpe interval above is the test of that.
Strategy equity stays near flat while buy-and-hold swings
Equity (USD) from $100,000 · stitched out-of-sample windows · 2016-11-25 to 2023-08-30
| Test window | Strategy return | Buy-and-hold return |
|---|---|---|
| 2016-11-25 to 2017-11-13 | 0.4 % | 6.5 % |
| 2017-11-14 to 2018-10-31 | −1.6 % | −26.1 % |
| 2018-11-01 to 2019-10-18 | 0.0 % | −1.8 % |
| 2019-10-21 to 2020-10-06 | −0.2 % | 2.9 % |
| 2020-10-07 to 2021-09-23 | −0.2 % | −5.2 % |
| 2021-09-24 to 2022-09-12 | −1.9 % | −2.2 % |
| 2022-09-13 to 2023-08-30 | −0.4 % | 6.6 % |
| All 7 windows | −3.9 % | −19.3 % |
Do fills and costs change the answer?
Look-ahead fills understate return by 0.2 pp, and costs only lower Sharpe further
These two checks use the full sample (2014-01-02 to 2023-08-30) with fixed parameters (126-day lookback, skip 21), not the walk-forward windows.
| Check (full sample, fixed parameters) | Value |
|---|---|
| Return, next-bar-open fills | −5.7 % |
| Return, same-bar fills (look-ahead) | −5.9 % |
| Look-ahead gap | −0.2 pp |
| Trades | 13 |
| Sharpe at 0 bps per trade | −0.52 |
| Sharpe at 5 bps per trade | −0.56 |
| Sharpe at 10 bps per trade | −0.59 |
| Sharpe at 25 bps per trade | −0.69 |
The look-ahead test is weak on this data. Bars are rebuilt from closes, so each open equals the previous close. Real open prices would show a larger gap.
How fast is the vectorized engine?
With 1 asset the vectorized engine is 8.82× faster; the gap grows with asset count
The vectorized engine's time stays near 0.11 s from 1 to 50 assets, which is mostly fixed overhead. The event engine's time grows with the number of assets, reaching 54.7 s and a 502× ratio at 50 assets.
Event-driven time grows with assets; vectorized time stays flat
Median seconds per backtest (log scale) · Synthetic GBM with regime shifts, seed 7, 2520 daily bars (10 years)
| Assets | Vectorized (s) | Event-driven (s) | Event ÷ vectorized |
|---|---|---|---|
| 1 | 0.11 | 0.98 | 8.82× |
| 10 | 0.11 | 12.0 | 113× |
| 50 | 0.11 | 54.7 | 502× |
One laptop, one session. Measured once on an Apple M5 Pro (Python 3.12.13, Numba 0.68.1) and committed as benchmarks/results.json; CI does not re-run it.
Methodology
How this was measured
Prices come from make_fixture.py: a geometric random walk whose drift and volatility switch between bull, bear and sideways regimes. Within a regime, daily returns are independent. Regimes switch at random, so any trend a rule picks up is weak and noisy.
Walk-forward testing picks parameters on three years and scores the next year, then steps a year. The bootstrap resamples out-of-sample daily returns. The deflated Sharpe ratio discounts the average out-of-sample Sharpe for the number of parameter settings tried across windows.
What this shows
- The walk-forward, bootstrap and deflated-Sharpe checks report no edge where none is expected.
- SMA crossover's out-of-sample Sharpe interval, [−1.06, 0.47], includes zero.
- Trading less, not skill, explains the smaller loss than buy-and-hold.
What it doesn't show
- Performance on market prices. Every number here is simulated.
- That the checks would catch a real edge; this run only tests the null case.
- Results on the other 4 synthetic assets; the report uses one.
Reproduce
Run it yourself
git clone https://github.com/allenwang0/quantsim.git && cd quantsim
make setup
uv run python tests/fixtures/make_fixture.py
uv run quantsim report --prices tests/fixtures/synthetic_prices.csv --strategy sma momentum --out site
cd benchmarks && uv run python bench_engines.py # engine timingEnvironment for this build · 7 rows
| Field | Value |
|---|---|
| Prices | Seeded synthetic GBM with regime shifts, seed 20240611 |
| Bars | 2520 |
| Asset used | SYN0 |
| Bootstrap seed | 0 |
| Commit | dcbd6a0 |
| Built | 2026-11-26 |
| Benchmark machine | Apple M5 Pro, Python 3.12.13 |