How to Backtest a Stock Strategy in India: An End-to-End Walkthrough
Backtesting a stock strategy in India means testing explicit rules on historical data that was actually knowable at each date, with realistic costs, a fair benchmark, and honest reporting.
Backtesting a stock strategy in India means turning an investment idea into explicit rules, then replaying those rules across history using only the information that was genuinely available on each past date, with realistic trading costs and a fair benchmark. Done properly it is mostly a data discipline exercise. The simulation itself is the easy part.
Most backtests that look impressive fail for the same reason: the history they ran on was quietly better than the history that existed. This walkthrough sets out the steps in the order a careful desk actually does them.
Step 1: Write the strategy down as rules
Before touching data, state the strategy in language precise enough that two people would implement it identically. That means answering, at minimum:
- Universe. Which stocks are eligible? An index constituent list, a market-cap band, a liquidity floor, a sector restriction, or some combination.
- Signal. What condition makes a stock a candidate? Write the exact metric, the exact threshold, and the exact period it is measured over.
- Selection. If more names qualify than you can hold, how do you rank and cut? Top twenty by score, all names above a threshold, or something else.
- Weighting. Equal weight, market-cap weight, or something conviction based.
- Rebalancing. How often do you re-run the rules, and on what calendar date or trigger.
- Exit. Does a stock leave when it fails the entry rule, or when a separate exit condition fires?
If any of these is left vague, you will end up making the choice implicitly, usually in the direction that improves the result. That is the first door through which overfitting walks in.
Step 2: Build the universe as it was, not as it is
This is where Indian backtests most often break. If you take today’s index membership list and run it back ten years, you have selected companies that survived and qualified through to today. Names that were delisted, merged away, or fell out of the index are simply absent, and the ones that are present were chosen partly because of what happened afterward.
You need a historical membership record: which stocks were in the eligible set on each past rebalance date, including the ones that no longer exist. Handling this correctly is the subject of survivorship bias in backtests, and it is not optional. A universe built from today’s list can flatter results without any other error in the test.
The same applies to liquidity screens. A stock’s traded volume today tells you nothing about whether it was tradable in size five years ago. Liquidity filters have to be evaluated with the volume data of that period.
Step 3: Get the timing of the data right
Every input to the signal needs a knowledge date, not just a period date. A March quarter is not public in March. Results are filed weeks later, and until they are filed the market does not have them.
If the strategy uses fundamentals, you have to know when each figure became public, and you have to use the figure as originally reported rather than the restated version that appears in today’s database. Companies recast prior periods routinely after demergers, discontinued operations, and accounting standard changes, and those recast numbers were not knowable at the time. This is exactly why point-in-time data matters and why restatements break models.
Price data needs its own care. Historical prices must be adjusted for splits, bonuses, and other corporate actions, or a five-for-one split will register as an eighty percent crash. But the adjustment must be applied consistently, and the shares outstanding used in any per-share metric must sit on the same basis as the price.
The failure mode across all of this has one name: lookahead bias. It rarely announces itself. It shows up as a strategy that is slightly, inexplicably good.
Step 4: Decide when trades happen and at what price
A signal computed from a closing price cannot be executed at that same closing price. The realistic convention is that a signal generated using data through the close of one day is acted on at some price the following session, and even then the price you model will not be the price you get.
Be explicit about:
- Signal date versus trade date. State the lag and keep it constant.
- Execution price assumption. Next open, next close, or an average. Each has different properties, and none is free.
- Partial fills. If the position size is large relative to a stock’s typical traded value, assume you could not have bought all of it at once.
If a strategy only works when you can trade at the exact price that generated the signal, it does not work.
Step 5: Charge realistic costs
An Indian equity trade carries brokerage, securities transaction tax, exchange charges, stamp duty, SEBI turnover fees, and GST on the brokerage and charges. On top of the explicit costs there is the implicit one: the difference between the price you modelled and the price your order actually achieved.
The practical point is not the exact rate card, which changes and varies by broker. It is that costs scale with turnover. A rule that rebalances monthly pays them roughly twelve times as often as one that rebalances annually. High-turnover strategies that look excellent gross of costs frequently look ordinary net of them, and the gap widens the larger the money.
Model the costs explicitly as a percentage of each traded value rather than deducting a lump sum at the end. That way you can see how sensitive the result is to the cost assumption, which is often the single most informative sensitivity in the whole exercise.
Step 6: Choose the benchmark before you see the result
Pick the comparison in advance and pick it honestly. A large-cap strategy compared against a broad small-cap index, or a strategy compared against a price index while the strategy itself implicitly reinvests dividends, will produce a flattering gap that says nothing about the rules.
The baseline any strategy has to beat is simply holding the market and doing nothing, net of the costs of doing nothing. That bar is higher than it looks.
Step 7: Read the output in the right order
Resist the urge to look at the headline return first. A more useful order is: the worst drawdown, the shape of the equity curve, the turnover, the cost drag, the number of positions and trades, and only then the return. A strategy whose entire result comes from three positions in one year is a different object from one with a broad, repeated pattern, even if the summary numbers match.
Look at the return statistics as a family rather than picking one. Volatility, drawdown, and risk-adjusted measures each answer a different question, which is the point of the portfolio metrics hub.
Step 8: Hold data back, then hold it back again
A backtest run on all your data, tuned until it looks good, has told you only that you can fit a curve. The minimum honest discipline is to develop on one slice of history and evaluate on a slice you did not touch, which is the logic of in-sample versus out-of-sample testing. A stricter version re-estimates the rules repeatedly through time, which is walk-forward analysis.
Neither technique makes a strategy true. They just make it harder to fool yourself.
What a backtest does not tell you
This is the section most backtest write-ups omit, and it is the most important one.
A backtest is a description of one sample of the past under a set of assumptions you chose. It does not establish that the pattern is real rather than coincidental, and with enough variations tested on the same history some rule will look good by chance alone.
It cannot capture the market conditions it never saw. Liquidity, market structure, tax treatment, and index composition all change, and a period that contained no serious liquidity crunch cannot tell you how the rules behave in one.
It cannot model your own behaviour. A drawdown that occupies two centimetres on a chart occupies eighteen months in a life, and most strategies are abandoned by their owners rather than defeated by the market.
It cannot represent capacity. A pattern that shows up in small, thinly traded names may be entirely real and entirely unusable at size.
And it says nothing about why the pattern existed. A rule with an economic explanation and a rule with none can produce identical backtests, but they are not equally trustworthy going forward. For more on that gap, see why backtest results do not repeat.
Related reading
- Portfolio Metrics Explained: the hub for the return, risk, and trade statistics a backtest produces.
- Common Backtesting Mistakes: the recurring errors that make results look better than reality.
- Survivorship Bias in Backtests: why the index of today is not the index of the past.
- Why Point-in-Time Data Matters: using the numbers that were actually knowable on each date.
- What Is Lookahead Bias: the quiet way future information leaks into a test.
This article is educational. Altys Labs is not a registered research analyst or investment adviser, and nothing here is investment advice or a recommendation to buy, sell, or hold any security.
Frequently asked questions
How do you backtest a stock strategy in India?
You write the strategy as explicit rules, define the universe of stocks it could have chosen from on each past date, feed it only data that was public on that date, simulate the trades with realistic costs, and compare the result to a fair benchmark. The hardest part is not the simulation. It is assembling history that does not leak information from the future.
How much history do you need for a credible backtest?
Enough to include more than one market environment. A test that covers only a rising market tells you how the rules behave in a rising market and nothing else. Many desks want a period that spans at least one significant drawdown and one recovery, and they still treat the result as indicative rather than proof.
Does a good backtest mean the strategy will work?
No. A backtest describes how a rule would have behaved on one particular sample of the past. It cannot establish that the same behaviour will repeat. Its honest use is to rule out ideas that never worked and to reveal the risk and cost profile of ideas that did.