# Backtesting: what it is and how to backtest a strategy

> What backtesting is, how to backtest a trading strategy step by step, the biases that fool people, and why out-of-sample testing matters.

Written by [Tactfolio research team](https://tactfolio.com/about/editorial-policy.md), published 2026-10-16, updated 2026-10-16, data as of 2026-09-25.

Backtesting is testing a trading or investing rule on past prices to see how it would have done. You write the rule down, replay history day by day as if you had followed it, and look at the results. A backtest is hypothetical: it shows what a rule would have done, not what it will do.

## Key points

- A backtest replays exact rules on past prices. It cannot test a rule that is vague.
- The worst numbers matter more than the best ones. Read the biggest drop before the return.
- The common traps are peeking at the future, testing only survivors, tuning too much and forgetting costs.
- Testing on years you did not tune on, called out-of-sample testing, is the best check you have.
- US rules treat backtested results as hypothetical performance, with extra limits on how advisers can show them.

## What is backtesting in trading?

Backtesting in trading is running a strategy's rules over past market data to measure how it would have performed. It is the first step in [algorithmic trading](https://tactfolio.com/learn/algorithmic-trading.md), and it is how a [quantitative trader](https://tactfolio.com/learn/quantitative-trading.md) decides whether an idea is worth real money.

A backtest needs three things:

1. **Exact rules.** "Buy when the market looks cheap" cannot be tested. "Hold an S&P 500 fund while its price is above its 200-day average, otherwise hold Treasury bills" can.
2. **Price data.** Daily prices, ideally with dividends included, for every fund or stock the rules might hold.
3. **Honest assumptions.** When do trades happen? What does each trade cost? What happens to cash?

The output is a growth line and a few numbers. It tells you how the rule might have felt to live through.

## How do you backtest a trading strategy?

You backtest a strategy by writing exact rules, running them on past prices, and then trying hard to prove the result wrong. Here are the steps.

1. **State the idea and why it should work.** For example: "Stocks tend to keep falling in long bear markets, so stepping aside when the trend breaks should cut big losses."
2. **Write the rules.** Name the funds, the signal, how often you check it, and what you hold instead.
3. **Pick a long test period.** Include at least one bad market, such as 2008, 2020 or 2022.
4. **Run it with costs.** Charge something for every trade.
5. **Read the risk first.** Look at the [max drawdown](https://tactfolio.com/learn/max-drawdown.md), the biggest fall from a high point. Then look at return and the [Sharpe ratio](https://tactfolio.com/learn/sharpe-ratio.md), which is return per unit of swings.
6. **Compare with a fair benchmark.** Compare with what you would hold instead, such as an S&P 500 fund or a 60/40 mix of stocks and bonds.
7. **Test it on new data.** Run the same rules, unchanged, on a period you did not use while building them.

Our guide on [how to read a backtest](https://tactfolio.com/docs/concepts/reading-a-backtest.md) explains each number in the order worth reading it.

## A worked example

Say you test the 200-day rule above. You build it using prices from 2010 to 2019. You try a 150-day, 200-day and 250-day average. The 200-day version looks best.

Now you run that exact rule, with no changes, on 2020 to 2025. Those years are your out-of-sample test.

- If it still cuts drawdowns and keeps most of the return, that is a good sign.
- If it falls apart, the 200-day "win" was probably luck.
- If 150 and 250 days did much worse than 200 in the first test, be careful. A real effect should not hang on one exact number.

Tuning on one period and checking on another is one of the most useful habits in testing.

## What are the biggest backtesting mistakes?

Most backtests that disappoint fail for one of five reasons.

| Mistake | What it means | How to guard against it |
| --- | --- | --- |
| Look-ahead bias | The test uses information that was not known yet on that day | Use only data published by each trade date |
| Survivorship bias | The test only includes stocks or funds that still exist today | Prefer broad index funds, or data that includes dead companies |
| Overfitting | The rules fit past noise, not a real pattern | Keep rules simple and test on new data |
| Too many tries | Test enough versions and one looks great by luck | Count your tries and expect less from the winner |
| Ignoring costs | Trading fees, slippage and taxes are left out | Charge costs on every trade and test higher costs too |

**Look-ahead bias** is hard to spot. Economic numbers like unemployment come out weeks after the month ends, and some get revised later. A test that uses the final revised number on the first day of the month is cheating.

**Overfitting** is the big one. A 2014 paper by Bailey, Borwein, López de Prado and Zhu put numbers on it. With 5 years of data, trying about 45 versions is enough to expect one with a strong-looking Sharpe ratio of 1 on paper. Its real expected Sharpe ratio would be zero ([Notices of the AMS](https://www.davidhbailey.com/dhbpapers/backtest-pseudo.pdf)).

Harvey and Liu made a related point in 2015. A common habit was to cut a backtest's Sharpe ratio in half to allow for data mining. They showed the right cut depends on how many things were tried. Middling results deserve much bigger cuts than very strong ones ([Journal of Portfolio Management](https://people.duke.edu/~charvey/Research/Published_Papers/P120_Backtesting.PDF)).

Our page on [why past results mislead](https://tactfolio.com/docs/concepts/why-past-results-mislead.md) covers these traps with more examples.

## What is out-of-sample testing?

Out-of-sample testing means checking a strategy on data that played no part in building it. In-sample data is what you tuned on. Out-of-sample data is the fresh test.

The cleanest out-of-sample test is time itself. Many published strategies have now run for years after their papers came out. The record is mixed. [Vigilant Asset Allocation](https://tactfolio.com/strategies/vigilant-asset-allocation.md) beat the S&P 500 on risk-adjusted return over its full ETF history. But since the paper appeared in mid-2017, it has grown at well under half the S&P 500's rate. That figure comes from a hypothetical backtest as of September 25, 2026.

Fading after publication is common. Expect real results to be worse than the backtest.

## How do regulators treat backtests?

US regulators treat backtested results as hypothetical, because nobody earned them. The SEC's Marketing Rule, adopted in December 2020, defines backtested performance as a type of hypothetical performance ([SEC](https://www.sec.gov/rules-regulations/2020/12/investment-adviser-marketing)). Advisers who show it must have policies to make sure it fits the audience. They must also explain how it was made and its risks and limits ([final rule](https://www.sec.gov/rules/final/2020/ia-5653.pdf)).

When anyone shows you a backtest, ask how many versions they tried, what costs they used, and how it did after it was published.

## Try it on Tactfolio

[Tactfolio backtests](https://tactfolio.com/backtesting.md) US stocks and ETFs on daily prices, with dividends reinvested and a 0.05% cost on every trade. Each test also draws a "next-day open" line, the same rules trading at the next morning's price. A "reality checks" table repeats the trades at higher costs. For young funds, you can switch on [simulated history](https://tactfolio.com/docs/simulated-history.md), which is clearly labeled as modeled data. The full list of assumptions is in [what a backtest simulates](https://tactfolio.com/docs/backtests.md). You can build a rule and test it in the [strategy builder](https://tactfolio.com/builder), or start from a [classic strategy](https://tactfolio.com/strategies/classics.md) and change one thing at a time.

## Common questions

### What is backtesting?

Backtesting is running a set of investing rules on past prices to see how they would have performed. It shows returns, drops and how often the rules traded. The results are hypothetical, not a record of real trades.

### How far back should I backtest?

As far as your data honestly allows, and long enough to include at least one bear market. Ten to twenty years usually covers a crash such as 2008 or 2020. A test of only the last five years may never have met a real downturn.

### Is backtesting accurate?

A backtest is only as good as its data and assumptions. Even a careful one leaves things out, like taxes and the stress of living through a loss. It is most useful for weeding out bad ideas. It cannot tell you what comes next.

### What is a good backtest result?

There is no single cutoff. A good result holds up on years you did not tune on, survives higher costs, and has drops you could live with. A smooth line with no bad years is more often a warning than a win.

### Can AI do backtesting for me?

An AI assistant can build rules and run many backtests quickly. That speed makes overfitting easier, because it can try dozens of versions in minutes. Decide how you will pick the winner before it runs, and check the winner on separate years. Our guide to [backtesting with ChatGPT or Claude](https://tactfolio.com/learn/backtest-with-chatgpt.md) shows how.

## Put it into practice

- [Backtest a portfolio](https://tactfolio.com/trading-tools/backtest-portfolio.md): Backtest a portfolio of US stocks and ETFs. Enter tickers and shares, pick when to rebalance, and get the results with a link to share.
- [Monte Carlo simulator](https://tactfolio.com/trading-tools/monte-carlo-simulation.md): Run 10,000 random futures for your savings and see the chance your money lasts, with a bad case and a good case.
- [Crypto backtesting](https://tactfolio.com/crypto-backtesting.md): Backtest crypto rules on Hyperliquid perps like BTC and ETH, daily or hourly, with funding and costs counted.

## Sources

- [Pseudo-Mathematics and Financial Charlatanism: The Effects of Backtest Overfitting on Out-of-Sample Performance](https://www.davidhbailey.com/dhbpapers/backtest-pseudo.pdf), Bailey, Borwein, López de Prado and Zhu, Notices of the American Mathematical Society 61(5), 2014, accessed 2026-10-16
- [Backtesting](https://people.duke.edu/~charvey/Research/Published_Papers/P120_Backtesting.PDF), Campbell R. Harvey and Yan Liu, Journal of Portfolio Management 42(1), 2015, accessed 2026-10-16
- [Investment Adviser Marketing](https://www.sec.gov/rules-regulations/2020/12/investment-adviser-marketing), US Securities and Exchange Commission, accessed 2026-10-16
- [Investment Adviser Marketing, final rule (Release IA-5653)](https://www.sec.gov/rules/final/2020/ia-5653.pdf), US Securities and Exchange Commission, accessed 2026-10-16
- [Vigilant Asset Allocation (VAA)](https://tactfolio.com/strategies/vigilant-asset-allocation), Tactfolio, figures as of September 25, 2026, accessed 2026-10-16
