Backtesting strategies honestly
Every strategy looks brilliant in a backtest. Look-ahead bias, survivorship and overfitting, with a calculator for how good luck can look; the costs you must model, worked step by step; six sanity checks; why Indian F&O history can mislead; and how Quantopian's 2016 study of 888 trading algorithms found backtest Sharpe ratios had almost no power to predict live results.
Facts reviewed Oct 2026
Anyone can produce a backtest that turns ₹1 lakh into ₹100 crore. The trick isn’t clever code. It’s quiet self-deception: usually by accident, sometimes not.
A strategy that looks fantastic over 10 years of history, then loses money live, isn’t unusual. It’s the norm.
Knowing why separates a hobby script from something you’d trust with real money. This lesson covers the traps, the sanity checks, and the discipline that makes a backtest worth trusting.
The three deadly biases
Almost every backtest failure comes down to one of three problems.
1. Look-ahead bias
You use information in a decision that wasn’t available at the time.
Classic examples:
- Using today’s closing price to decide whether to buy today. You didn’t know the close until the market shut.
- Using quarterly earnings from the last day of the quarter. Results come out weeks later.
- Using today’s index lists for the past. The Nifty 50 today isn’t the Nifty 50 of 2015.
- Using adjusted prices without checking when a split or bonus was announced.
Even experienced quants trip on this. The fix is discipline. For every piece of data your strategy uses at time t, ask: “Was this actually known at time t?” If yes, keep it. If not, drop it, or delay it until it was.
2. Survivorship bias
You test only on companies that are still alive today. All the delisted, bankrupt or merged ones are silently missing. And, by and large, they did badly.
Say you backtest “buy Nifty 500 stocks with rising ROE” using today’s Nifty 500. You leave out every company that fell out of the index because it failed. That can inflate past returns a lot. Jet Airways, which stopped flying in 2019, is one company your 2015 self could have bought.
The fix is a point-in-time database. It shows the actual index members on each past date, including firms that later vanished. Paid data providers offer this. Free price archives usually don’t.
3. Overfitting
You keep tweaking until the backtest looks great. Change the moving average from 20 days to 22. Add a filter. Move the stop loss. Leave out 2020 as an “outlier”. Congratulations: you’ve fitted your rule to past noise.
Signs you’re overfitting:
- Many settings, or “knobs”. More than four or five is a warning sign.
- Fragile results: small changes to a setting cause big changes in returns.
- Heavy tuning on one asset, or one time period.
- Different settings needed for different market conditions.
The fix is out-of-sample testing. Split your history. Use the first 70% to develop and tune. Hold back the last 30%, untouched. Then run the final strategy on it, once. If the out-of-sample results look nothing like the in-sample ones, you were overfitting.
Even better is walk-forward analysis. Tune on a rolling window, then test on the next window, again and again. It’s slower, and much more honest.
If none of your variants has any real edge, the best backtest Sharpe still drifts up with the number you try: roughly √(2 ln N) ÷ √years. Try 100 variants on five years of data, and luck alone can produce a Sharpe around 1.4. A strategy must clear that bar, out of sample, before it means anything.
You try 1,000 variants of a rule on 4 years of data, and none has a real edge. Roughly what's the best Sharpe ratio luck alone could show?
√(2 × ln 1,000) ≈ √13.8 ≈ 3.7. Divide by √4 = 2, and you get about 1.9. A backtest Sharpe that high, after 1,000 tries, proves nothing.
Costs you must model
A live account bleeds in ways a naive backtest doesn’t see:
- Brokerage: for example, ₹20 or 0.03% per executed intraday or F&O order, whichever is lower, at many discount brokers. It adds up over 200 trades.
- STT: 0.1% on both the buy and sell of delivery trades, 0.025% on the intraday sell, 0.02% on futures sells, and 0.1% of the premium on option sells.
- Exchange charges, SEBI fees, GST and stamp duty: small one by one, but meaningful together.
- Slippage: the gap between the price your backtest assumed and what you’d actually get. Assume about 0.05% for liquid large caps, and 0.2% or more for mid caps.
- Impact cost: larger orders move the price against you.
Worked example. A delivery strategy trades ₹1 lakh a time, and makes 100 round trips a year.
- STT: 0.1% on the buy plus 0.1% on the sell = ₹200 per round trip.
- Slippage: about 0.05% each way, on a large cap = ₹100.
- Other charges: say about ₹50.
- Total: about ₹350 per round trip, or 0.35%.
- A year: 100 × 0.35% = 35% of each ₹1 lakh traded. That has to come out of the strategy’s gross return.
Strategies that show 25% a year in a naive backtest often drop to 12–15% after realistic costs. Sometimes they drop below zero.
Sanity checks every backtest should pass
Before you take a backtest seriously, ask:
- Does it make economic sense? If you can’t explain in one sentence why the edge should exist, be suspicious. Rules that work only because they worked before rarely last.
- How does it behave in known bad periods? Test across 2008, the 2013 “taper tantrum”, the 2018 small-cap crash and March 2020. If it blows up in one, that’s real information.
- What’s the worst fall, or maximum drawdown? Not just the average return. A 40% fall can make you quit before you ever enjoy the 30% a year.
- How many trades? A backtest built on 12 trades over 10 years proves nothing. Aim for 100 or more, for medium-frequency strategies.
- Is the Sharpe ratio realistic? Above 2, for a retail strategy on Indian stocks, should raise eyebrows. Above 3 is almost always overfitting, or a hidden bug.
- Have you paper-traded it? Run the algo in real time, without placing orders, for 3 to 6 months. Compare it with your backtest for the same period. If they differ, something is wrong.
An Indian trap: F&O rules keep changing
Indian derivatives rules change often. From 20 November 2024, each exchange could offer weekly expiries on only one benchmark index. NSE kept weekly Nifty options, and BSE weekly Sensex options. Bank Nifty weekly options ended, leaving only monthly contracts. Lot sizes also rose, and expiry days have moved since.
So an options backtest on older data may be testing a market that no longer exists. Spreads, rolls and open interest patterns have shifted too. Before trusting old F&O patterns, check which rules were in force at the time.
Tools
Common backtesting tools for Indian retail traders:
- Python, with pandas and numpy, and your own engine: the most flexible, and the most work.
- Ready-made Python frameworks, such as Backtrader, Zipline or Vectorbt. Good, but each has quirks.
- AmiBroker: a favourite of older Indian retail quants, especially for end-of-day systems.
- TradingView’s Pine Script: good for quick visual tests, weak for anything statistical.
Whatever you pick, the tool doesn’t save you from the biases above. Discipline does.
A real case: Quantopian’s 888 algorithms, 2016
Quantopian was a US platform where thousands of people wrote and backtested trading algorithms. That gave it rare data: many backtests, plus what happened next.
- 2016: four of its researchers published a study of 888 algorithms. Each had at least 6 months of live, out-of-sample results.
- The finding: the backtest Sharpe ratio had almost no power to predict live results. It explained under 2.5% of the differences in live performance.
- Overfitting showed up clearly: the more backtests an author ran on a strategy, the bigger the gap between backtest and live results.
- What did help a little: measures of risk, such as volatility and maximum drawdown, predicted live results better than past returns.
Worked example: what “under 2.5%” means. Say live Sharpe ratios across the 888 strategies vary a lot.
- The backtest Sharpe explains under 2.5% of that variation.
- So over 97.5% comes from other things: luck, overfitting, costs and changing markets.
- In practice, ranking strategies by backtest Sharpe is barely better than ranking them at random.
The lessons:
- A great backtest is weak evidence on its own.
- Every extra tweak adds to the risk of overfitting.
- Risk measures carry more information than headline returns.
Going further: why more testing can make things worse. Each new test is like buying another lottery ticket. Try enough variants, and one will look brilliant by chance, as the calculator shows. Researchers now “deflate” backtest Sharpe ratios for the number of trials run. They also keep a written record of every test, not just the winner. If you tried 50 ideas, say so, and raise the bar to match. The honest question isn’t “How good is my best backtest?” It’s “How good would the best of 50 random strategies look?”
Common mistakes
- Testing on today’s index list.
- Using data before it was published.
- Tuning until it looks good, then calling it a discovery.
- Leaving out costs and slippage.
- Trusting old F&O patterns after the rules changed.
Practice 1: You have 15 years of daily data, and plan a 70/30 split. Which years do you tune on, and which do you hold back?
- In-sample: 70% of 15 years = 10.5 years, for building and tuning.
- Out-of-sample: the last 4.5 years, untouched until one final test.
- Decide the split first, before looking at any results.
Practice 2: A backtest earns 22% a year before costs. It makes 60 round trips a year, each costing 0.25% of the money traded. Roughly what's left after costs?
- Cost drag: 60 × 0.25% = 15% a year.
- After costs: 22% − 15% ≈ 7% a year, before taxes. That’s below many safe returns.
Key takeaways
- Look-ahead bias: never use information that wasn’t available when the decision was made.
- Survivorship bias: use point-in-time lists, not today’s index.
- Overfitting: separate in-sample tuning from out-of-sample testing, and keep settings few.
- Model all real costs: brokerage, STT, GST, slippage and impact.
- Sanity-check every backtest. Does it make sense? Does it survive 2008 and 2020? Enough trades? A realistic Sharpe?
- Paper trade for 3 to 6 months before risking money.
- Quantopian’s 2016 study of 888 algorithms found backtest Sharpe ratios predicted almost nothing about live results.
Go deeper
- Marcos López de Prado: Advances in Financial Machine Learning, the standard text on backtest overfitting.
- NSE: historical reports archive, for past price data.
- Quantpedia: Quantopian’s paper on in-sample vs out-of-sample performance.