What you will learn
- Walk through backtesting a simple strategy end to end
- Follow the disciplined workflow and avoid the biases
- Compute an annualized return (CAGR)
- Interpret results honestly and deploy cautiously
This capstone pulls the unit together by walking through the process of backtesting a simple strategy from start to finish. It ties the strategy components, the testing methods, the biases to avoid, and the risk management into a single disciplined workflow. The example is deliberately simple, but the process and its lessons apply to strategies of any complexity, and the main theme, the ongoing fight against fooling yourself, runs through every step.
Moving average crossover backtest in Python (Coding With Russ)
Codes and backtests the exact example strategy of this capstone. Follow the workflow end to end.
A simple example strategy
Consider a classic, simple strategy: a moving-average crossover, drawn from the trend-following ideas of Unit 4. The rule is to buy when a short-term moving average crosses above a long-term moving average, taken as a signal that an upward trend is beginning, and to sell when the short-term average crosses back below the long-term one, signaling the trend has reversed. This is a momentum strategy in the family discussed earlier in this unit, and its simplicity makes it ideal for illustrating the backtesting process, though the same disciplined steps would apply to any strategy.
Code a simple SMA crossover strategy in Python (ATJ Research)
A second walkthrough of coding the crossover backtest. Reinforces the mechanics of simulating trades.
The disciplined workflow
- Define the strategy clearly: specify the exact signal, entry rule, and exit rule, leaving no ambiguity, since a systematic strategy must be fully precise, as the anatomy and signals lessons stressed.
- Obtain clean, point-in-time historical data: ensure the data is accurate and free of survivorship bias, and structure it so the strategy sees only what was known at each moment, avoiding the look-ahead bias that the dedicated lesson warned is a silent killer.
- Implement the backtest: feed the data to the strategy sequentially, simulating each trade using only past and present information, never the future.
- Include realistic transaction costs and slippage: subtract the commissions, spreads, and slippage that the costs lesson showed can turn a profitable-looking strategy into a losing one.
- Measure performance with proper metrics: evaluate the results using risk-adjusted and drawdown metrics from Unit 6 and the trade-level metrics from this unit, never a single cherry-picked number.
- Check rigorously for overfitting: validate on out-of-sample and walk-forward data, test parameter sensitivity, and demand an economic rationale for why the edge should exist.
Measuring the result: annualized return
When the backtest finishes, you summarize the result with the metrics from the last lesson. One of the most useful is the compound annual growth rate, or CAGR, which expresses the whole backtest as a single annualized return so strategies of different lengths can be compared. It is the steady yearly rate that would grow the starting capital into the ending capital over the test period.
- ending value = capital at the end
- beginning value = capital at the start
- years = length of the backtest
Compute the annualized return
A backtest grows 10,000 dollars into 12,100 dollars over 2 years. What is the CAGR, as a percent?
Being honest about the results
The most important step is the one most easily skipped: reading the results honestly. After running the backtest, the essential question is not merely whether the strategy was profitable but whether its edge is real and robust or an artifact of overfitting. A genuinely promising result holds up across out-of-sample periods, works across a range of parameter values rather than one fragile setting, performs in more than one market or era, and rests on a plausible economic reason. A suspicious result is spectacular but fragile, dependent on precise parameters, confined to one slice of history, and lacking any rationale beyond fitting the past. Honest interpretation means actively looking for reasons to doubt an attractive result, applying the skepticism that Unit 5 and this unit have made central.
The whole discipline of quant trading is a structured fight against self-deception. The market endlessly offers noise that looks like signal to those who wish to believe.
From promising backtest to cautious deployment
If a strategy survives this rigorous scrutiny and appears genuinely promising, the path forward follows the staged progression from the backtest-to-live lesson. The strategy should be paper traded to confirm it works on real-time unseen data and that the trading system functions correctly, then deployed live with minimal capital so that the inevitable surprises are discovered cheaply, and scaled up only gradually as live performance justifies confidence. Throughout, live results must be monitored against the backtest's expectations, with the discipline to cut the strategy if its edge proves illusory or decays. This cautious progression, never rushing from an attractive backtest straight to large live capital, is what protects against the reality gap that destroys most strategies.
The synthesis of the unit
Stepping back, the backtesting process embodies every major theme of this unit. The backtest is the central tool of quantitative trading and simultaneously its central danger, capable of making worthless strategies look brilliant. The biases, overfitting, look-ahead bias, survivorship bias, and underestimated costs, are everywhere and must be guarded against at every step. Risk management from Unit 6 and survival against transaction costs determine whether a real edge translates into real profit. And most apparent edges, on honest examination, turn out to be overfitting, which is why skepticism is the quant's most important trait. A genuine edge must be robust, rest on an economic rationale, and survive both realistic costs and live conditions, a demanding standard that the great majority of backtested strategies fail to meet.
The deepest lesson and the bridge forward
If one idea defines quantitative trading, it is the discipline of not fooling yourself, carried directly from the statistics of Unit 5. The whole enterprise is a structured fight against self-deception, because the market endlessly presents noise that looks exactly like signal to anyone who wants to believe they have found an edge. Quant trading is not about discovering a magic formula. It is about rigorously testing ideas while relentlessly guarding against the many ways backtests lie, managing risk so as to survive, and remaining honest even when honesty means abandoning a beloved strategy. This skeptical, disciplined mindset is the thread connecting this unit to the whole curriculum: the statistics of Unit 5, the risk management of Unit 6, the strategies of Unit 4, and the derivatives of Unit 7 all converge here, in the systematic, testable, risk-managed pursuit of edge. The edge, if it exists, is small and hard-won, and the discipline not to fool yourself is, in the end, what matters most.
Real edge or overfit?
Your moving-average crossover backtest is profitable only when the short average is exactly 9 days and the long is exactly 43 days, nudging either by a day destroys the profit, and it only worked in one 3-year window. What should you conclude?
This is overfitting. A real edge holds up across a range of parameter values rather than one fragile pair, works in more than one period or market, and rests on an economic rationale. A result that profits only at exactly 9 and 43 days in a single window, with no reason why, is an artifact of fitting the noise of that history and should not be traded.The fight against self-deception
In your own words, summarize the disciplined backtesting workflow and why the whole enterprise is a fight against fooling yourself.
Write an answer before comparing it with the model response.
Model answer
The disciplined workflow is to define the strategy precisely, obtain clean point-in-time data free of survivorship bias, implement the backtest so it uses only past and present information, include realistic transaction costs and slippage, measure performance with a panel of risk-adjusted and trade-level metrics rather than one cherry-picked number, and check rigorously for overfitting with out-of-sample and walk-forward testing, parameter-sensitivity checks, and an economic rationale. Only if it survives all that do I paper trade it and then deploy live in small, staged size while monitoring against expectations, ready to cut it if the edge proves illusory. The whole enterprise is a fight against fooling myself because the market endlessly offers patterns that look like signal but are really noise, and a backtest makes it dangerously easy to tune a worthless strategy until it looks brilliant. Every step, point-in-time data, realistic costs, out-of-sample validation, honest interpretation, is a guard against my own wish to believe I have found an edge. The edge, if real, is small and hard-won, and the discipline not to fool myself is what separates the quants who survive from those who blow up.