Capstone 5 - Statistical-Learning Research Pipeline
Build a time-aware backtest with regularization, honest transaction costs, and explicit model risk - and refuse to overfit.
Leads to: This pipeline’s discipline (time-aware CV, costs, OOS) is the backbone of the final capstone (18.8).
Learning Objectives
Click a status chip to cycle: Not started → In progress → Studied → Practiced → Needs review → Mastered.
- Design a time-aware (walk-forward) validation scheme that prevents look-ahead leakage.
- Apply regularization and explain the bias–variance trade-off it controls.
- Incorporate realistic transaction costs into a strategy’s net performance.
- Quantify model risk via out-of-sample degradation and multiple-testing awareness.
- Explain why in-sample performance is not evidence and design an honest test.
Key Vocabulary
- Walk-forward validation
- Training on a past window and testing on the next, rolling forward - the time-series analogue of cross-validation.
- Data leakage
- Information from the test period (or future) contaminating training, inflating apparent performance.
- Regularization
- Penalizing model complexity (e.g. ridge/lasso \(\lambda\)) to reduce variance at the cost of some bias.
- Transaction cost
- The cost of trading (spread, commission, slippage) that erodes gross returns; often decisive.
- Multiple testing
- Trying many strategies inflates the chance one looks good by luck; demands a higher bar or correction.
- Model risk
- The risk that the model is wrong or overfit, so realized performance falls short of the backtest.
Intuition & Motivation
The honest stance: in-sample performance is not evidence. Any sufficiently flexible model fits the past. The only thing that counts is out-of-sample, net-of-cost performance, evaluated in a way that respects the arrow of time - and even then, discounted for how many strategies you tested. This capstone is as much about intellectual honesty as code.
The brief
Build a walk-forward backtest for a simple predictive signal, with ridge regularization, a realistic per-trade cost, and an out-of-sample evaluation. Deliverable: code, an in-sample-vs-out-of-sample comparison, a cost-sensitivity curve, and a paragraph honestly discussing model risk and multiple testing. No profitability is promised or implied.
Required theory recap
- Bias–variance (Phase 11): test error \(=\text{bias}^2+\text{variance}+\text{irreducible}\); regularization trades a little bias for less variance.
- Ridge (Phase 11): \(\hat\beta=\arg\min\|y-X\beta\|^2+\lambda\|\beta\|^2\); \(\lambda\) chosen by time-aware CV.
- Time-series validation (Phase 12): walk-forward / expanding window; never shuffle time.
- Costs & capacity: net return \(=\text{gross}-\text{turnover}\times\text{cost}\); costs scale with trading frequency.
Time-aware validation: the arrow of time is not optional
Standard k-fold cross-validation shuffles rows - catastrophic for time series, because it trains on the future to predict the past. Use walk-forward: fit on \([t_0,t_1)\), test on \([t_1,t_2)\), roll forward. Every prediction uses only data available before it (equation 17.7). Any feature computed with future information (a full-sample mean, a look-ahead label) is leakage and must be purged.
Regularization and the bias–variance trade-off
With many candidate predictors and noisy financial data, an unregularized fit chases noise (high variance). Ridge shrinks coefficients toward zero, accepting a little bias for a large variance reduction - usually improving out-of-sample error. The penalty \(\lambda\) is itself chosen by walk-forward CV, never by looking at the test set.
Transaction costs: the signal killer
Gross returns flatter than net. A per-unit-turnover cost \(c\) (spread + slippage + commission) turns a beautiful gross curve into a flat or negative net one when the strategy trades a lot:
Model risk and multiple testing
If you test 100 strategies at the 5% level, ~5 will look ‘significant’ by pure luck. Backtest Sharpe ratios are inflated by the search that produced them. Guard with: a pre-registered hypothesis, a higher significance bar, out-of-sample holdout you touch once, and honest reporting of how many variants you tried. This is the deepest form of model risk.
Features are strictly point-in-time (17.6); \(\lambda\) is chosen on validation folds, never the final test; the report states the multiple-testing context honestly.
- Using k-fold CV that shuffles time - trains on the future, guaranteeing look-ahead leakage.
- Standardizing/normalizing features using full-sample statistics (leaks the test distribution).
- Tuning \(\lambda\) (or anything) on the test set, then reporting that test score as out-of-sample.
- Reporting gross returns and omitting transaction costs - the most common way to overstate an edge.
- Ignoring that you tried 50 variants; the best one’s backtest Sharpe is selection-biased upward.
- Treating in-sample \(R^2\) or Sharpe as evidence the strategy works.
- Validate walk-forward; every number a prediction uses must predate it (17.7).
- Fit all preprocessing (means, scalings, \(\lambda\)) on the training fold only; apply to the test fold.
- Subtract realistic costs and show a cost-sensitivity curve, not a single-point net Sharpe.
- Keep a final holdout you evaluate exactly once; report how many strategies you tested.
- Report OOS net performance with a standard error; if it’s within noise of zero, say so plainly.
Interactive: walk-forward validation with costs, no leakage
Implement the walk-forward split and a net-return calculation. The tests check that no split uses future data and that costs reduce returns as turnover rises.
Knowledge Check
Practical Exercise
You are reviewing a colleague’s backtest claiming a Sharpe of 2.1. Write a due-diligence checklist of at least six questions whose answers would determine whether you believe it, covering leakage, validation, costs, and model risk. For each, state what a bad answer looks like.
A due-diligence checklist (bad answers in parentheses):
- Was validation walk-forward or shuffled? (Bad: shuffled k-fold - look-ahead leakage.)
- Were features and scalings computed point-in-time, or using full-sample statistics? (Bad: full-sample means/normalization - leakage.)
- Were hyperparameters (\(\lambda\), thresholds) tuned on the test set? (Bad: yes - the ‘OOS’ score is contaminated.)
- Is the Sharpe gross or net of realistic costs, and what is the turnover? (Bad: gross only, high turnover - likely flat net.)
- How many strategies/variants were tried before this one? (Bad: dozens, no correction - selection-biased Sharpe.)
- Is the universe survivorship-free and point-in-time? (Bad: today’s index members - survivorship bias, Capstone-adjacent 17.6.)
- What is the out-of-sample degradation and the standard error of the Sharpe? (Bad: no OOS holdout, no error bar.)
If several answers are ‘bad’, the 2.1 is almost certainly an artifact. A trustworthy claim survives all of these with net, out-of-sample, leakage-free numbers reported with uncertainty - and still promises nothing about the future.
Lesson Summary
Retrieval Practice
Close the lesson and answer from memory before checking. This is deliberate, effortful recall - the single highest-yield study action.
A: Because shuffling breaks the time order and lets the model train on future data to predict the past - look-ahead leakage that inflates performance. Walk-forward trains on a past window and tests on the next, preserving the arrow of time.
A: \(r^{\text{net}}=r^{\text{gross}}-c\cdot\text{turnover}\). The curve matters because a strategy profitable only at zero cost is not tradeable; showing net performance across a range of cost assumptions reveals whether the edge is real or an artifact of ignoring costs.
Completion Checklist
- I can explain the core ideas in my own words
- I worked the derivations/examples by hand
- I completed the interactive workbench(es)
- I passed the knowledge check