---
title: "What is backtesting? Meaning, how it works and its traps"
url: "https://amaltash.com/articles/backtesting"
published: "2026-11-18T20:21:29.666500+00:00"
summary: "The short answer. Backtesting is running a fixed set of trading or investing rules over historical market data to see what those rules would have done. A backtest is a simulation, not a record of…"
---

# What is backtesting? Meaning, how it works and its traps

The short answer. Backtesting is running a fixed set of trading or investing rules over historical market data to see what those rules would have done. A backtest is a simulation, not a record of…

Written by Charvi Agarwal (COO); Arpit Agarwal (Founder & CEO); Amaltash Research (Amaltash Advisors LLC).
Reviewed by Arpit Agarwal (Founder & CEO); Charvi Agarwal (COO); The Amaltash Team (Editorial review).
Updated 2026-11-18 · Published 2026-11-18.

The short answer. Backtesting is running a fixed set of trading or investing rules over historical market data to see what those rules would have done. A backtest is a simulation, not a record of real trades. It can expose broken or risky rules, but it is not a forecast.

Interactive calculator on the page: https://amaltash.com/articles/backtesting

## Turn this into a rule

> Hold SPY. If it closes below its 200-day moving average, move to T-Bills. Buy back when it closes above the 200-day average. Use a 5% stop-loss and no more than one trade per week.

[Turn this into a rule](https://invest.amaltash.com/strategy-builder?plan=Hold+SPY.+If+it+closes+below+its+200-day+moving+average%2C+move+to+T-Bills.+Buy+back+when+it+closes+above+the+200-day+average.+Use+a+5%25+stop-loss+and+no+more+than+one+trade+per+week.)

Opens the Strategy Builder with this rule filled in. It starts building after a 3-second countdown; type to stop it. Nothing trades until you deploy.

## What is backtesting in trading?

Backtesting means testing an exact trading or investing rule on past market data, to check the rule before you use real money. Here is a rule: “hold the fund while it closes above its 200-day average, and sell when it closes below.” The 200-day average is the average closing price over the last 200 trading days. A backtest applies the rule day by day, using only what was known on each day.

The output is a simulated record: every trade the rule would have made, the account value over time and its biggest drop along the way. Nothing in it was traded. It is math about the past, built on guesses about prices, costs and timing.

So the result is hypothetical, and US regulators treat it that way too. The SEC’s Marketing Rule counts performance “backtested by the application of a strategy to data from prior time periods when the strategy was not actually used” as hypothetical performance.

This page covers the idea and its traps for any single rule. Testing a whole mix of funds, with rebalancing and a benchmark, is [portfolio backtesting](https://amaltash.com/articles/portfolio-backtesting).

## How do you backtest a trading strategy?

Every backtest, from a spreadsheet to a professional platform, follows the same six steps.

1. Write the rule exactly: what to buy, when to buy, when to sell (for example with a [stop-loss rule](https://amaltash.com/articles/stop-loss)) and how much to hold.
2. Pick the data: which stocks or funds, which dates, and whether prices include dividends. Use data as it was known at the time.
3. Step through each day and use only what was known on that day. Trade at the next price, not the one that triggered the signal.
4. Take out costs: trading fees, bid-ask spreads, slippage and, where relevant, taxes.
5. Look at the bad parts: the [max drawdown](https://amaltash.com/articles/max-drawdown), the time to recover and the number of trades.
6. Test the rule again on dates you did not use to build it.

## Trade backtesting for stocks, options and futures

Trade backtesting, or a trading backtest, usually means testing buy and sell rules on one stock or fund. Stock backtesting is the most common kind, because old stock prices are easy to find.

Option backtesting is harder. An option’s price depends on how much time is left and how much traders expect prices to swing. You need old option prices for every strike price and date, and that data costs more and often has gaps.

Futures backtesting has its own snag. Each futures contract ends on a set date, so your test has to roll from one contract to the next. Each roll has a cost, and different ways of joining contracts give different answers.

Amaltash’s Strategy Builder tests rules on US stocks and ETFs only. It does not test options or futures.

## Why is a backtest not a forecast?

A backtest answers one question: what would this rule have done then? You probably want to know what it will do next. Most bad backtests hide in the gap between the two.

Markets change, and a test only sees the past it was given. Classic traps can also make a backtest look better than any real account could have done. The table lists the common ones; the sections below define the biggest.

Common backtesting traps and how to spot them

| Trap | What goes wrong | Warning sign | What helps |
| --- | --- | --- | --- |
| Overfitting | The rule fits past noise, not a real pattern | Lots of settings; small changes break it | Fewer settings; test on dates you didn’t use |
| Look-ahead bias | The test uses facts nobody had on the trade day | It trades at the same close that gave the signal | Trade the next day; use data as it was then |
| Survivorship bias | Only stocks that still exist get tested | The list comes from today’s index | Include stocks that closed or were dropped |
| Data snooping | Many ideas tried; only the best one shown | No record of what else was tried | Count every version you tried |
| Ignoring costs | Fees and price gaps left out | The rule trades a lot | Add real costs and delays |
| Markets change | The test covers only one kind of market | No crash and no flat years in the test | Test across crashes, rallies and flat years |

Source: Bailey, Borwein, López de Prado and Zhu, Notices of the AMS (2014); Harvey, Liu and Zhu, Review of Financial Studies (2016).

## What is look-ahead bias?

Look-ahead bias is using information in a backtest that was not available on the day of the trade. It makes a rule look smarter than it could ever have been.

Common examples: buying at the same close that triggered the signal, using economic data revised later, or picking stocks from today’s index list. The fixes are point-in-time data and trading on the next bar.

For economic data, the St. Louis Fed’s ALFRED database keeps each past release, called a vintage, as it was on the day it came out. A test can then use only the numbers people actually had.

## What is survivorship bias?

Survivorship bias is testing only the assets that still exist today. Companies that went bankrupt, were delisted or merged away drop out of the data, so the test sees mostly survivors.

A rule tested on today’s stock list never meets the losers that vanished along the way. The guard is a dataset that keeps delisted stocks and closed funds, as they were on each date.

## Overfitting and data snooping: the trap that looks like skill

Overfitting is tuning a rule so closely to past data that it fits noise, not a lasting pattern. Data snooping is the same problem across many ideas: test enough of them and one will look great by luck. A great result on old data can come before a weak result on new data.

Bailey, Borwein, López de Prado and Zhu measured how fast this happens (Notices of the AMS, 2014). They studied strategies with no real skill, scored by the Sharpe ratio: return per unit of risk.

With 5 years of data, the best of 45 independent versions is expected to show a Sharpe ratio of 1 in the test. Its expected Sharpe ratio on new data is zero. With 2 years of data, 7 versions are enough.

Harvey, Liu and Zhu reached a similar view for academic research (Review of Financial Studies, 2016). With hundreds of factors already tested, they argue a new one should clear a t-statistic above 3.0, not the usual 2.0.

This matters for any tool that makes testing easy, including ours. Amaltash’s [Strategy Builder](https://amaltash.com/strategy-builder) runs backtests on past US stock and ETF prices, and it can try many settings for you. Each extra version you test raises the odds that the winner is luck. So treat a long list of tries as a reason for more doubt, not less.

A simple defense helps. Pick a rule you can explain in one sentence, and keep the settings few. Count every version you try. Save a stretch of dates you never use to build the rule, and test on those last.

## Costs and slippage: the gap between a test and real trades

Slippage is the difference between the price a backtest assumes and the price a real order gets. It comes from bid-ask spreads, fast markets and orders that are large for the market.

Costs come on top. The SEC’s investor bulletin on fees explains that transaction fees are charged each time you buy, sell or exchange an investment. Ongoing fees are charged even when you do not trade. A rule that trades often pays the first kind again and again.

In a taxable account, a sale at a gain can also bring a tax bill. Charge realistic costs and a one-bar delay, then see whether the rule still holds up.

## Free backtesting: what to check first

Many tools offer free backtesting, and free is fine for learning. You can start building and backtesting rules in Amaltash’s Strategy Builder for free. A free test has the same limits as any backtest: it is hypothetical, and it can’t predict results.

Paid or free, check these four things before you trust a tool’s results:

1. Does it include dividends, or only price changes?
2. Does it take out trading costs and price gaps?
3. Does it include stocks that no longer trade?
4. Can you pick the dates, so you can test more than one kind of market?

## Why you will not see backtest results here

Under the SEC Marketing Rule, a backtest is hypothetical performance. When it adopted the rule, the SEC said advisers “generally would not be able to include hypothetical performance in advertisements directed to a mass audience.” So this page explains backtesting and shows no backtest results for any strategy.

Inside the Strategy Builder, a backtest is a tool for you to check your own rules. Treat its output as a stress test of the rule’s logic and risk, not as a preview of returns.

## How to use a backtest well

Use a backtest to throw rules out, not to pick winners. It is good at showing a rule that trades too often, a drop deeper than you could sit through, or a rule that does something you didn’t mean. It is weak at proving a rule will work.

After the backtest, paper trade the rule. Paper trading means trading with pretend money in live markets. Then start small, check that real trades match what you expected, and stop if they don’t.

## Risks and limits

- Overfitting: a rule built to fit old data can fail on new data. Trying many settings makes this more likely.
- Look-ahead bias: a test that uses facts nobody had at the time looks better than real life could.
- Past results do not predict future results. Backtested results are hypothetical. No real account earned them.
- The rule or the code can be wrong. A rule may be set up differently than you meant, so read it before you test.
- Costs, price gaps and taxes make real results worse than a test. You can lose money.

## Frequently asked questions

### Is backtesting accurate?

It can show exactly what a rule would have done, if its data and costs are right. Whether that tells you anything about the future is a different question. Overfitting, missing costs and changing markets can all make it wrong.

### How many years of data do I need to backtest?

Enough to include several kinds of markets: at least one [stock market crash](https://amaltash.com/articles/stock-market-crash), one strong rally and one flat stretch. Short tests that cover only one kind of market say little.

### What is out-of-sample testing?

It is checking a rule on data that was not used to design or tune it, such as the most recent years held back. A rule that works only on the data it was tuned on is probably overfit.

### What is walk-forward testing?

You tune a rule on one stretch of data, test it on the next stretch, then roll both windows forward and repeat. It gives several out-of-sample checks instead of one.

### What is the difference between backtesting and paper trading?

A backtest replays a rule on past data. Paper trading runs the rule forward in real time with no real money, so it meets prices, delays and news the backtest never saw. Each catches problems the other misses.

### Can a backtest be trusted?

Trust it to find problems, not to promise results. A rule that fails a backtest probably has a flaw. A rule that passes still needs testing on new dates and paper trading.

## Sources

- [eCFR: 17 CFR 275.206(4)-1, Investment adviser marketing, paragraph (e)(8) defining hypothetical performance](https://www.ecfr.gov/current/title-17/chapter-II/part-275/section-275.206%284%29-1)
- [SEC: Investment Adviser Marketing, final rule release IA-5653 (December 2020)](https://www.sec.gov/files/rules/final/2020/ia-5653.pdf)
- [SEC Investor.gov: How Fees and Expenses Affect Your Investment Portfolio (Investor Bulletin)](https://www.investor.gov/introduction-investing/general-resources/news-alerts/alerts-bulletins/investor-bulletins/updated)
- [Federal Reserve Bank of St. Louis: ALFRED, archival economic data vintages](https://alfred.stlouisfed.org/)
- [Bailey, Borwein, López de Prado and Zhu: Pseudo-Mathematics and Financial Charlatanism, Notices of the AMS (May 2014)](https://www.ams.org/notices/201405/rnoti-p458.pdf)
- [Bailey, Borwein, López de Prado and Zhu: The Probability of Backtest Overfitting (SSRN)](https://papers.ssrn.com/sol3/papers.cfm?abstract_id=2326253)
- [Harvey, Liu and Zhu: …and the Cross-Section of Expected Returns, Review of Financial Studies (2016)](https://doi.org/10.1093/rfs/hhv059)

## Keep reading

- [Portfolio backtesting: how to backtest a portfolio](https://amaltash.com/articles/portfolio-backtesting)
- [Quant strategies explained](https://amaltash.com/articles/algorithmic-trading)
- [Trend following explained](https://amaltash.com/articles/trend-following)
- [Sequence-of-returns risk](https://amaltash.com/articles/sequence-of-returns-risk)
- [AI trading explained: how AI trading bots work](https://amaltash.com/articles/ai-trading)

---

Educational content published by Amaltash Advisors LLC. Nothing here is investment advice or a recommendation to buy or sell any security. All investing involves risk of loss, including loss of principal, and past performance does not guarantee future results.
