On 15 Sep 2026 the twenty session realised volatility of the Nifty was 7.3% a year. Across the 300 sessions in the NSE file that ends that day, the same measure ran from 5.2% to 29.5%. A model fitted inside one of those regimes has learned that regime, and nothing in its score says so. Machine learning works well where data carries a lot of signal. Market data carries little, comes as one history and keeps changing, so most of the work sits in the method around the model. This module is about that method. It is education: it names no strategy, promises no result and makes no call on any contract.
3By the end you can
- Build a label and a validation split that respect overlap, with purging and an embargo.
- Work out the effective sample, the noise in a hit rate and the chance a lucky variant passes.
- Turn a model probability into a size with ruin in view, inside the Indian algo framework.

The idea, plainly
Why is market data hard for machine learning?
Four facts do the damage, and a good algorithm cannot remove any of them.
- Small signal. Daily returns are mostly noise, so a model can fit noise and look skilful.
- One history. The past cannot be re-run, so each idea is tested on the same data again and again.
- A moving process. Volatility, correlations, lot sizes, tax rates and settlement rules change.
- Overlapping labels. A label that looks ahead several days shares most of its days with its neighbours, so the sample is smaller than the row count.
The regime moves: twenty session volatility ran from 5.2% to 29.5%
A fit that is good inside one stretch can be poor in the next, and a single train and test split cannot tell the two cases apart. That is why the checks below are about how the data is cut, not about which model is used.
What does a careful pipeline look like?
Each stage can fail without any error message, and a later stage cannot repair an earlier one. The map is a method, not a result.
A model passes seven checks before its score is worth reading
- Data: each value as it was known on its date, not as later revised.
- Features: only what was known when the trade would have been placed.
- Labels: what a trade could earn after costs, not an arbitrary next day sign.
- Ledger: a count of every variant tried, kept even for the ones that failed.
How should a label be built?
A fixed horizon label asks whether the price is higher in a set number of days. A triple barrier label is closer to a trade. It sets a profit barrier, a loss barrier and a time barrier, each scaled to recent volatility, and records which was touched first. Barriers wide in quiet markets and narrow in noisy ones keep the label comparable across regimes.
Meta-labelling splits the job. A simple rule decides the side of a trade, and a second model decides whether to take it and how large. The second model sees fewer, more selective rows, which is where overfitting waits.
Why does overlap shrink the sample?
Label each day with the return of the next three. Today's label and the next day's label share two of their three days, so they are not independent rows. Counting them as independent overstates the evidence by about the horizon, and a fit on overlapping rows looks sharper than the data supports.
The maths: effective sample size
Uniqueness of a label =
average of 1 over the
number of labels sharing
each of its days
Effective N = sum of
uniqueness over all labels
With a horizon of h days and one label a day, each interior label shares its days with up to h minus one neighbours on each side, and its average uniqueness is close to one over h. The effective sample size is then about N over h. Sample weights equal to uniqueness give each stretch of time a fair say, and a weight can also scale with the size of the return, so large moves do not swamp the fit. The standard error of a hit rate p over N independent rows is the root of p times (1 minus p) over N, which at p of one half is one half over the root of N.
The term this section turns on: Effective sample size
What do purging and an embargo do?
Ordinary k fold validation shuffles rows into folds. With overlapping labels, a training row just before a test fold has a label window that reaches into it, so the model has seen part of its own answer. Purging deletes training rows whose label windows overlap the test period. An embargo also skips a short stretch after the test fold, because serial correlation lets information leak forward.
- Purge: drop training rows whose window crosses into the test fold.
- Embargo: drop a further slice, often a small share of the sample, after it.
- Walk forward testing, in module A29, never trains on the future by construction, but gives one path only.
The maths: combinatorial purged paths
Split the sample into N groups
Test k groups at a time
Splits = N choose k
Paths = splits times k over N
Each group appears in the test set in a share k over N of the splits, so the test results can be stitched into several full length paths instead of one. With six groups and two tested at a time that is 15 splits and 5 paths. A strategy then has a spread of results to read, not one number. Purging and an embargo apply to every split.
How many tries did it take?
Every variant tried on the same history is a draw from the same noise. The honest question is not whether a model scored well but how many were tried to find it. The bars show the chance that at least one of n useless variants clears two standard errors above a coin flip by luck, each with a 2.3% chance on its own.
Twenty tries on one history clear a lucky bar more than a third of the time
This is why the ledger matters. Module E16 turns the count of trials into a deflated Sharpe ratio. Until the count is known, a good score is a number without a denominator.
Which features leak?
- Revised data. A figure restated later was not available on its date.
- Look ahead in code. A rolling window centred on the day, or a scaler fitted on the whole sample, uses the future.
- Survivorship. An index list as it stands today leaves out the names that dropped out.
- Corporate actions. A split or a bonus looks like a crash. The realised correlation file used in this course leaves out any name with a one day move above a quarter in a window, for that reason.
- Rule changes. Lot sizes, STT and settlement methods differ by date, and a model fitted across them mixes two products.
The relationship between stocks moves too. The twenty session realised correlation among the fifty Nifty names, on a fixed weight set, ran from 0.04 to 0.60 between 24 Sep 2025 and 15 Sep 2026, and stood at 0.10 on the last day.
The link between the names moves: correlation ran from 0.04 to 0.60
Which features matter, and how would anyone know?
Importance scores from a fitted model mislead when features are correlated: the score of one is split or stolen by its neighbours. Two checks help. Shuffle one feature at a time in a purged test fold and see how much the score falls, which is permutation importance. And test whether the features carry information in a fresh period, not only in the one used to rank them.
- A feature that ranks high in training and low in a later period was fitting that period.
- A cluster of related features is better judged as one group than one by one.
- Fewer, simpler features are easier to audit and cheaper to retest.
How does a probability become a size?
A classifier outputs a probability, and a position size turns it into rupees. The Kelly fraction of an edge is the size that grows an account fastest if the edge is known exactly, and it is not known exactly. Sizes near or above it ruin accounts that have a real edge. The model below takes a rule that wins 52% of trades with equal wins and losses, so Kelly is 4% of the account.
Model, not market data
The same edge ruins few paths at a small size and most paths at twice Kelly
Read one more paragraph, 48 words
At 4% of the account per trade, the size equal to Kelly, 19% of paths still lose half. At 8%, twice Kelly, 57% do. A model that scores well is not a size. Fractions of Kelly, set from a fixed risk budget, sit in module A31.
What happens after it goes live?
A model keeps being tested after launch, because the world it was fitted on keeps moving. A written plan for that, fixed before the first order, is part of the method.
- Drift checks. Compare the live spread of features and of outcomes with the spread in training, on a schedule.
- Stop rules. A drawdown or a run of misses that pauses the program, set in advance and not by feel.
- Retraining. Each refit is a new variant. It goes in the ledger with its date and its data window.
What do the Indian rules add?
- A program that sends orders through a broker's API is an algo order under SEBI's framework, whatever the model inside it (module A27).
- Giving the model's signals or the algo to others is a different route, with its own registration and claims rules.
- Past performance may be shown only as verified figures by firms permitted to do so. A chart of a backtest is not that.
- SEBI's Aug 2026 study found 87.7% of individual F&O traders lost money in FY26. Costs and size decide many outcomes before any model does.

Worked example: a three day label on the sessions in the file
The NSE file behind the volatility chart has 300 Nifty closes. Take a label that looks three sessions ahead and one row a day, and read what the sample can support.
- Rows. 300 closes give one row a day, before the last three rows lose their label.
- Overlap. Neighbouring labels share two of three days, so the effective sample is about 300 over three: 100 independent rows.
- Noise. The standard error of a hit rate over 100 independent rows is one half over ten: 5.0%.
- A bar. Two standard errors above a coin flip is a hit rate of 60%, before any cost, to be seen as unusual on this sample.
- Purge and embargo. With a three session label, drop 2 rows before a test fold, and an embargo of one percent of the sample is 3 rows after it.
- Trials. If ten variants were tried, the chance that one clears the bar by luck is 21%. If twenty, it is 37%.
Read one more paragraph, 59 words
The same arithmetic shows the limit of the exercise. A hit rate in the high fifties on this sample is within the noise, and a model with a hundred features has far more freedom than a hundred rows can pin down. More history and a smaller set of ideas are the cures. Neither is a feature of the model.
The common mistake
The claim: The model scored 70% accuracy on the test set, so it has an edge.
A score says little until three things are known: how many variants were tried, whether the test rows overlapped the training rows, and what the trades earn after STT, charges and slippage. A hit rate does not give a payoff either, since a rule can win most trades and still lose money. Read a score as a hypothesis, test it on a later period it never touched, with costs charged, and quote the number of trials with it. The short answer is on the machine learning question page.
Two terms to hold on to from 19.14
Key takeaways
- Market data has little signal, one history and changing rules.
- Overlapping labels shrink a sample to about N over the horizon.
- Purge training rows that overlap the test fold, then embargo what follows.
- Count every variant tried: twenty tries clear a lucky bar often.
- A probability is not a size. Kelly is a limit, not a target.
- Test later data with costs charged, and quote the trial count.
Where this section sits in module 19.14
Before you trade. Derivatives trading carries a high risk of loss. SEBI's study "Profitability of Individual Traders in the Equity Derivatives Segment (FY25 to FY26)" (August 2026) found that 87.7% of individual traders in equity F&O made net losses in FY26, with aggregate net losses of Rs 91,685 crore. Read the SEBI study