Guide · Systematic
How to backtest a trading strategy in India
The short answer
A backtest runs a fully specified set of rules over historical data to estimate the distribution of that rule's outcomes: its expectancy, the spread of its results, and the depth of its drawdown. It does not predict one future return. The honest deliverable is expectancy plus variance plus drawdown, never a single number, and it is only as trustworthy as three things: unambiguous rules, honest costs, and testing on data the rule was not built on.
Most retail platforms will hand you a Sharpe ratio in five seconds. That number is not the problem; treating it as an answer is. A backtest is a simulation, and a simulation inherits every assumption you feed it. Feed it survivorship bias, zero costs, and one lucky market, and it will return a beautiful curve that means nothing. This guide is the method: how to run a backtest whose answer actually carries information, step by step, with the Indian specifics that decide whether a paper edge exists in reality. The catalogue of every way a backtest can quietly lie to you lives in its own companion piece, the bias treatise; here we build the process that defends against them.
What a backtest actually is
Start with the epistemics, because they change how you read every result that follows. A single trade has a random outcome. A rule applied over a hundred trades produces a sample from an underlying distribution you can never see directly. Backtesting is an attempt to estimate the shape of that distribution from history: not "this rule will make X next year" but "this rule has an expectancy of roughly this, a spread of roughly that, and in its worst historical stretch it drew down this far for this long."
Read that way, three habits follow immediately. First, one number is never the answer; you report expectancy, variability and drawdown together, because a rule with a healthy average return and a ruinous worst case is not a good rule. Second, the number of observations governs your confidence: an estimate from twenty trades is almost worthless no matter how clean it looks, while the same edge across four hundred trades spanning several market regimes carries real weight. Third, the backtest is evidence, not proof. It shifts your justified confidence up or down. It never reaches certainty, which is why the honest end of the process is a slow live ramp rather than a victory lap.
The seven-step protocol
A backtest whose answer means something is not a button; it is a sequence of real decisions, each of which can invalidate the result if you get it wrong. Here is the pipeline, and then each step in turn.
Step 1: Specify the rules unambiguously
A rule is testable only if a machine could follow it identically every time. Entry, exit, stop and position size must each be a precise condition, not a description. "Buy on a strong breakout" is not a rule; "buy when price closes above the highest high of the prior twenty sessions, size so that the distance to the stop risks a fixed fraction of equity" is. The test of specification is simple: if a human has to judge, it is not yet testable. Every discretionary "unless it looks weak" you leave in is a place where hindsight will sneak into the result.
Step 2: Choose the data, and clean it for India
Two data problems silently corrupt more Indian backtests than anything else. The first is corporate actions. If a stock does a bonus issue or a split, the raw price drops mechanically while shareholder wealth is unchanged. An unadjusted 1:1 bonus halves the quoted price overnight: to a backtest that looks like a 50 percent crash and will trigger every stop and every trend rule falsely. Prices must be adjusted for splits, bonuses and rights before you test a single bar; the mechanics of why a bonus moves the quoted price without changing value are set out in the bonus-issue guide.
The second is survivorship. If you test on the index's current constituents, you are testing only the companies that survived and were promoted, and quietly deleting the ones that were delisted or demoted. That flatters results, and in Indian small-caps the effect is large, not academic. The fix has a name: a point-in-time universe, the set of stocks that were actually in the index on each historical date, delistings and all.
Step 3: Include costs honestly
This is where most paper edges die, so it gets its own worked section below. In one line: model the full Indian statutory stack plus slippage and impact on every trade, because a strategy is only real if it clears its costs.
Step 4: Split in-sample and out-of-sample
Divide the history. Develop and tune on the in-sample block; hold the out-of-sample block back untouched, then run the frozen rules on it exactly once. If the edge survives on data the rule never saw during development, it is more likely to be real. If it collapses, you fitted noise. The discipline is fragile in one specific way: the moment you look at the out-of-sample result and go back to re-tune, that data is now in-sample, and its protective power is spent.
Step 5: Walk forward
A single split tests one slice of the future once. Walk-forward is the rolling, honest generalisation: optimise on a window, test on the next unseen block, roll both windows forward, repeat across the whole timeline. It mirrors how a live strategy is genuinely run, re-fitted periodically and traded blind into the near term, and it produces many out-of-sample segments across different regimes instead of one. A rule that only worked in a single bull phase is exposed far more reliably here than by any one split. The next figure shows how the windows roll.
Step 6: Choose metrics that matter
CAGR alone lies, because it says nothing about the suffering that earned it. The metrics that carry information, and the way each one misleads when read alone, are laid out in the metrics table below. The single most important is the least glamorous: the trade count, because it is the sample size that decides how much any other metric can be trusted.
Step 7: Apply the verdict rules
Before a rule earns any live capital, it must clear explicit gates: a minimum trade count large enough that the result is not luck; stability of the edge across up, down and sideways markets, not just the regime it was born in; and a positive expectancy that survives honest costs and the out-of-sample and walk-forward tests intact. Regime stability is its own discipline, because a rule that only works when the market trends needs a regime filter to know when to stand aside. A rule that passes on the friendly regime and fails on the hostile one has not passed.
The Indian cost stack, with a worked example
Costs are not a footnote to a backtest; on a high-frequency rule they are frequently the difference between an edge and a slow bleed. India layers several statutory charges on every trade, and then reality adds slippage on top. You must model all of it. The rates below are the current framework: verify the live figures against your exchange and broker before you rely on them, because statutory rates change with each budget.
| Component | Basis | Typical rate | Note |
|---|---|---|---|
| Securities Transaction Tax (STT) | Trade value | Delivery 0.1% each side; intraday 0.025% on the sell | The largest statutory line on delivery |
| Exchange transaction charge | Trade value | ~0.003% (NSE cash) | Set by the exchange; varies by segment |
| SEBI turnover fee | Trade value | 0.0001% | The smallest line, but real |
| Stamp duty | Buy side only | 0.015% delivery; 0.003% intraday | Uniform national rate since 1 July 2020 |
| GST | On brokerage + charges | 18% | On the service fees, not on trade value or STT |
| Depository (DP) charge | Per scrip, delivery sell | A flat rupee fee per scrip | Fixed, so it bites small orders hardest |
| Slippage and impact | Trade value | ~0.05% to 0.20%+ | Worse on thin counters and large orders |
Now watch a plausible edge meet that stack. Suppose an intraday rule shows a gross average gain of 0.45% per round-trip on a liquid stock near ₹500, which looks like a comfortable edge. Model the intraday costs honestly on each side and it is a different picture.
| Line | Effect on the round-trip | Running edge |
|---|---|---|
| Gross edge (assumed) | +0.45% | +0.45% |
| STT (intraday, sell side 0.025%) | −0.025% | +0.425% |
| Stamp duty (buy 0.003%) | −0.003% | +0.422% |
| Exchange charge (~0.003% each side) | −0.006% | +0.416% |
| SEBI fee + GST on charges | −0.002% | +0.414% |
| Slippage + impact (~0.20% each side) | −0.40% | +0.014% |
| Brokerage + its GST | − varies | near zero or negative |
The statutory taxes are small; slippage is the killer. A gross edge of 0.45% that looked ample is almost entirely consumed before brokerage, and once realistic fills and commission are added, the rule that "worked" in a zero-cost backtest is a way to pay the exchange for the privilege of trading. This is not pessimism, it is arithmetic, and it is exactly why a costed backtest is the only kind worth reading. Building the cost model correctly, and every other guard in this pipeline, is precisely what the method we teach is built around.
In-sample, out-of-sample and walk-forward, in one picture
The three splitting ideas are easiest to see on a timeline. A plain split trains on the early history and tests once on the tail. Walk-forward slides that arrangement along, producing a chain of separate train-then-test cycles that together cover many market conditions.
The metrics that matter, and how each one lies alone
Every metric compresses the outcome distribution into a number, and every compression throws information away. The skill is reading them as a panel, each one covering another's blind spot, with the trade count underneath as the thing that says how much to trust the rest.
| Metric | What it measures | How it misleads alone |
|---|---|---|
| CAGR | Compound annual growth of equity | Says nothing about the drawdown suffered to earn it; two identical CAGRs can hide wildly different pain |
| Maximum drawdown | The deepest peak-to-trough equity fall | Depth without duration understates it: a shallow drawdown that lasts two years can end a strategy that a sharp brief one would not |
| Exposure-adjusted return | Return relative to time actually in the market | Ignored, it flatters an always-invested rule over a selective one that only acts on its edge |
| Profit factor | Gross profit divided by gross loss | A single outlier trade can inflate it; a high figure on ten trades is noise, not skill |
| Sharpe (intuition) | Return per unit of volatility | Punishes upside volatility as if it were risk, and is easily gamed by leverage or by a short sample; useful, not sacred |
| Trade count (N) | The sample size behind every figure above | The one number that cannot mislead by itself: a small N simply means none of the others can be trusted yet |
Notice the deliberate demotion of the Sharpe ratio. It is a reasonable intuition, return earned per unit of wobble, and a terrible idol. A short sample, a dose of leverage, or a rule that happens to avoid volatility can all flatter it, which is why it belongs in a panel and never on a pedestal.
Reading an equity curve
The most information-dense output of a backtest is the equity curve itself, and the single most important lesson is that the same CAGR can draw two completely different curves. One climbs in a steady line you could hold through; the other reaches the identical endpoint through violent lunges and long, grinding drawdowns almost no one would actually survive. The endpoint is equal; the experience, and the odds you stay in the seat, are not.
From backtest to live: the honest bridge
A passed backtest is a hypothesis with supporting evidence, not a licence to deploy capital at size. The bridge from simulation to live money has three deliberate stages, and each exists because the backtest is evidence rather than proof.
First, paper trade the rule forward on live data before risking anything. This catches the gap between "the historical data said this bar filled here" and "the live market actually moved like this," including execution frictions a backtest cannot fully see. Paper trading is the forward-testing stage that no amount of historical fitting can replace, and its own mechanics and traps are covered in the paper-trading guide. Second, ramp size slowly: begin live at a small fraction of the intended position and scale up only as real fills confirm the paper result, so an unpleasant surprise costs a little rather than a lot. Third, hold the honest expectation that live will underperform the test.
FAQ
Frequently asked questions
What is backtesting a trading strategy?
+Backtesting is running a fully specified set of rules over historical data to see how it would have behaved. Done honestly, it does not predict a single future return; it estimates the distribution of the rule's outcomes, its expectancy, the spread of results and the depth of drawdown. The deliverable is a distribution and a confidence, not one number. Its value is destroyed if the rules are ambiguous, the costs are omitted, or the same data is used to both build and judge the rule.
How much data or how many trades is enough to backtest?
+There is no fixed threshold, only the honest fact that confidence scales with the number of independent trades, not calendar years. A result built on twenty trades tells you almost nothing, however good it looks. You want enough trades to span at least one full up-trend, one down-trend and one range, because a rule that only ever met a rising market has not been tested, it has been flattered. Report the trade count next to every metric, because it is what governs whether the metric means anything.
What is out-of-sample testing?
+You split the history into two parts. On the in-sample part you develop and tune the rules. The out-of-sample part is held back and never looked at during development, then the frozen rules are run on it once. If the edge survives on data the rule has never seen, it is more likely to be real and less likely to be a pattern you fitted to noise. If the result collapses out of sample, you overfitted. The discipline only holds if you do not peek and then quietly re-tune.
What is walk-forward analysis?
+Walk-forward is the rolling, honest version of an out-of-sample test. You optimise on a window of history, test on the next unseen block, then roll both windows forward and repeat across the whole timeline. It mimics how a strategy is actually run, re-fitted periodically on recent data and then traded blind into the near future. Because it produces many separate out-of-sample segments across different regimes, it exposes a rule that only worked in one market far better than a single split can.
Which backtest metrics matter most?
+No single number is enough, which is the point. CAGR alone hides how much pain earned the return, so read it beside maximum drawdown, its depth and its duration. Add exposure-adjusted return, so a rule in the market ten percent of the time is not compared unfairly with one always invested, and profit factor, gross profit over gross loss. The Sharpe intuition, return per unit of volatility, is useful as long as you do not worship it. Above all, read the trade count: it is the sample size that decides how much any of the others can be trusted.
Why does my live result differ from the backtest?
+Live almost always underperforms the test, and the gap has structural causes. Real fills carry slippage and market impact a backtest rarely models fully. Costs bite on every trade. The market regime drifts away from the one the rule was fitted to. And if an edge becomes widely known, crowding erodes it. Expecting live to match a clean backtest is the mistake; a sound process expects decay and sizes for it, rather than treating the backtest curve as a promise.
Do I need to code to backtest a strategy?
+Not necessarily, but you do need to be exact. The real requirement is that every rule is unambiguous enough to execute without human judgement: an entry, an exit, a stop and a position size that a machine could follow identically every time. Code makes that exactness natural and makes honest cost and lag modelling easy, which is why serious testing tends to be programmatic. A spreadsheet can validate a simple rule. A vague rule that needs you to eyeball a chart cannot be backtested at all, in any tool.
What costs must I include when backtesting in India?
+The full statutory stack plus friction. Securities Transaction Tax (0.1% each side on delivery, 0.025% on the intraday sell), exchange transaction charges (roughly 0.003% on NSE cash), the SEBI turnover fee (0.0001%), stamp duty on the buy (0.015% delivery, 0.003% intraday), 18% GST on brokerage and those charges, and depository charges on delivery sells. Then add slippage and market impact, the difference between the price your backtest assumed and the price you actually get. Omitting these is the single most common reason a paper edge does not exist in reality.
When is a backtest actually conclusive?
+Never fully; a backtest raises or lowers confidence, it does not prove anything. What moves confidence upward is a large trade count, an edge that survives untouched out-of-sample and walk-forward data, stability across up, down and sideways regimes, and honest costs that still leave something over. Even then the correct posture is provisional: you carry the rule to paper trading and a slow live ramp precisely because the test is evidence, not a guarantee. Certainty is not on the menu; degrees of justified confidence are.
Where the facts come from
Sources
- India survivorship evidence. Harjot Singh Ranse, "Survivorship Bias in Emerging Market Small-Cap Indices: Evidence from India's NIFTY Smallcap 250" (November 2025): survivor-only backtests overstated annualised return by 4.94 percentage points (about 23 percent relative) and Sharpe by roughly 9 percent, with about 82.5 percent of index entrants removed over nine years. This grounds the point-in-time-universe requirement. arxiv.org
- Indian statutory cost stack. NSE India, "SEBI Turnover Fees, STT and Other Levies," sets out the Securities Transaction Tax, exchange transaction charges and the SEBI turnover fee (0.0001%) that a backtest must model on every trade. nseindia.com
- Uniform stamp duty. The amended Indian Stamp Act, effective 1 July 2020, standardised stamp duty on securities nationally: 0.015 percent on delivery buys and 0.003 percent on intraday buys, charged on the buy side only, which is why the cost stack is asymmetric between the two legs.
- STT and GST mechanics. Current STT rates (0.1 percent each side on delivery, 0.025 percent on the intraday sell) and the 18 percent GST applied to brokerage and exchange or regulatory charges, not to trade value or STT, define how each cost line is computed in the worked example.