This guide is a step-by-step method for backtesting strategies on NSE data, from writing the rules to reading the results. It covers the details that decide whether a backtest can be trusted: realistic fills, every cost, contract changes, the right metrics and the tests that separate a real edge from luck. If you only need a definition, see backtest meaning.
A short history of backtesting
Testing a trading rule on past prices began with pencil and paper. Commodity traders in the 1950s and 1960s, such as Richard Donchian, worked out trend-following rules by hand from price charts and counted how they would have done.7 Computers made the count fast. By the 1980s, commodity trading advisers ran their rules on years of daily prices, and the first trading-system software for personal computers let individual traders do the same.
Speed brought a new problem: if you can test a thousand versions of a rule in an afternoon, one of them will look excellent by chance. In 1992 Robert Pardo described walk-forward analysis, in which rules are built on one period and tested on the next.6 In 2014 David Bailey, Jonathan Borwein, Marcos López de Prado and Qiji Jim Zhu showed how quickly testing many variations produces a strategy that looks good in the past and has no edge at all, and gave ways to measure that risk.12
In India, backtesting options strategies became common after weekly index options arrived, Bank Nifty in 2016 and Nifty in February 2019, and minute-level option prices became available to retail traders through brokers and data vendors. The Indian market also changed under the backtests: lot sizes were revised several times, weekly expiries were cut to one benchmark index per exchange from November 2024, expiry days moved, and STT rose from 1 April 2026.345 A backtest of an Indian options strategy now has to handle those changes, which is why Step 3 below spends so long on them.
Step 1: Start with a question
Every useful backtest answers a specific question. "Does option selling work?" is too vague to test. "Does selling the Nifty ATM straddle at 9:20 am, with a 25% stop loss on each leg and a 3:15 pm exit, make money after costs over the last three years?" can be tested.
A good question names:
- The instrument. Nifty weekly options, Bank Nifty futures, a basket of Nifty 50 stocks.
- The idea. Why should this work? Time decay, a tendency for breakouts to continue, mean reversion toward VWAP.
- The test period. Long enough to include calm and volatile markets.
- What success looks like. A net profit after costs, a maximum drawdown you could live with, a minimum number of trades.
Writing down why the strategy should work matters more than it seems. A strategy with a clear reason behind it is more likely to keep working than one found by trying combinations until something looks good.
Step 2: Write the rules before you see any results
Write the complete rule set first, then run the test. If you change the rules after seeing the results, you are fitting them to the past.
Every rule must be exact enough for a computer to follow:
| Component | Vague | Exact |
|---|---|---|
| Entry | When the market looks strong | When a 5-minute candle closes above the 9:15–9:30 high |
| Size | A few lots | 1 lot of 65 units |
| Stop loss | If it goes wrong | At the 9:15–9:30 low |
| Target | When it has moved enough | 1.5 times the opening range |
| Time exit | Before the close | 3:15 pm |
| Filters | Avoid bad days | Skip RBI policy and Budget days |
If a rule needs judgement, it cannot be tested reliably. Either make it exact or remove it.
Step 3: Get the right data
The data decides what a backtest can tell you.
Match the data to the strategy
Intraday strategies need intraday data, usually 1-minute candles or tick data. A strategy with a stop loss that can trigger within a candle needs data fine enough to know when it would have triggered. Positional strategies can use daily data, but only if entries and exits happen at prices you could actually have traded.
Options need data for each contract
Options strategies need prices for each strike and expiry, not just the index. To test a short straddle you need the price of the exact call and put you would have sold at 9:20 am on each day, and their prices every minute after that until you exit.
Account for contract changes
Indian derivatives have changed a great deal in recent years, and a backtest that spans those changes must handle them:
- Lot sizes. NSE has changed the Nifty lot size several times. The most recent change cut it from 75 to 65 units from the January 2026 series.3 Rupee results must use the lot size in force on each date.
- Weekly expiries. Since November 2024, NSE has offered weekly options only on Nifty 50, and BSE only on Sensex.4 A Bank Nifty weekly strategy cannot be tested beyond that date because the contracts no longer exist.
- Expiry days. Exchanges have moved expiry days more than once; NSE's moved to Tuesday from 1 September 2025. Use the actual expiry date of each contract.
- Margins and charges. SEBI's framework added extra margin on expiry day for short index options, and STT on futures and options rose again from 1 April 2026.5
Watch for survivorship bias and corporate actions
For stock strategies, use data that includes stocks that were later delisted or removed from an index. Testing only today's Nifty 50 members on ten years of data quietly removes the companies that failed, which flatters the results. Adjust prices for splits, bonuses and dividends so that a corporate action does not look like a crash or a rally.
Step 4: Model fills honestly
Most backtests that look too good get their fills wrong.
Trade at prices you could have traded
A signal that appears when a candle closes can only be traded after it closes. Suppose a 5-minute candle closes at ₹500.00 and triggers a buy of 80 shares. A naive backtest buys at ₹500.00. In reality, the next price available is the next candle's open, say ₹500.40. If the trade exits at ₹503.10:
- Naive backtest: 80 × ₹3.10 = ₹248 gross profit.
- Realistic backtest: 80 × ₹2.70 = ₹216 gross, minus ₹46 of charges, for ₹170 net.
The naive version overstates the result by about 46%. Over hundreds of trades, that gap decides whether a strategy makes money at all.
Decide what happens when a candle hits both the stop and the target
Suppose you are long with a stop at ₹98 and a target at ₹104, and the next candle has a high of ₹105 and a low of ₹97. Both levels were touched, but the candle does not tell you which came first. A backtest that assumes the target was hit first will be optimistic. The safe assumption is that the stop was hit first, or to use finer data to find out.
Account for depth and spreads
A backtest that fills a large order at the last traded price ignores the order book. If you buy 100 units and only 20 are offered at ₹100 with the next 80 at ₹101, your average price is ₹100.80. A single-price fill at ₹100 understates the cost by ₹80. Options, especially far out-of-the-money strikes, often have wide bid-ask spreads. Buy at the ask and sell at the bid in your backtest, or add a slippage allowance for every order.
Step 5: Include every cost
Costs are certain; profits are not. Include all of them:
- Brokerage on every order
- Securities transaction tax (STT)
- Exchange transaction charges and SEBI fees
- Stamp duty and GST
- Slippage between the expected price and the fill
- Platform and data subscriptions
Here is how they add up. A strategy makes ₹18,000 gross over 100 round trips in a year. Charges total ₹6,000 and slippage another ₹4,000, leaving ₹8,000. A ₹3,000 software subscription leaves ₹5,000. The strategy kept less than a third of its gross profit, and a little more slippage would have wiped it out.
Estimate charges with a brokerage calculator and an STT calculator, and allow for slippage on every order, more on far strikes and fast markets.
Step 6: Model capital and position size
Decide how much capital the strategy uses and how the position size is set.
- Start with fixed size. Test with one lot or a fixed number of shares first. Compounding makes results harder to read, because a lucky early run inflates every later trade.
- Check margin. Options and futures need margin, and margin rises on volatile days and on expiry day. A strategy that runs out of margin on its worst day cannot follow its own rules.
- Round to whole lots. Real positions come in lots. A sizing rule that asks for 2.7 lots must round down to two.
- Size by risk. Once the strategy works at fixed size, size each trade by the loss you can accept, using a position size calculator.
Step 7: Read the right metrics
Total profit is the least informative number in a backtest. Look at the full picture:
| Metric | What it tells you | What to watch for |
|---|---|---|
| Net profit after costs | Whether the strategy made money | Compare with the risk taken |
| Number of trades | How much evidence the result rests on | Fewer than 100 trades is thin |
| Win rate | How often trades made money | Meaningless on its own |
| Average win and average loss | The size of typical outcomes | Large average losses with a high win rate |
| Expectancy | Average profit per trade after costs | Must stay positive after realistic costs |
| Profit factor | Gross profits divided by gross losses | Close to 1 means little margin for error |
| Maximum drawdown | The largest fall from a peak | Could you live through it? |
| Time to recover | How long the worst drawdown lasted | Months underwater test patience |
| Longest losing streak | The worst run of consecutive losses | Plan your sizing around it |
| Sharpe and Sortino ratios | Return relative to volatility | Compare strategies on the same basis |
Expectancy
Expectancy combines win rate and the size of wins and losses. Suppose 40% of trades win an average of ₹300 and 60% lose an average of ₹150:
0.40 × ₹300 − 0.60 × ₹150 = ₹120 − ₹90 = ₹30 per trade.
That looks positive. But if costs average ₹35 per trade, expectancy is −₹5 and the strategy loses money over time. Always calculate expectancy after costs.
Drawdown and recovery
Drawdowns are harder to recover from than they look. A 30% fall needs a gain of about 43% to get back to the peak, because the recovery starts from a smaller base. Measure the largest drawdown and its recovery time on every test, and compare strategies on a risk-adjusted basis, such as the Sharpe ratio, rather than on total profit.
Step 8: Test whether the result is real
A good-looking backtest is a hypothesis, not proof. These tests check whether the edge is likely to survive.
Check parameter stability
Run the strategy with nearby settings. If a straddle works with a 9:20 entry and a 25% stop, it should also work reasonably well with a 9:30 entry or a 30% stop. If only one exact combination works and its neighbours fail, the result is probably luck.
Separate design data from test data
Split your history. Design and tune the strategy on one period, then test it once on a later period it has never seen. If the results collapse on the unseen period, the strategy was fitted to the past. Our guide to avoiding overfitting covers this in depth.2
Use walk-forward testing
Walk-forward testing repeats that split over time. Design on 2021 to 2023 and test on 2024, then design on 2022 to 2024 and test on 2025, and so on. The combined results of the test periods are a much fairer estimate of live performance than a single backtest. See walk-forward testing.6
Count how many versions you tried
The more variations you test, the more likely the best one is luck. Researchers have shown that with five years of daily data, trying more than about 45 independent strategy variations is almost guaranteed to produce one with an attractive in-sample Sharpe ratio even if none of them has any real edge. Keep a record of every version you test and be most suspicious of the best one.
Stress-test the order of trades
A Monte Carlo simulation reshuffles the order of your trades thousands of times to show the range of drawdowns the same trades could have produced. The historical order is only one of many possible paths. A strategy whose worst reshuffled drawdown is twice its historical one needs a smaller size than the backtest suggests.
Check different market conditions
Look at how the strategy did in specific periods: the March 2020 crash, steadily trending years, quiet range-bound months and sudden event days. A strategy that made all its money in one kind of market may stop working when conditions change.
Step 9: Forward test before going live
Once the backtest holds up, run the strategy on live prices without real money. A forward test shows how the strategy behaves in today's market, how its orders fill and whether anything in the logic breaks.
Compare the forward-test results with the backtest over the same kind of period. Large differences usually point to unrealistic fills or costs in the backtest, or to a rule that behaves differently on live prices.
Step 10: Go live small and keep checking
Start with the smallest size the strategy allows, with a daily loss limit that refuses new orders once the day's loss reaches it and an account stop that squares off everything. Track live results against the backtest and the forward tests. Expect live results to be somewhat worse; if they are much worse, stop and find out why before adding size.
A worked backtest, from question to decision
This is a hypothetical example of the method, not a result.
The question. Does an opening range breakout on Nifty futures, trading the break of the first 15 minutes, make money after costs on 5-minute candles?
The rules, written first. Mark the high and low from 9:15 to 9:30 am. Buy one lot of 65 when a 5-minute candle closes above the high; sell one lot when one closes below the low. One trade a day. Stop at the other side of the range. Target 1.5 times the range. Exit everything at 3:10 pm. Skip RBI policy and Budget days.
The data. Two years of 5-minute candles on the near-month future, rolled to the next month before expiry week.
The fills. Entry at the open of the candle after the signal. If a candle touches both the stop and the target, assume the stop. Slippage of one point on entry and one on exit.
The first result. About 480 trading days, 410 trades. 42% of trades win, the average win is 1.4 times the average loss, and the result is a small profit before costs. After charges of a little over ₹100 a round trip and two points of slippage, it falls to roughly break-even.
The checks. A 30-minute range instead of 15 gives a similar result; a target of 2 times the range gives a slightly better one; a target of 1 time gives a loss. The first year is positive and the second slightly negative. A filter that trades only when the range is narrower than average improves both years.
The decision. The filtered version has a reason behind it, holds across nearby settings and survives costs by a thin margin. That is enough to run it forward for two months at one lot, not enough to trade it at size. If the forward test is much worse than the backtest over the same weeks, the fills or the costs are wrong, and the next step is to find out which.
The point of the example is the order of the steps. Every number that decides the result, the range, the target, the costs, the slippage, was set before the first run, and every change after that was tested on both years, not just the one that looked better.
Backtesting options strategies
Options add a few challenges of their own:
- Define ATM at the entry time. The at-the-money strike at 9:20 am is the strike nearest to the index at 9:20 am, not at the open or the previous close.
- Track each leg separately. Per-leg stops, re-entries and adjustments must be modelled on each option's own price path.
- Model changes in IV. Option prices move with implied volatility as well as the index. Using real option prices rather than prices calculated from the index captures this automatically.
- Handle expiry correctly. Options settle at the final settlement price. A strategy that holds to expiry must use it, and one that exits before must use the price at the exit time.
- Watch margin through the day. Margin for short options can rise sharply during volatile sessions and on expiry day.
- Use enough expiries. A weekly strategy over three years gives around 150 expiries. A monthly strategy over the same period gives only 36, which is thin evidence.
Reading an equity curve
The equity curve, the running total of a backtest's results, says more than its final number.
- Smooth and steady. Gains spread across many months. More believable, though a curve that is too smooth for a strategy that takes risk can be a sign of overfitting.
- Steps. Long flat periods broken by a few large jumps. The result depends on rare events; check whether they can happen again.
- A strong start, then flat. Most of the gain came in the early part of the test. The strategy may have stopped working, or the early period was unusual.
- Deep, long dips. Large drawdowns that took months to recover. Even if the end result is positive, ask whether you would have kept trading through the dip.
Plot the curve with the drawdown underneath it, and mark the dates of major events, such as rule changes, expiry-day changes and market shocks. A curve that changes shape at a rule change is telling you something.
Common backtesting mistakes
- Look-ahead bias: using information that was not available at the time, such as the day's closing price to decide a morning entry.
- Ignoring costs and slippage, especially for strategies that trade often.
- Filling at the signal price instead of the next available price.
- Testing on too few trades and treating the result as reliable.
- Optimising until the curve is smooth, then trusting the smoothest version.
- Using today's index members for a stock strategy tested over many years.
- Ignoring contract changes such as lot sizes, expiry days and discontinued weekly options.
- Rolling futures at the wrong time, or splicing contract months without adjusting for the price gap between them, which creates jumps that never happened.
Tools for backtesting
You can backtest in a spreadsheet, in Python or on a platform.
- Spreadsheets work for simple daily strategies but struggle with intraday options data and multi-leg positions.
- Python gives full control, but you must source clean data, model fills and costs yourself and maintain the code.
- A backtesting platform handles data, fills and costs for you, so you can focus on the rules.
QuantPower's backtesting runs two kinds of test, both with charges and slippage included and every trade listed:
- Rule backtests run a condition on one instrument, such as a moving-average cross on Nifty futures, over up to 2,000 past candles from your connected broker, from 5-minute to daily.
- Option strategy backtests run a set of option legs day by day and minute by minute, with each leg's strike picked at the entry time, per-leg stops and targets, an overall stop and target in rupees, and a time exit. They hold back the last 30% of the days as unseen and say whether the result held up on them.
A backtest costs 2 tokens a run, and the first 10 each week are free. Quanty, the assistant in the app, can build a strategy from your words and backtest it for you to check.
Start with 500 free tokens
Connect your broker, build a strategy and test it on paper before a single live order goes out.
Frequently asked questions
How many years of data do I need for a backtest?
Enough to include different market conditions and at least 100 trades. For intraday options strategies, two to three years of weekly expiries is a reasonable minimum. For slower strategies, you may need much longer.
Is backtesting enough before trading live?
No. A backtest shows how rules would have performed in the past. Forward testing on live prices, then a small live start, are needed to check fills, costs and how the strategy behaves now.
Why are live results usually worse than backtests?
Because backtests often underestimate slippage and costs, use fills that were not really available and are tuned to past data. Markets also change after the test period.
What is a good win rate for a strategy?
There is no good win rate on its own. A strategy that wins 35% of the time can make money if its wins are large, and one that wins 90% can lose money if its losses are large. Look at expectancy after costs.
What is the difference between backtesting and forward testing?
Backtesting replays past data quickly over a long period. Forward testing runs in real time on live prices with no real money. Backtesting tests the idea; forward testing tests the execution.
Can I backtest options strategies without coding?
Yes. Platforms such as QuantPower let you build multi-leg options strategies with entries, stops and exits through menus, then backtest them over past expiries.
What is overfitting in backtesting?
Overfitting is tuning a strategy so closely to past data that it captures random noise rather than a real pattern. An overfitted strategy looks excellent in the backtest and fails on new data.
Where backtesting is going
Backtests are getting faster and easier to build, which makes them easier to misuse. AI assistants can now write a strategy from a sentence and test it in seconds, so the number of versions a trader tries has gone up sharply, and the problem Bailey and his co-authors described matters more each year.2 Better tools respond by building checks in: held-back unseen days, walk-forward runs and warnings when costs take most of the gross. India's rules are also changing what a backtest is for. Since 1 April 2026, an algo offered to a retail trader runs through a broker under exchange rules, with each strategy registered, so a clear, documented test of the rules is becoming part of putting an algo into use.8
Related guides
- Backtest performance metrics: each measure in a report
- Backtest tutorial: your first test in QuantPower
- Read backtest results
- Strategy performance: checking a strategy once it runs
References
- Bailey, D. H., Borwein, J. M., López de Prado, M. and Zhu, Q. J. (2014). Pseudo-Mathematics and Financial Charlatanism: The Effects of Backtest Overfitting on Out-of-Sample Performance. Notices of the American Mathematical Society, 61(5), 458–471
- Bailey, Borwein, López de Prado and Zhu: The Probability of Backtest Overfitting, Journal of Computational Finance (2016)
- NSE: Equity derivatives contract specifications (lot sizes and expiry days), checked 12 November 2026
- SEBI circular SEBI/HO/MRD/TPD-1/P/CIR/2024/132: Measures to strengthen the equity index derivatives framework, 1 October 2024 (sebi.gov.in)
- Union Budget 2026-27: securities transaction tax on futures and options raised from 1 April 2026 (indiabudget.gov.in)
- Pardo, R. (1992). Design, Testing and Optimization of Trading Systems. Wiley
- Covel, M. W. (2007). The Complete TurtleTrader. HarperCollins (on Richard Donchian's trend rules)
- SEBI, circular on safer participation of retail investors in algorithmic trading, 4 February 2025, in force for every broker from 1 April 2026 (sebi.gov.in)