Backtesting means applying a trading system's fixed rules to historical prices to see how it would have performed. The result is hypothetical: it shows how the rules behaved on past data, not what they will earn in the future.
How it works
A fair backtest needs every decision written down before it runs:
- Rules: the exact entry, stop, exit and target conditions, with no room for judgment.
- Data: prices adjusted for splits, ideally including stocks that were later delisted, over a period that covers different market conditions.
- Fills: the price at which each order would realistically have executed. A signal calculated from today's close cannot be filled at that close without looking ahead; the next session's open is the conservative choice.
- Costs: commissions, bid-ask spreads and slippage on every entry and every exit.
- Sizing: how much is risked per trade, the largest position allowed and what happens when cash runs out.
The output is a trade list and an equity curve, summarized by statistics such as the compound annual growth rate (CAGR), maximum drawdown, win rate, profit factor (gross profit ÷ gross loss), average R and expectancy per trade, and the share of time spent in the market. A buy-and-hold benchmark such as SPY over the same window shows whether the system added anything.
How to read it
- Expectancy after costs comes first. Expectancy = win rate × average win − loss rate × average loss, measured in R; see risk-reward ratio. A small positive edge can disappear once costs are included.
- Drawdown is what you have to live through. A system returning 15% a year with a 40% drawdown is much harder to follow than its CAGR suggests.
- Count the trades. Twenty trades say very little; results based on a few hundred trades across several market environments are more informative.
- Look for robustness. Results should hold when a parameter changes slightly, such as a 45- or 55-day moving average instead of 50, and in different years.
- Keep data for later. Developing rules on one period (in-sample) and checking them once on a period not used before (out-of-sample) is the simplest guard against fooling yourself.
Worked example (illustrative numbers)
A system is tested on 200 trades. It wins 40% of them, the average winner is 2.0R and the average loser 1.0R:
| Step | Calculation | Result |
|---|---|---|
| Expectancy before costs | 0.40 × 2.0R − 0.60 × 1.0R | +0.20R |
| Costs per trade | 0.10% per side × 2, with the stop 5% below entry (1R = 5%) | 0.04R |
| Expectancy after costs | 0.20R − 0.04R | +0.16R |
Now an over-fitting check. Testing moving-average lengths from 10 to 100 days, the best result comes from 37 days at +0.35R per trade. But 30 and 45 days each produce about +0.05R. A peak that sharp, surrounded by weak neighbors, is most likely noise fitted to the past. The broad plateau at +0.16R is the more honest estimate, and even that should be checked on data the tests did not use.
Limitations and common mistakes
- Look-ahead bias. Using information that was not available at the time: filling at a price that was only known later, using financial data before its release date, or selecting stocks by a measure calculated at the end of the test.
- Survivorship bias. Testing only stocks that still exist leaves out the companies that went bankrupt or were delisted, which usually makes results look better than they were.
- Selection bias. Testing on today's market leaders or today's most liquid stocks quietly picks winners in advance.
- Over-fitting. Each extra rule and parameter makes the fit to the past better and the forecast worse. Trying many variations and reporting the best is data snooping.
- Unrealistic execution. Ignoring costs, gaps through stops and limited liquidity overstates results, most of all for short-term systems.
- One market regime. A test covering only a bull market says little about how the rules behave in a bear market.
In Clear Tape
In trading systems, any preset or your own system can be backtested on daily prices, in a holdout test (below) or over the last 1, 3, 5 or 10 years, on your watchlist, a single ticker, long-history ETFs or the screener's 500 stocks. You choose the entry fill (the next day's open, labeled conservative, or the signal day's close), costs of 0 to 100 basis points per side including slippage, and risk per trade of 0.1% to 5% of equity. The test starts with $100,000, caps any position at 20% of equity and uses no margin; stops are checked against each day's low, and gaps fill at the open. Results show CAGR, total return, maximum drawdown, win rate, profit factor, average R, expectancy after costs and time in the market, with an equity curve against SPY buy and hold and the full trade list. A recent-window test uses split-adjusted prices without dividends, for the system and SPY alike. Each report warns that only stocks listed today are tested (survivorship bias), and a test on the screener's list adds that it consists of today's most liquid stocks, chosen with hindsight. Building systems is free; backtests (Tools 20 a day, Pro 50) are available to Tools and Pro members.
The holdout test judges the rules on 2000–2014, then runs them unchanged from 2015 to now, against the same stocks bought and held in equal weights, with dividends included and idle cash earning the 3-month Treasury bill rate. It ends in one of four verdicts, Passed holdout, Trade-off, No edge or Not enough data, each with its reasons and with costs and survivorship bias disclosed. A library of published rules, each with its source and how Clear Tape's version differs, is a place to start; parameter sweeps are judged on the training period only and say whether the result is a plateau or an isolated peak; saved studies are re-checked every month. The Quantitative trading course walks through the whole process.
To see what the costs you assume mean for a single trade and over a year, in dollars and in R, use the free trading cost calculator.
For educational purposes only. Not investment advice.