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.

  1. Choose the underlying. Nifty, Bank Nifty, Fin Nifty, Midcap Nifty, Sensex or Bankex, or MCX: Crude Oil, Natural Gas, Gold, Silver and their minis.
  2. 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
  3. 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
  4. 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
  5. Add advanced rules if your strategy needs them. These cover how real traders manage positions:
  6. 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
  7. Add costs. Enter slippage and brokerage so the results match what you would actually keep.
  8. Run it. Results arrive in under 5 seconds. Change one input and run again to compare.
Trade more than one strategy? Basket backtesting, first introduced by StockMock in late 2020, runs several strategies together as one portfolio, so you see the combined equity curve, drawdown and margin. ▶ Watch: Basket backtesting, compare and combine strategies

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

MetricWhat it tells you
Overall profitTotal profit or loss over the whole period, after the costs you entered.
Average monthly profitWhat 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 daysThe 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 periodHow long it took to climb back to the old peak.
Return to MDD ratioReturn earned for each rupee of drawdown. Higher is better and lets you compare strategies.
ExpectancyThe average result per trade, weighing wins and losses.
Max winning / losing streakThe 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:
  • 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.

Have a strategy in mind? Test it on years of data in one click.

Try a free backtest See Backtest

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.