output on the six days
Not called in this example: vol_target=None, so line 55 does not run. With a target it would return one annualised volatility per day, computed from returns up to that day.
Quant notes · private sheet · backtest.py
The five functions in the positions of the structure diagram, each with its code and the output it produces on the six-day example (closes 100, 102, 101, 104, 103, 105; signal 0, +1, +1, −1, −1, +1; no carry; no volatility target). Docstrings are omitted from the code; line numbers are those of the file. Dashed arrows: a function call, caller to callee. Solid arrows: data passed. The backtest column shows the results table built line by line. All numbers are computed in the page from the six closes.
Not called in this example: vol_target=None, so line 55 does not run. With a target it would return one annualised volatility per day, computed from returns up to that day.
Each row is one column of the table as the line that creates it leaves it. Read top to bottom: every row uses only rows above it. Line 62 (orange) is the one-bar lag.
| line | column | day 1 | day 2 | day 3 | day 4 | day 5 | day 6 |
|---|
| year | Return | MaxDD |
|---|
The six days fall in one calendar year, so one row.
CAGR and TurnoverPerYear annualise six days by 365/6; they are shown as the code computes them.
Windows with the defaults, train 3 years, test 1 year, on 7 years of daily data (illustrative layout, not a computed result):
Pink: training window (every grid entry is run; best Sharpe wins). Orange: test window (the chosen entry only). The orange windows, concatenated, are the out-of-sample results.
Selection log, one row per window (structure; values come from a real run):
| train_start | test_start | test_end | chosen | train_sharpe | test_sharpe |
|---|---|---|---|---|---|
| date | date | date | {"lookback": …} | number | number |
| A large and repeated gap between train_sharpe and test_sharpe indicates parameters fitted to noise. | |||||
Sources. xau-btc-models/src/backtest.py, 157 lines, as read on 30 October 2026; the six-day example and the selection-log layout follow the project's Code Walkthrough doc. All numbers are computed in the page from the six invented closes; no market data is used. Companion to Backtester implementation; part of quant-notes.