Backtesting

Lookahead bias and overfitting in trading backtests

Why backtests of NIFTY strategies look better than live results, how lookahead bias and overfitting creep in, and how a held-back check period exposes them.

By
Veloce team
Published
Reading time
10 min read
On this page
  1. What lookahead bias looks like
  2. Seven ways future information leaks into options backtests
  3. 1. Filling at the signal candle’s close
  4. 2. Filtering on values that are known only at the end of the day
  5. 3. Signal on the index, price on the option
  6. 4. The closing auction
  7. 5. Knowing the future shape of the market
  8. 6. Settling before expiry
  9. 7. Indicators that repaint
  10. How Veloce prevents the mechanical leaks
  11. What overfitting is
  12. How a held-back check period helps
  13. Reading a sweep: an illustration
  14. Practical rules against overfitting
  15. Walk-forward testing
  16. Try it in Veloce

A backtest suffers from lookahead bias when the strategy uses information it could not have had at the moment it decided, and from overfitting when its rules or settings were picked because they matched the noise in past data. Both make results look better than anything you could trade. You avoid lookahead bias mechanically: decide only on candles that have closed, fill at a later price, and never filter on values that are only known at the end of the day. You limit overfitting statistically: try few settings, prefer settings whose neighbours also work, and judge the winners on a held-back check period they were never tuned on.

This article covers both, with examples from intraday NIFTY options, and shows how Veloce’s engine and sweeps handle them.

What lookahead bias looks like

The classic example: a 5-minute moving average crosses at the close of the 10:15 candle, and the backtest buys at that close. In a live market the close of the 10:15 candle is known at 10:20, by which time the price has moved on. On a single trade the difference is a few points. Over hundreds of trades in the direction of momentum, it can turn a losing strategy into a winning one, because the backtest consistently buys at the price just before the move it is reacting to.

Lookahead bias is rarely this obvious in practice. It tends to hide in data handling, in filters, and in the market’s own rules.

Seven ways future information leaks into options backtests

1. Filling at the signal candle’s close

Covered above, and still the most common. The fix is a strict rule: a candle may only be acted on after its start plus its length, and the order fills at a price that comes afterwards. Veloce fills at the open of the contract’s next candle, plus slippage.

2. Filtering on values that are known only at the end of the day

“Sell a straddle only on days when NIFTY moves less than 1%” is a perfectly good description of days a straddle would have done well, and useless as a rule, because at 09:20 you do not know how far NIFTY will move by 15:30. The same applies to the day’s high, low, close and volume, India VIX at the close, and anything computed from a daily candle that has not finished. If a filter depends on today’s daily candle, it must use yesterday’s instead.

3. Signal on the index, price on the option

Most option strategies take their signal from NIFTY and trade an option. If the backtest reads the option’s price at the same timestamp as the index signal, it may be reading an option candle that has not closed yet. In Veloce, when a strategy targets a contract it was not already following, the engine prices that contract only from candles that closed at or before the decision time, and the order then fills at that contract’s next candle open. If the option does not trade for a few minutes, the fill waits.

4. The closing auction

NSE runs a closing auction session in the cash market, and from August 3, 2026 extended F&O trading to 15:40 to line up with it. In Veloce’s one-minute NIFTY data since that date, index candles go flat from about 15:15 and then jump to the official close in the last minute or two. A signal that reacts to that jump is reacting to an auction price that the options market keeps trading around. Veloce’s built-in option strategies ignore index candles that close after 15:15, so the auction never produces a signal; in your own spec, the signal_cutoff setting does the same.

5. Knowing the future shape of the market

Some leaks come from using today’s facts for yesterday’s trades:

  • Expiry days. NIFTY weekly options expired on Thursdays until August 28, 2025 and on Tuesdays from September 2, 2025 (NSE/FAOP/68747). A test that assumes Tuesday throughout holds 2024 positions for the wrong number of days.
  • Lot sizes. NIFTY went from 75 to 65 units per lot for weekly contracts expiring from January 6, 2026 (NSE/FAOP/70616). Rupee results scale with lot size, so mixing sizes mixes results.
  • Which strikes existed. Choosing strikes from today’s option chain, or from a list of strikes that later became liquid, is a quiet form of survivorship bias.

Veloce changes the expiry weekday on the date each exchange rule took effect and moves expiries to the previous trading day around holidays. It also sets each contract’s lot size from the exchange’s dated schedule, by expiry.

6. Settling before expiry

An option held to expiry settles at its intrinsic value against the index’s closing price on expiry day. A test that marks positions to that close in the morning, or exits “at expiry value” at 14:00, is using a price from the future. Veloce books settlement at the close of the derivatives session on expiry day, never earlier.

7. Indicators that repaint

Some charting tools compute a higher-timeframe indicator (say a 15-minute Supertrend on a 1-minute chart) from a candle that is still forming, and then redraw it once the candle closes. A strategy tested on the redrawn values has seen the future. In Veloce an indicator is updated once per closed candle of the strategy’s own candle size and never revised.

How Veloce prevents the mechanical leaks

Leak What the engine does
Acting on an unfinished candle A candle reaches the strategy only after its start plus its length
Filling at a seen price Every candle starting at a moment goes to the simulated broker first, which fills waiting orders at its open; the strategy sees closed candles after that
Pricing a new contract early A newly chosen contract is priced from its last candle that closed before the decision
Auction prices in signals Built-in option strategies ignore index candles closing after 15:15; specs can set the same signal_cutoff
Wrong expiry day Expiry weekday follows the rule in force on each date; holidays move expiry earlier
Early settlement Settlement happens at the close of the derivatives session on expiry day

These rules are part of the engine, not something each strategy has to remember. A strategy written for Veloce cannot reach the price it trades at, however it is written. The engine page describes the replay in more detail.

What overfitting is

Overfitting is a different problem. Every rule can be mechanically clean and the strategy can still be fit to noise, because you picked its settings by looking at the results.

Suppose you test a moving-average crossover with five fast lengths, five slow lengths and four stop-loss levels. That is 100 combinations. Even if none of them has any real edge, one of them will look best, and the best of 100 looks much better than a typical one.

How much better? A simple simulation makes the point. Take 100 strategies with no edge at all: each makes 60 trades, and each trade wins or loses ₹1,000 with equal odds. Pick the one with the highest net P&L. Across 2,000 repetitions of this experiment:

Measure Typical strategy Best of 100
Net P&L over 60 trades ₹0 ₹20,000 (median)
Win rate 50% 67% (median)
Times the best made ₹16,000 or more 93.5% of experiments

Every one of those strategies is a coin flip. On the next 20 trades, the “best” one’s median result was ₹0, exactly like the rest. Real sweeps are less extreme than this because neighbouring settings behave alike, but the direction of the effect is the same: the more you try, the more the winner’s backtest overstates its future.

Bailey, Borwein, López de Prado and Zhu formalised this as the probability of backtest overfitting: the chance that the configuration that ranked best in-sample ranks below the median out of sample. The more configurations tried relative to the data, the higher that probability. The same authors argue that a single hold-out period is a weak safeguard on its own, which is why the rules below about trying few settings and looking for plateaus matter as much as the check itself.

How a held-back check period helps

The simplest defence is to split your history in two:

Tuning period: try every combination Check period Mar 1 Sep 1 Oct 31 only the best few settings are rerun here
Tune on one stretch of history, then rerun only the top settings on a later stretch the tuning never saw.

The rules that make the check meaningful:

  1. The check period comes after the tuning period. Markets change over time. Checking on an earlier period tests whether the past resembled an older past, which is not the question.
  2. Only the best few settings go forward. If you rerun all 100 combinations on the check period and pick the best there, you have simply tuned on the check period.
  3. You look at it once. If the check fails and you adjust the rules and check again, the check period has become part of the tuning. Each look spends some of its value.
  4. It contains enough trades. A check period with eight trades cannot confirm or reject much.

Veloce’s sweep follows this design. You give it a tuning period, the settings to vary, and a “check until” date. It runs every combination on the tuning period, ranks them by net P&L, and reruns the top three (or however many you choose) from the day after the tuning period ends to the check date. For each run you see net P&L, maximum drawdown, trades, win rate, profit factor, charges and peak capital at risk, side by side for tuning and check. The sweeps page shows the inputs.

Reading a sweep: an illustration

Here is the shape of a sweep result for the built-in moving-average option buyer, varying the fast and slow lengths. The numbers below are made up to show how to read the table; they are not results from any real period.

Rank Fast / slow Tuning net Tuning trades Check net Check trades
1 5 / 13 ₹41,200 212 −₹6,900 71
2 9 / 21 ₹29,800 148 ₹8,400 52
3 7 / 21 ₹27,100 155 ₹7,200 55

What this table would tell you:

  • The top setting in tuning lost money in the check period. On its own that is a warning, not a verdict, but it is what overfitting looks like.
  • Ranks 2 and 3 are neighbours (fast 9 and 7 with slow 21) and both held up. A plateau of similar results is more believable than a single sharp peak.
  • The check-period profit is a fraction of the tuning profit, as it almost always is. Plan around the check figures, not the tuning ones.

Practical rules against overfitting

  • Start from a reason, not a search. Decide why a rule should work (time decay, a trend persisting, a range holding) before testing it. A sweep refines a reasoned idea; it should not generate one.
  • Keep the number of settings small. Each extra setting multiplies the combinations. Two settings with three values each is 9 runs; four settings with five values each is 625.
  • Prefer coarse steps. Testing stops at 25%, 50% and 100% of premium says more than testing every 5%.
  • Look for plateaus. If 9/21 works but 9/20 and 9/22 do not, 9/21 is noise.
  • Count trades per setting. Fewer than a few dozen trades per varied setting is thin.
  • Include changes in the market. For NIFTY options, a tuning period from before and after the September 2025 move to Tuesday expiry, or before and after the January 2026 lot size change, tells you whether the strategy depends on one regime.
  • Include costs from the start. A setting that wins only before charges is not a winner. Veloce charges every fill, so sweep results are net of brokerage, exchange fees, STT, stamp duty and GST.

Walk-forward testing

One check period is a single test. Walk-forward testing repeats it: tune on January to June and check on July to August, then tune on March to August and check on September to October, and so on. The combined check results are a fairer picture than any single split.

Veloce runs one tuning period and one check period per sweep. You can approximate walk-forward testing by running a sweep per window and comparing the check rows, keeping the varied settings the same each time.

Try it in Veloce

Veloce’s engine handles the mechanical side of lookahead bias for you, and its sweeps hold back a check period so you can see how the best settings did on data they never saw. Both run on one-minute data for NIFTY 50 weekly and BANK NIFTY monthly options, SENSEX weekly options, and MCX gold and gold mini futures.

Create a free Veloce account, pick one of the built-in strategies, and run a sweep with a check period. The step-by-step backtesting guide covers the rest of the method, and the moving average crossover guide applies it to a strategy that is especially easy to overfit.

Frequently asked questions

What is lookahead bias in a backtest?
It is any use of information that was not available at the moment of the decision, such as trading at the close of the candle that produced the signal or filtering trades by the day's final high and low. It makes results look better than anything you could have traded.
What is overfitting in trading?
Overfitting is choosing rules or settings because they matched the noise in past data rather than a repeatable effect. The more combinations you try, the better the best one looks by chance alone.
How does a held-back check period help?
You tune settings on one period and then run only the best few on a later period you never tuned on. If they hold up there, the result is less likely to be luck. If they collapse, the tuning mostly fit noise.
How long should the check period be?
Long enough to contain a meaningful number of trades and at least one change in market conditions. For a weekly options strategy that usually means several months, not a few weeks.
Is walk-forward testing better than one check period?
Walk-forward testing repeats the tune-then-check cycle over several windows, so it uses more of the history for checking. It is more work but harder to fool. You can approximate it in Veloce by running successive sweeps that each check the months after their tuning period.
Can a backtest ever be completely free of bias?
No. Choosing which strategy to test after watching the market is itself a bias. The aim is to remove the mechanical leaks, limit how many settings you try, and judge results on data the tuning never saw.

Sources

  1. Bailey, Borwein, Lopez de Prado and Zhu, The Probability of Backtest Overfitting (SSRN)papers.ssrn.com, accessed
  2. NSE circular NSE/FAOP/68747: revision in expiry day of index and stock derivatives (June 25, 2025)nsearchives.nseindia.com, accessed
  3. NSE circular NSE/FAOP/70616: revision in market lot of derivative contracts on indices (October 3, 2025)nsearchives.nseindia.com, accessed
esc
↑↓Move↵Open