backtest-engine · real-data case study

Case study: SPY moving average walk-forward

SPY daily · 2016-11-21 to 2026-11-20 · 2514 bars · adjusted for distributions

Out-of-sample result The walk-forward strategy returned 69.1985% over 2018-11-21 to 2025-11-28, with a Sharpe ratio of 0.7980 and a maximum drawdown of -12.9362%. It underperforms the 187.5521% buy-and-hold return over the same dates.

What is measured

This is a real daily history of SPY, not synthetic data. The strategy is a long/flat moving-average rule. Every fold selects its window only on the training block, then runs the winning window on the following, non-overlapping test block. Costs are charged on every fill: 1 bps commission, 2 bps spread, and 100 bps slippage at 100% participation.

The source is Yahoo Finance's chart API. OHLC values are multiplied by Yahoo's adjusted close, so splits and distributions are reflected in the price series. Volume is unchanged. Yahoo data is used here for research; check the provider's terms before commercial use.

Data provenance

SourceYahoo Finance chart API
Retrieved2026-11-23T15:04:30Z
Symbol / rowsSPY / 2514
Range2016-11-21T21:00:00Z to 2026-11-20T21:00:00Z
CSV SHA-2562db20ca1bd97775f20b913b2b4fc9620c3bbf130b735a1e1d1b6e0b4f3da8fff
Engine data hash4f5c488080735c1d7fd06b4e206ef8dda958f5c9671df3f99791a558a7cd6ebb
AdjustmentOHLC scaled by Yahoo adjclose/close; volume unchanged

Walk-forward design

Training window: 504 bars. Test window: 252 bars. Step: 252 bars, so test windows are contiguous and never overlap. Grid: 20, 50, 100, 200. The winner is chosen by training Sharpe, then total return, then grid order. 7 folds fit in the available history.

Out-of-sample performance

Total return
69.1985%
compounded test folds
Annualized volatility
10.0943%
daily returns, 252 periods
Sharpe ratio
0.7980
risk-free = 0
Max drawdown
-12.9362%
peak to trough
Turnover
85.3916x
traded notional / mean equity
Total cost
17,546.97
175.47 bps of initial capital

Out-of-sample equity

0.87x 1.88x 2.89x 2018-11-21 2025-11-28 walk-forwardbuy and hold

The grey line is buy-and-hold over the same test timestamps. It is shown as a reference and is not part of the walk-forward strategy. The strategy has no costs on the benchmark line.

Strategy vs buy and hold

MetricWalk-forward strategyBuy and hold
Total return69.1985%187.5521%
Annualized volatility10.0943%20.0574%
Sharpe ratio0.79800.8560
Max drawdown-12.9362%-33.7173%

The walk-forward strategy underperforms buy-and-hold on total return. This is the honest result, including the cost drag.

Folds

FoldTrainTestWindowTrain SharpeTest returnTest SharpeTest max DDFillsCost
02016-11-21 to 2018-11-202018-11-21 to 2019-11-211000.8533-3.3619%-0.3556-12.5754%433,226.19
12017-11-21 to 2019-11-212019-11-22 to 2020-11-20200.83918.6288%0.5927-10.0937%683,895.72
22018-11-21 to 2020-11-202020-11-23 to 2021-11-22201.245514.0713%1.5770-4.0515%644,458.02
32019-11-22 to 2021-11-222021-11-23 to 2022-11-221001.6990-4.3264%-0.5610-10.0353%221,747.61
42020-11-23 to 2022-11-222022-11-23 to 2023-11-24500.19075.9861%0.6976-6.7771%393,397.23
52021-11-23 to 2023-11-242023-11-27 to 2024-11-251000.233018.3017%1.7784-8.4056%15621.62
62022-11-23 to 2024-11-252024-11-26 to 2025-11-281001.823117.7863%1.9935-5.0714%6200.59

Look-ahead checks on the real data

Honest control: PASSED Moving average (100) over the full series: 0 future reads, 0 divergent decisions. The masked replay reproduced every decision.
Subtle leak: FAILED, as required Full-sample z-score: 1 future read (research_series) on 2016-11-21, requesting data through 2026-11-20. The first divergent decision is #0 on 2016-11-21: normal target weight +0.660893, masked target weight +0.000000. Divergent decisions: 2514. Normal final equity 1,209,445.25, masked final equity 1,000,000.00.

The subtle strategy does not peek at tomorrow's price. It computes the mean and standard deviation of the whole sample and normalizes each close with them. In the masked replay it only sees bars up to the clock, so the first standard deviation is zero and it stays flat. The detector compares the two decision traces and reports the first difference. The default strict mode rejects the research view before any report can be produced.

Reproduce

python -m pip install .
python scripts/build_case_study.py
python scripts/verify_case_study.py

The committed report hash is in docs/case_study.sha256. The numbers above come from this exact CSV and this exact code. No result is hand-entered.