Fit the hedge ratio of Bank Nifty on Nifty over the previous sixty sessions and read it on the last day of February 2026. It is close to zero. Read the same fit on 31 Jul 2026 and it is above one and a half. Same indices, same method: from almost no hedge to more than one and a half for one. A fixed ratio is too stiff for that, and a rolling one is too jumpy. The Kalman filter is the third answer: let the ratio drift, and let each day's surprise decide how far. This lesson builds the filter in plain steps, shows what it does to the Nifty and Bank Nifty ratio on a year of dated closes, and asks whether a moving ratio finds a spread worth trading or only makes an old spread look calm. Dated NSE data, nothing live, nothing a view.

3By the end you can

  1. Build the predict, forecast, compare and update loop of a Kalman hedge ratio and read its one dial, q.
  2. Explain why a more mobile ratio makes the leftover spread look more mean reverting without proving it is.
  3. Judge a filtered spread by a fixed rule on later days, with lots and costs in the picture.
The RupeeCase terminal on sample data: Growth per year: how fast did the model grow?
Watch in the terminal: how fast did the model grow? A short tutorial on sample data.

The idea, plainly

The problem a fixed ratio hides

The cointegration toolkit fitted one ratio on a formation window and froze it. If the relationship between the two prices moves, the frozen ratio goes stale and the spread drifts for a reason that is not mean reversion. The usual patch is to refit on a rolling window. That swaps one choice for two: the window length, and the fact that every day's refit is a fresh draw from a short sample. The ratio then jumps about, and a pair that needs a stable hedge gets an unstable one.

The filter in plain words

The Kalman filter treats the ratio as a hidden number that follows a random walk: the next day's ratio is the last one plus a small unknown step. Each day it does the same four things.

  • Predict. The ratio is what it was, and the doubt about it grows a little.
  • Forecast. Use the predicted ratio to say where the Bank Nifty should close given the Nifty.
  • Compare. The gap between the forecast and the actual close is the innovation, the day's surprise.
  • Update. Move the ratio by a share of the surprise. That share is the gain: large when the doubt about the ratio is large next to the noise in the data, small otherwise.

Predict, forecast, compare, update: the ratio moves by a share of each surprise

The Kalman filter as a daily loop: predict the hedge ratio, forecast the spread, observe the close and compute the innovation, update the ratio by the gain times the innovation, then repeat the next dayDiagram with 4 boxes. Predict the ratio to Forecast the close; Forecast the close to Innovation; Innovation to Update by the gain.Predict the ratiodoubt growsForecast the closeratio times NiftyInnovationactual less forecastUpdate by the gainratio moves a share
One day of the filter. The gain is set by two noise levels: how much the ratio is allowed to wander, and how noisy the closes are. Their ratio, called q here, is the only dial. An illustration of the method, with no prices. Source: RupeeCase illustration of the method. As of 17 Oct 2026.
The maths: the recursion

Let y be the log of Bank Nifty and x the log of Nifty. The state b holds the slope and the intercept, h is the row of x and one.

b(t) = b(t-1) + w
y(t) = h(t) b(t) + v
P = P + Vw
e(t) = y(t)-h b
Q = h P h' + Ve
K = P h' / Q
b = b + K e(t)
P = P-K h P

The noise in w is Vw and in v is Ve. I set Vw to q times Ve, so one number, q, decides how freely the ratio moves. A very small q gives a filter that behaves like a regression over everything seen so far. A large q gives one that chases yesterday's close. The standardised innovation is e divided by the square root of Q, and if the model were right it would have unit variance and no pattern.

Two things the filter does not do

It does not create mean reversion. The innovation is the part of today's close that the ratio did not predict, and the filter updates the ratio from it. Raise q and the ratio absorbs more of every deviation, so the leftover looks calmer and less persistent. That looks like reversion and is partly a property of the method.

Read 2 more paragraphs, 134 words

It does not choose q either. The dial sets how stiff the ratio is, and no part of the data says what the right stiffness is. If I pick q to make the spread look best on the same days I will trade, I have fitted the dial to the answer.

And it does not know a break from noise. If the link between the two indices changes for good, because index weights moved or a rule changed, the filter adapts a few days later and the old spread vanishes without a mark. A frozen ratio would have shown the break as a spread that never returns. That makes the filter a smoother, not a detector, and a trader who wants to know that a relationship has gone has to look at something else.

q is a window length in disguise

A rolling regression forgets everything older than its window all at once. The filter forgets gradually: each new day counts a little more than the one before it. A larger q means a shorter memory, a smaller q a longer one. So the dial does the job that the window length does in a rolling fit, with smoother edges. That is useful, and it is also why q needs the same discipline: pick it on one stretch of data and test on another, and never on the days that will judge the rule.

Appendix: one update by hand

Take a ratio of one, a doubt about it of one hundredth, noise in the close of four hundredths, and a regressor of one. The doubt over the doubt plus the noise gives a gain of one fifth. If the close comes in a quarter above the forecast, the innovation is a quarter, the ratio moves up by a twentieth to one and five hundredths, and the doubt falls from one hundredth to eight thousandths. The next morning the filter adds a little doubt back, since the ratio is allowed to wander, and the cycle repeats. The quiz works the same numbers.

Worked example: Bank Nifty on Nifty, a year of closes

The RupeeCase terminal on sample data: Portfolio value: what does "Same money in NIFTY 50" mean?
Watch in the terminal: what does "Same money in NIFTY 50" mean? A short tutorial on sample data.

Which number is the hedge ratio

The file holds three hundred daily closes of both indices from 1 Jul 2025 to 15 Sep 2026. The chart lines up the estimates a trader could have held. The filter starts from a fit to the first sixty sessions, and I judge everything from 25 Sep 2025 on.

Four ways to fit the ratio, four different answers

Hedge ratio estimates of Bank Nifty on Nifty from 25 Sep 2025 to 15 Sep 2026: 0.74 on the whole file, 1.01 on the first 60 sessions, a rolling 60 session fit between 0.07 and 1.67, and a Kalman filter in the middle of the dial between 0.94 and 1.16Whole file regression 0.74; First 60 sessions 1.01; Rolling 60, lowest 0.07; Rolling 60, highest 1.67; Kalman, lowest 0.94; Kalman, highest 1.16.Hedge ratio of log Bank Nifty on log NiftyWhole fileregression0.74First 60 sessions1.01Rolling 60,lowest0.07Rolling 60,highest1.67Kalman, lowest0.94Kalman, highest1.16
The rolling fit is refitted every session on the last sixty. The Kalman filter uses a middle setting of its dial, q equal to a hundredth. The ratio is in log terms, which is close to a ratio of values. Same closes, same dates. Source: NSE end of day data, computed by RupeeCase. As of 15 Sep 2026.
Read one more paragraph, 79 words

The whole file gives about three quarters, the first sixty sessions about one, and a rolling fit anything from nothing to almost two. The filter stayed in a narrow band around one, and moved slowly inside it. Its ratio was above one from 12 Mar 2026 and drifted down after late Jul. That is the case for the filter: it shows the relationship moving without the jumps. It is not yet a case that the movement is worth following.

One dial, two readings

Now turn the dial. At the smallest settings the filter behaves like a regression over everything it has seen, and its innovations are strongly persistent: the spread wanders. At the largest the ratio chases every close, and the leftover forgets most of yesterday.

The more the ratio moves, the less the leftover remembers

Lag one autocorrelation of the Kalman innovations of Bank Nifty on Nifty for six settings of q from 25 Sep 2025 to 15 Sep 2026: 0.96, 0.96, 0.94, 0.91, 0.74 and 0.36, falling as the ratio is allowed to move moreq 0.00001 0.96; q 0.0001 0.95; q 0.001 0.94; q 0.01 0.91; q 0.1 0.74; q 1 0.36.Lag one autocorrelation: near 1 wanders, near 0 is noiseq 0.000010.96q 0.00010.96q 0.0010.94q 0.010.91q 0.10.74q 10.36
The lower the bar, the faster the leftover from the filter forgets yesterday. A tall bar is a spread that wanders. A low bar can mean a spread that reverts, or a ratio that has simply absorbed it. Source: NSE end of day data, computed by RupeeCase. As of 15 Sep 2026.
Read one more paragraph, 47 words

This is the trap in one picture. Across the six settings the leftover goes from a spread that barely forgets to one that forgets most of yesterday. Nothing about the Nifty and Bank Nifty changed. Only the dial did. A lower bar is not a better spread.

The test that decides

So I ran the trade as a test on past data. Each day the rule was long the leftover when it stood low against its recent size and short when it stood high, up to a fixed limit, hedged with that day's ratio, and it collected the next day's change in the spread. The same rule ran for each setting, and for the frozen and rolling fits for comparison.

No setting of the dial made money, and the fixed ratios did no better

Mean daily return in basis points of a spread reversion rule on Bank Nifty and Nifty from 25 Sep 2025 to 15 Sep 2026 before costs: between minus 1.36 and minus 4.84 for six settings of q, minus 3.10 with a frozen ratio and minus 1.91 with a rolling ratioq 0.00001 −2.50; q 0.0001 −2.16; q 0.001 −2.26; q 0.01 −4.84; q 0.1 −4.02; q 1 −1.36; Frozen first 60 −3.10; Rolling 60 −1.91.Mean daily return, basis points, before any costq 0.00001-2.50q 0.0001-2.16q 0.001-2.26q 0.01-4.84q 0.1-4.02q 1-1.36Frozen first 60-3.10Rolling 60-1.91
Index closes, a limit on the position, the hedge ratio of the day, and the next day's change in the spread. About two hundred and forty sessions. Every t statistic is between about minus one and a half and zero, so none of the means can be told from noise. Source: NSE end of day data, computed by RupeeCase. As of 15 Sep 2026.
Read one more paragraph, 97 words

Every bar is below zero before costs, and none is far enough from zero to mean anything: the t statistics run from about minus one and a half to zero, for a daily noise of about fifty to seventy basis points on the filtered rules. The frozen and rolling ratios did about as well. The filter did not find a trade in this pair. It found a way to describe the pair more smoothly. I would take that as the honest output of the method here, and I would not tune q until a bar turned positive.

What a changing ratio means in lots

The filter's ratio moved by less than a fifth in any month, and a trader can only hold whole lots. On 10 Jun 2026 one lot of the near Nifty future was worth Rs 15,10,607 and one lot of Bank Nifty Rs 16,56,012, so the lots are close in value. SEBI's circular of 1 Oct 2024 asks for lot sizes that keep the value on the day of review between 15 and 20 lakh rupees, and both lots sit inside that band. A move in the ratio from the lowest to the highest value of the filter's band changes the Bank Nifty needed against a hundred Nifty lots by about twenty lots. Against one lot the same move is a fifth of a lot, which cannot be traded. At small size the ratio is a number on a chart, not a position. Each rebalance also pays the statutory charges, with STT of 0.05% on the sale of a future.

Appendix: why I centre the Nifty series

The log of Nifty sits near ten and barely moves, so the slope and the intercept of the regression are almost interchangeable. The filter then gives a wrong share of each surprise to each of them, and the ratio swings for no reason. Subtracting the average of the first sixty sessions from the log of Nifty makes the intercept the level of Bank Nifty at the average Nifty, and the slope the ratio alone. The forecasts do not change, but the ratio becomes readable.

Where this meets India

The legs are index futures, which expire monthly, settle in cash and need a roll by the last day. Each lot is a fixed number of units, set by NSE and revised from time to time, and an index future moves in ticks that depend on the level of the index. A filter that wants a ratio change of a few hundredths to a sixth in a month has to be sized so that the change is a whole lot, and at that size the costs of changing it count. The same filter on two stock futures adds delivery on the last day, the ban list and the lot mismatch of the stock futures pair lesson. A smooth hedge ratio does not remove any of that.

Two terms to hold on to from 18.14

Two terms to hold on to from 18.14Two terms to hold on to from 18.14. Kalman filter: A recursion that tracks a hidden quantity, here the hedge ratio, by predicting it and then correcting it with each new observation. Innovation: The actual value less the value forecast from the prediction: the day's surprise. The filter updates the state from it.Kalman filterA recursion that tracks a hidden quantity,here the hedge ratio, by predicting it andthen correcting it with each new observation.InnovationThe actual value less the value forecast fromthe prediction: the day's surprise. The filterupdates the state from it.
From the module glossary. Source: Module 18.14, Kalman filter hedge ratios.

The common mistake

The claim: A Kalman filter adapts the hedge ratio, so the pair never breaks down. The filter follows a ratio that moves. It does not make a spread revert, and it can absorb a break so quietly that nothing looks wrong. In this file the setting of the dial changed how calm the leftover looked, from persistent to short lived, while the result of trading it stayed below zero in every case. Before trusting a filtered spread, ask how q was chosen, on which days, what the same rule earns with a fixed ratio, and whether the hedge moves by whole lots.

Key takeaways

  • The filter lets the hedge ratio drift and updates it from each surprise.
  • One dial, q, sets how freely the ratio moves.
  • A freer ratio makes the leftover look more mean reverting, partly by construction.
  • No setting of the dial made the Bank Nifty and Nifty rule positive here.
  • A ratio that moves by fractions of a lot cannot be followed at small size.

The term this section turns on: q

The term this section turns on: qThe term this section turns on: q. q: The ratio of the noise allowed in the hedge ratio's step to the noise in the data. It is the filter's one dial and is not estimated by the filter.qThe ratio of the noise allowed in the hedgeratio's step to the noise in the data. It isthe filter's one dial and is not...
From the module glossary; every term is in the Learn glossary too. Source: Module 18.14, Kalman filter hedge ratios.

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