How to backtest a trading strategy

How do you backtest a trading strategy?

How to backtest a trading strategy comes down to four moves: define the rule precisely, run it against historical data as if it were trading at the time, charge it realistic costs, and then test it once on data you held back. The mechanics are simple. The discipline is in not fooling yourself, because nearly every error makes the result look better than it will be.

These steps work whatever tool you use, from a spreadsheet to a full research platform. They are ordered on purpose. Doing them out of order is how a strategy passes a backtest and then fails an account.

What are the steps, in order?

Step 1: Write the rule down completely

Before touching any data, write the strategy so precisely that two people would code it identically: what triggers an entry, what size, what triggers an exit, and what happens if both occur at once. Vague rules get quietly adjusted to fit the data.

Step 2: Get point-in-time data

Use data as it existed on each date, including companies that later went bankrupt, merged or were delisted. A history containing only today's survivors has already removed the failures your strategy would have bought.

Step 3: Split the data and put part away

Divide the history into a research period and a validation period. Set the validation period aside and do not look at it. It only has value if it is genuinely unseen.

Step 4: Model costs honestly

Charge commissions, the spread between bid and ask, slippage when orders move the price, and borrowing costs for short positions. For short-term strategies, costs often decide the result more than the signal does.

Step 5: Test on the research period and count your attempts

Run the rule and record every variation you try. Each adjustment makes a lucky result more likely, so if you tried many versions, expect the best one to be flattered by chance.

Step 6: Test on the validation period once

Run the final version on the held-back data, one time. If it fails, the honest conclusion is that the strategy failed, not that the validation period was unusual.

Step 7: Stress the result

Raise costs, delay entries slightly, remove the few best trades and try different periods. A strategy that only works under exact conditions will not survive real ones.

Step 8: Paper trade before any real money

Run it on a paper account in today's market. A backtest tests the idea against history. Paper trading tests the behavior now.

What results should make you suspicious?

  • A smooth, steadily rising result with few losing periods.
  • Results that collapse when costs are raised slightly.
  • Most of the profit coming from a handful of trades.
  • A strategy that only worked in one kind of market.
  • A large gap between research and validation results.
  • Performance that improved every time you adjusted the rule.

Real strategies have long stretches of disappointing results. A backtest without them is more likely to be fitted to the past than to be exceptional.

What tools can you use to backtest?

A spreadsheet

Fine for simple, slow strategies and for understanding the mechanics. Easy to introduce look-ahead errors by referencing a row you should not be able to see yet.

Your own code

The most flexible and the most dangerous, because every error is your own and nothing warns you. Worth it if you will also write tests for the backtester itself.

A research platform

Faster to start, and it usually handles data and costs for you. Check how it models fills and whether its data includes delisted companies.

How is backtesting different from paper trading?

A backtest replays history quickly to test an idea. Paper trading runs the strategy in real time in the current market without real money, which tests how it behaves with today's data, connections and timing. Neither reveals real execution costs. Both come before live trading, in that order.

The errors that inflate backtests, and how to judge a backtest someone else shows you, are covered in more depth under backtesting trading strategies.

Common questions

How do you backtest a trading strategy?
Write the rule down precisely, gather point-in-time historical data including delisted companies, set aside a validation period, charge realistic costs, test on the research period while counting your attempts, test once on the validation period, stress the result, then paper trade before using real money.
Can you backtest a trading strategy for free?
Yes. A spreadsheet and free historical price data are enough for simple strategies. The limitation is usually data quality, particularly missing delisted companies, which makes free backtests look better than they should.
How many trades does a backtest need?
Enough that no small group of trades decides the result. If removing a handful of the best trades changes the conclusion, you do not yet have enough evidence, however long the period tested.
What is the most common backtesting mistake?
Using information that was not available at the time, known as look-ahead bias. It includes using a day's closing price to decide a trade placed earlier that day, and testing on a list of companies that only includes survivors. Both make results look better than they could have been.
Should I backtest before paper trading?
Yes. The backtest tests the idea against history quickly and cheaply. Paper trading then tests behavior in the current market. Skipping the backtest wastes time on ideas history already rejects; skipping paper trading skips the test that most resembles reality.
What is walk-forward testing?
Repeating the research and validation split through time: research on one period, test on the next, then move forward and repeat. It shows whether a strategy keeps working as the market changes, rather than on a single held-back period.

TradeAgentic is an autonomous trading desk for macOS and Windows, licensed to operators and firms who intend to run it themselves.

Request licensing terms