backtest-engine · multi-asset case study

Case study: SPY/TLT relative momentum walk-forward

SPY and TLT daily · 2016-11-21 to 2026-11-20 · 5028 bar events (2,514 per asset) · adjusted for distributions

Out-of-sample result The two-asset strategy returned 34.2857% over 2018-11-21 to 2025-11-28, with a Sharpe ratio of 0.3258 and a maximum drawdown of -46.6757%. The static 50/50 SPY/TLT reference returned 91.2796%. The strategy underperforms that reference.

What is measured

This uses real daily histories for two assets. On the first bar of each month the strategy computes each asset's return over the selected lookback and puts 100% of equity in the winner, 0% in the loser. The lookback is selected on each training block and applied to the following, non-overlapping test block. The first test callback emits both legs; the second callback at the same timestamp is a no-op.

The engine values the two assets independently, marks the portfolio at their latest closes and charges every fill separately. The reference is a static 50/50 SPY/TLT portfolio, bought once at the start of the out-of-sample period and never rebalanced, with no costs.

Data provenance

SourceYahoo Finance chart API
Retrieved2026-11-23T16:29:25Z
Symbols / barsSPY 2514 · TLT 2514
Range2016-11-21T21:00:00Z to 2026-11-20T21:00:00Z
CSV SHA-256aa12fdae89a3740aaa91bad77ec5e071e96384f49cbb418035c57e544739e076
Engine data hashb30e32289503cf9e0d9001f4aa1cb40cbed340fa4f06dba40fd5636b4b5130cb
AdjustmentOHLC scaled by Yahoo adjclose/close; volume unchanged

Walk-forward design

Training window: 504 timestamps. Test window: 252 timestamps. Step: 252, so test windows are contiguous and never overlap. Lookback grid: 63, 126, 252. The winner is chosen by training Sharpe, then total return, then grid order. 7 folds fit in the available history. Across the test folds the strategy selected SPY 69 times and TLT 22 times.

Out-of-sample performance

Total return
34.2857%
compounded test folds
Annualized volatility
17.8669%
daily returns, 252 periods
Sharpe ratio
0.3258
risk-free = 0
Max drawdown
-46.6757%
peak to trough
Turnover
39.7264x
traded notional / mean equity
Total cost
8,182.70
81.83 bps of initial capital
Fills
93
each asset fill counted separately
Bar events
3528
1764 timestamps x 2 assets
Multi-asset
SPY + TLT
one target weight per asset

Out-of-sample equity

0.73x 1.33x 1.93x 2018-11-21 2025-11-28 relative momentumstatic 50/50

The grey line is the static 50/50 SPY/TLT reference over the same test timestamps. It is not rebalanced and has no costs.

Strategy vs static 50/50

MetricRelative momentumStatic 50/50
Total return34.2857%91.2796%
Annualized volatility17.8669%12.2823%
Sharpe ratio0.32580.8189
Max drawdown-46.6757%-27.8624%

The strategy underperforms the static 50/50 reference on total return. The result is published as measured, including the drawdown and cost drag.

Capital allocation and per-asset costs

Target weights are fractions of total portfolio equity. The engine sizes each order as (w_i * E - position_i * price_i) / price_i at the decision close and fills it at that asset's next open. The strategy uses w_SPY + w_TLT = 1, so gross exposure is 100% and cash is the residual after fills. The engine does not enforce a budget; the strategy is responsible for keeping the sum of absolute weights at or below 1.

Every fill is priced and charged on its own asset. A switch from SPY to TLT produces a sell fill and a buy fill, so the fixed commission is paid twice. Commission is fixed + bps * |qty_i| * open_i / 10_000; spread and slippage use that asset's open and volume. The table below is the actual out-of-sample cost split.

AssetFillsNotionalCommissionSpreadSlippageTotal
SPY6222,633,022.922,263.302,263.309.004,535.61
TLT3117,556,560.781,755.661,755.66135.783,647.09
Total9340,189,583.694,018.964,018.96144.788,182.70

Folds

FoldTrainTestLookbackTrain SharpeTest returnTest SharpeTest max DDFillsCost
02016-11-21 to 2018-11-202018-11-21 to 2019-11-211260.3065-8.5554%-0.5801-14.5080%192,475.35
12017-11-21 to 2019-11-212019-11-22 to 2020-11-20630.537220.2835%0.8896-15.7027%151,045.27
22018-11-21 to 2020-11-202020-11-23 to 2021-11-22630.861621.8327%1.6593-6.6475%131,197.80
32019-11-22 to 2021-11-222021-11-23 to 2022-11-22631.1312-39.1397%-1.9685-46.1132%192,115.57
42020-11-23 to 2022-11-222022-11-23 to 2023-11-242520.446315.0671%1.0584-9.9743%7200.82
52021-11-23 to 2023-11-242023-11-27 to 2024-11-252520.117333.3437%2.4379-8.4056%6200.33
62022-11-23 to 2024-11-252024-11-26 to 2025-11-281261.67707.3108%0.4601-18.7552%14947.57

Look-ahead checks on the two-asset data

Honest control: PASSED Relative momentum (126) over the full series: 0 future reads, 0 divergent decisions. The masked replay reproduced every decision.
Multi-asset trap: FAILED, as required The trap peeks at both assets' next bar on every rebalance: 242 future reads, first kind as_of on 2016-11-21, requesting 2016-11-22. The first divergent decision is #0 on 2016-11-21: normal SPY +1.000000, TLT +0.000000; masked SPY +0.000000, TLT +0.000000. Divergent decisions: 121. Normal final equity 2,025,864.26; masked final equity 1,000,000.00.

The trap is cross-sectional: it does not use a single future price, it ranks two assets with their next-bar returns. The detector compares the per-symbol target weights and finds the first month where the ranking changes. In the masked replay every future request returns None, so the strategy stays flat. Strict mode rejects the future reads before a raw report can be produced.

Reproduce

python -m pip install .
python scripts/build_multi_asset_case.py
python scripts/verify_multi_asset_case.py

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