1. Home
  2. AI Trading
  3. Backtesting Explained: Test a Trading Idea First
AI Trading

Backtesting Explained: Test a Trading Idea First

Published on October 20, 2026 · by Qubira 9 min read
Backtesting Explained: Test a Trading Idea First

Every trading idea sounds convincing when someone explains it with a chart that goes up and to the right. Backtesting is the habit of asking a duller and more useful question: what would this idea have actually done, including the ugly parts? This guide explains backtesting in plain language, how to run a basic one without any special software, and, more importantly, the handful of traps that make a backtest lie to you in a friendly voice.

⚠️ Notice. This guide is educational and is not financial advice. Backtests describe the past and do not guarantee anything about the future. Invest only what you can afford to lose.
Useful, not magic
Our short answerA backtest is a filter for bad ideas, not a promise of good ones. If a rule cannot survive an honest test on old data, drop it. If it does, you have earned the right to test it further with small money, nothing more.

What backtesting really is

Imagine you have a rule: buy an index fund when its price closes above its average of the last 200 days, and move to cash when it falls below. Backtesting means taking the daily prices of that fund over, say, twenty years, applying the rule mechanically day by day, and recording what your account would have done. You end up with a growth curve, a final result, and, the part people skip, the worst stretch you would have had to sit through.

That last number is the reason we like backtesting. Final returns are exciting, but a strategy that makes 8% a year with a 50% drawdown is a very different thing from one that makes 7% with a 20% drawdown. Most people cannot sit through the first one, and a strategy you abandon at the bottom has an effective return of zero. Seeing the drawdown in advance, on a chart rather than in your stomach, is half the value.

What backtesting is not: a crystal ball. Markets change, rules that worked get crowded, and a long period of calm can hide a risk that only appears once in a decade. The honest framing is that history gives you evidence about whether an idea was sensible, never a guarantee that it will be.

A simple backtest you can run in an afternoon

You do not need software to understand the process; a spreadsheet will teach you more than a fancy platform that hides the mechanics. The steps are few, and the thinking behind each is what matters.

Start by writing the rule in words so precise that a stranger could follow it without asking questions: which asset, what triggers a purchase, what triggers a sale, and how much you put in each time. Vague rules (“buy when it looks strong”) cannot be tested, and the vagueness is usually where self-deception hides.

Next, get daily prices for the asset over a long period. Use data adjusted for splits and dividends, because otherwise an ETF that pays income will look worse than it was and a stock that split will show a phantom crash. Then add a column that computes your signal, here the 200-day average, and another that says whether you would be invested or in cash the next day. That detail is important: you decide at today’s close and can only act at tomorrow’s price. Using today’s price to trade today is a classic way to cheat without noticing.

Finally, compute the daily return of the asset, multiply it by your invested/cash flag, and chain those returns into a growth curve. Compare it with a boring benchmark, normally just buying and holding the same asset. If your clever rule cannot beat doing nothing, or can only do so by taking more risk, you have your answer, and it is a perfectly good answer.

Here is what to measure, and why each number earns its place:

MetricWhat it tells youHonest reading
Total / annual returnHow much the rule madeMeaningless without the benchmark next to it
Maximum drawdownThe worst peak-to-trough fallCan you actually live through this?
Number of tradesHow active the rule isFew trades means weak statistics; many means costs bite
Time in the marketHow often you were investedExplains why returns differ from the benchmark
Worst yearThe single ugliest periodA reality check on your nerves

The traps that make a backtest lie

The painful truth about backtesting is that the easy mistakes all make the results look better. That is exactly why they survive.

Overfitting is the big one. Suppose you test a 150-day average, then 180, then 200, then 210, and keep the one with the best result. You have not found a pattern; you have found the setting that happened to fit one particular stretch of history. Add a few more tuned parameters and you can make nearly any random price series look like a gold mine. The antidote is to prefer simple rules with few settings, and to check that neighbouring settings also work. If 200 days is great but 190 and 210 are terrible, you are looking at luck.

Look-ahead bias is using information you would not have had at the time, for example trading at a close you only know after the fact, or using a company’s final reported earnings before they were published. It often creeps in through spreadsheet formulas that reference the wrong row.

Survivorship bias appears when you test only the stocks that exist today. Companies that went bankrupt or were delisted vanish from the data, so the past looks safer than it was. If you test “buy the best stocks of an index”, make sure the list of that index at each date is the real one, not today’s.

Ignoring costs quietly inflates returns. Commissions, the gap between buying and selling price, taxes and, for leveraged products, financing fees all eat into a strategy that trades often. A rule that makes a small gain on paper per trade can be a loser once costs are subtracted.

Testing on the same data you designed on is the subtlest. The honest approach is to split your history: design the rule on one part, and then test it, once, on a period it has never seen. If the results collapse on the unseen period, that is the market telling you the rule was a story you told yourself.

Simple rules, few parameters
4.7
Tested across bull, bear and sideways
4.5
Costs and taxes included
4.2
Checked on unseen data
4.4
Fancy indicators and optimisation
1.5

These bars are our editorial view of what deserves your attention when you evaluate a backtest, not measured results. Notice that cleverness comes last.

Reading the result like a sceptic

When the test is finished, resist the urge to celebrate and start interrogating. How many trades were there? A strategy that fired six times in twenty years proves very little, because one lucky trade can carry the whole result. Where did the profit come from? If removing the best three days wipes out the edge, the strategy depends on luck and timing you cannot count on. How does it behave when conditions change? Look at the equity curve in the 2008 crash, the 2020 plunge and the sideways years in between, not only at the final figure.

Compare risk-adjusted outcomes, not just returns. A rule that matches buy-and-hold with half the drawdown can be a genuinely good outcome even if it earns a little less. Equally, a rule that beats the benchmark only by taking on leverage has not found an edge; it has bought more risk.

And be willing to accept a boring conclusion. Many of the most-publicised “systems” fail to beat simple buy-and-hold index investing after costs. Discovering that cheaply, on a spreadsheet, is a victory, not a failure. It is the exact job a backtest exists to do.

From backtest to real money, carefully

Even a solid backtest is only the first step. The next is to run the rule on paper, with no real money, for long enough to see it behave in live conditions and to notice the practical frictions that history hides: delayed orders, prices that move before you act, and your own temptation to override the rules. Then, if you still believe in it, start with an amount small enough that a bad outcome is an annoyance and not a disaster.

If you want a deeper grounding, a good book will teach you more than a dozen videos. You can browse trading and quantitative investing books on Amazon, and our review of AI trading books points at the ones we think are worth the money. Tools that automate testing are covered in our AI trading analysis platforms review, and once you hold several assets, a portfolio tracking app keeps the real picture honest. For the wider context, start from our AI trading guide, and read our piece on AI trading scams and red flags before you trust anyone selling a “proven” backtest, since a glossy curve with no method behind it is the oldest sales pitch in the business.

A word about AI helpers: asking a chatbot to write the code for your backtest is fine for speed, but it will happily produce code with look-ahead bias and then describe the results with confidence. Read what it wrote, test it on a case where you already know the answer, and never treat an AI-generated equity curve as evidence on its own.

What to keep in mind

  • Write the rule precisely, then apply it mechanically to adjusted historical data.
  • Look at drawdown and the benchmark, not only at the final return.
  • Distrust beautiful results: check overfitting, look-ahead, survivorship and costs.
  • Validate on unseen data, then on paper, then with small money.

Where we land

Backtesting is worth learning because it makes you harder to fool, starting with yourself. Do it with a simple rule, honest data and a sceptical eye, and it will save you from most bad ideas before they cost you anything. Do it with forty tuned indicators and a hunger for a pretty curve, and it will happily tell you what you wanted to hear. We would rather you finish with a dull rule you understand than an exciting one you cannot explain.

Informational content, not financial advice. Invest only what you can afford to lose. This page contains affiliate links: if you buy through them we may earn a commission at no extra cost to you.

FAQ

What is backtesting in plain words?
It means applying a set of rules to historical prices to see what would have happened if you had followed them back then. It does not predict the future; it tells you whether an idea was at least plausible in the past and how painful the ride would have been.
Do I need to know how to code?
No. A spreadsheet is enough for a simple rule such as 'hold when the price is above its 200-day average'. Coding (usually Python) helps when you want many assets, many tests and fewer manual errors, but it is a convenience, not a requirement.
Where do I get historical data?
Your broker, free finance portals and open data sources offer daily prices, and many charting platforms include a built-in tester. The important thing is data that is adjusted for splits and dividends; otherwise your results will be wrong in ways that are hard to spot.
What is overfitting?
It happens when you tweak a strategy until it fits the past perfectly, so it captures random noise instead of a real pattern. An overfitted strategy looks brilliant on old data and falls apart on new data. The more parameters you tune, the greater the risk.
How many years of data do I need?
Enough to include very different market conditions: a long rise, a crash, a sideways stretch. Ten to twenty years of daily data is a common starting point for liquid assets, and a strategy that has only ever been tested in a bull market has not really been tested.
If a backtest looks great, can I trust it?
Treat a great-looking result with suspicion rather than excitement. Check costs, check that you did not peek at future information, test on a period you did not use to design the rules, and then try it with tiny money or on paper before anything serious.
Can AI tools backtest for me?
They can speed up the setup, but they can also produce confident, wrong code and flattering charts. You still need to understand what is being tested. Be very wary of any service that sells backtested 'guaranteed' returns.