← Allen Wang Code ↗

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.

Out-of-sample Sharpe, pooled over all test windows, with its 95 % bootstrap interval. The vertical rule at zero means no edge.

Strategy
Out-of-sample Sharpe, 95 % interval−0.33[−1.06, 0.47]: the interval includes zeroBootstrap, 5,000 resamples · 7 one-year windows
Deflated Sharpe probability0.00after 28 parameter trials; 0.95 would indicate skill4 settings × 7 windows
Out-of-sample return−3.6 %Buy-and-hold: −19.3 %. In the market on 53 % of days.2016-11-25 to 2023-08-30 · not evidence of an edge
Look-ahead bias, same-bar fills+1.3 ppSame-bar fills overstate total return (30 trades)Full sample 2014-01-02 to 2023-08-30, fixed parameters

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

SMA crossover: out-of-sample results per one-year test window
Test windowChosen parametersSharpe95 % intervalReturnBuy-and-hold
2016-11-25 to 2017-11-13SMA 50/1000.33−1.61 to 2.780.8 %6.5 %
2017-11-14 to 2018-10-31SMA 50/100−0.99−2.68 to 0.89−1.6 %−26.1 %
2018-11-01 to 2019-10-18SMA 20/1000.68−1.98 to 2.940.7 %−1.8 %
2019-10-21 to 2020-10-06SMA 20/100−1.63−3.66 to 0.64−1.5 %2.9 %
2020-10-07 to 2021-09-23SMA 20/100−1.08−3.19 to 0.67−1.1 %−5.2 %
2021-09-24 to 2022-09-12SMA 20/100−0.58−2.08 to 1.13−1.2 %−2.2 %
2022-09-13 to 2023-08-30SMA 50/2000.18−2.22 to 2.570.2 %6.6 %
Out-of-sample daily returns, next-bar-open fills, parameters refit each window. Each window holds one year of daily returns, so intervals are wide.

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

SMA crossover: out-of-sample returns per window
Test windowStrategy returnBuy-and-hold return
2016-11-25 to 2017-11-130.8 %6.5 %
2017-11-14 to 2018-10-31−1.6 %−26.1 %
2018-11-01 to 2019-10-180.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-300.2 %6.6 %
All 7 windows−3.6 %−19.3 %
Blue: the strategy, stitched across test windows. Orange: buy-and-hold over the same days. Single synthetic price path, so no interval.

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.

SMA 20/100, full sample 2014-01-02 to 2023-08-30
Check (full sample, fixed parameters)Value
Return, next-bar-open fills−4.9 %
Return, same-bar fills (look-ahead)−3.6 %
Look-ahead gap1.3 pp
Trades30
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.

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)

Median of 5 runs, Apple M5 Pro
AssetsVectorized (s)Event-driven (s)Event ÷ vectorized
10.110.988.82×
100.1112.0113×
500.1154.7502×
SMA crossover 50/200. Median of 5 runs after a warm-up, no spread shown.

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 timing
Environment for this build · 7 rows
Build environment
FieldValue
PricesSeeded synthetic GBM with regime shifts, seed 20240611
Bars2520
Asset usedSYN0
Bootstrap seed0
Commitdcbd6a0
Built2026-11-26
Benchmark machineApple M5 Pro, Python 3.12.13