What Is Backtesting? How to Backtest an Options Strategy, Step by Step
Backtesting means running a trading strategy on past market data to see how it would have performed, before you put real money on it.
What is backtesting?
You write your rules once: what to trade, when to enter, when to exit and how much to risk. A backtest applies those rules to every trading day in a past period and records the profit or loss of each trade, exactly as the rules say.
Take a common options strategy: "Sell the Bank Nifty ATM straddle at 9:20, put a 25% stop loss on each leg, exit everything at 15:15." A backtest answers the questions every trader has about it:
- Over the last few years, did it make money?
- How often did it win, and how big were the wins and losses?
- What was the worst losing stretch, and how long did it take to recover?
- How did it behave on expiry days, gap days and in crashes?
A backtest does not predict the future. It shows how a fixed set of rules behaved across real past conditions, which is far better than guessing.
▶ How to backtest Bank Nifty and Nifty option strategies on StockMock · More on our YouTube channel
Why traders backtest
- Test ideas without paying for them. A strategy that looks good on paper can fail in ways you only see across hundreds of days.
- Know the worst case in advance. The maximum drawdown and the longest losing streak tell you how much pain to expect, so a bad week doesn't make you quit a good strategy.
- Compare versions. 9:20 or 9:30 entry? 25% or 40% stop loss? Change one input and run again.
- Size your positions. Knowing the drawdown and the margin tells you how many lots your capital can actually carry.
▶ Watch: Why backtesting is important (1 min)
What you need before you start
A backtest is only as clear as its rules. Before you open any tool, write down:
- Underlying: Nifty, Bank Nifty, Sensex, Crude Oil and so on.
- Entry: a time (for example 9:20) or a condition (for example a range breakout).
- Legs: buy or sell, call or put, which strike and which expiry.
- Exits: stop loss, target and a final exit time.
- Size and costs: number of lots, brokerage and slippage.
How to backtest an options strategy on StockMock
StockMock is where time-based options backtesting in India began, in 2020. A test that once took 2 to 3 days of spreadsheets runs in under 5 seconds, with no coding.
- Choose the underlying. Nifty, Bank Nifty, Fin Nifty, Midcap Nifty, Sensex or Bankex, or MCX: Crude Oil, Natural Gas, Gold, Silver and their minis.
- Set entry and exit times. Intraday (for example 9:20 to 15:15), or positional from one day to another. ▶ Positional backtesting with Extended Week
- Add the legs. Pick the strike by distance from ATM, by closest premium, or by delta, and choose weekly or monthly expiry. ▶ Closest premium explained
- Set the risk on each leg. Stop loss and target in points or percent, with trailing stop loss if you want it. Then add a total stop loss and target for the whole strategy. ▶ Stop loss and target demo ▶ Trailing stop loss 𝕏 Trailing SL, first posted Nov 2020
- Add advanced rules if your strategy needs them. These cover how real traders manage positions:
- Wait & Trade: enter only after the premium moves by a set amount. ▶ Watch 𝕏 Launch post
- Re-Entry: get back in after a stop loss, for V, M and W shaped days. ▶ Watch 𝕏 Launch post
- Re-Execute: start a fresh trade at new strikes after a stop loss or target. ▶ Watch 𝕏 Update post
- Range Breakout: enter when price breaks the opening range. ▶ Watch
- Profit Lock: lock and trail gains once the strategy is in profit. ▶ Watch
- Journey: chain follow-up legs that open when a leg hits its stop loss or target. ▶ Watch 𝕏 Launch post
- Pick the period and filters. Choose a date range and, if you like, specific weekdays or days to expiry (DTE). 𝕏 Why we added the DTE filter
- Add costs. Enter slippage and brokerage so the results match what you would actually keep.
- Run it. Results arrive in under 5 seconds. Change one input and run again to compare.
How to read the results
Don't stop at total profit. These numbers tell you whether you can actually live with the strategy. ▶ Watch: How to read StockMock backtest results
| Metric | What it tells you |
|---|---|
| Overall profit | Total profit or loss over the whole period, after the costs you entered. |
| Average monthly profit | What a typical month looked like, which is easier to compare with your capital. |
| Win % (days) | The share of days that ended in profit. A high win rate with big losses can still lose money. |
| Average profit on win days / loss on loss days | The size of a typical win against a typical loss. |
| Max drawdown (MDD) | The largest fall from a peak. This is the pain you must be ready for. |
| MDD recovery period | How long it took to climb back to the old peak. |
| Return to MDD ratio | Return earned for each rupee of drawdown. Higher is better and lets you compare strategies. |
| Expectancy | The average result per trade, weighing wins and losses. |
| Max winning / losing streak | The longest run of winning or losing days in a row. |
Common backtesting mistakes
- Overfitting. Tweaking inputs until the past looks perfect. If 9:21 works but 9:20 and 9:25 don't, the edge is probably luck.
- Testing too short a period. One calm year says little. Test across trending, sideways and crash periods: StockMock's Bank Nifty data goes back to 2017 and covers the March 2020 COVID crash.
- Ignoring costs. Brokerage and slippage turn many small-edge strategies from profit to loss. Always add them. StockMock builds slippage into its reports for exactly this reason:
For the greater good of trading community, Stockmock has taken an initiative to show Close To Real results in backtesting reports by considering below scenarios:
— Stockmock.in (Backtesting, Simulator & Builder) (@stockmock_in) 11 Feb 2022
- Inbuilt Slippages
- Check Hide NA Rows
- Removing Outliers
Head over to to know more. - Looking only at profit. A strategy you abandon in its worst drawdown makes you nothing. Check MDD and the losing streak first.
- Treating the past as a promise. Markets change: expiry days, lot sizes and volatility shift over time. Re-test regularly.
FAQs
Do I need to know coding to backtest?
No. On StockMock you set the strategy with simple inputs (underlying, times, legs, stop loss, target) and run it in one click.
How long does a backtest take?
Under 5 seconds on StockMock, even across several years of data.
How far back does StockMock's data go?
Backtests: Bank Nifty from 2017 and Nifty from 2019, with later start dates for newer indices. MCX: Crude Oil and Natural Gas from Jan 2023, Gold and Silver from Jan 2024. Simulator: from 1 Jan 2021 for Nifty and Bank Nifty.
Can I backtest several strategies together?
Yes. Basket backtesting runs many strategies as one portfolio and shows the combined profit, drawdown and margin. ▶ Watch how
Does a good backtest guarantee profits?
No. It shows how the rules behaved in the past. Use it to reject weak ideas and to know the worst case, then practise in the Simulator and start live with small size.
How much does backtesting cost?
You can try backtesting with free credits. Multi-year backtests in one click need a Backtesting plan: ₹449 for 1 week, ₹1,299 for 4 weeks (₹325 a week) or ₹2,999 for 12 weeks (₹250 a week). The longer plans save 28% and 44%. Prices are plus 18% GST.
Follow StockMock for new features, strategy ideas and trader podcasts.
Founder updates: Nitish Narang on X (@nitishnarang)