On 15 Sep 2026 the log spread between Bank Nifty and Nifty stood a little above one usual size from its average if I used every session in the file, and close to zero if I used only the last sixty. Same day, same spread, two answers, and neither was wrong. A z score is a distance measured in the spread's usual size, and the usual size depends on the window you choose. That is the first thing the cointegration toolkit teaches: every number in it is an estimate from a window, and each choice of window is a decision the data did not make for you. This lesson builds the Engle Granger test step by step, adds half life and z score, and runs it on 300 dated NSE closes with a part held out. Nothing here is live, and nothing is a view on a trade.
3By the end you can
- Run the two steps of the Engle Granger test and read the statistic against the strict cutoffs.
- Work out a half life from the spread's pull back and a z score from a window, and say why both depend on choices.
- Explain why many pairs, a fitted ratio and one window each make a pass less reliable.

The idea, plainly
Two steps
The pair trading intuition module explained why correlation does not make a pair. The Engle Granger method is the standard way to ask the better question. Step one regresses the log of one price on the log of the other over a formation window. The slope is the hedge ratio and the leftover is the spread. Step two tests that spread for a unit root. A unit root means the spread wanders and has no home. Rejecting it is evidence that the spread keeps returning to one.
Fit, test, measure, then judge on days not used
The model under the test
Step one is a plain least squares fit of log Bank Nifty on log Nifty. The slope is the covariance of the two over the variance of the second, and what is left each session is the spread.
y(t) = a + b x(t) + s(t)
b = cov(x, y) / var(x)
ds = k (m − s) dt + sigma dW
Half life = ln 2 / k
= −ln 2 / ln phi
Long run sd of s =
sd(e) / sqrt(1 − phi^2)
The lag choice moves the statistic a little and the verdict not at all
dy = c1 + a1 gap + noise
dx = c2 + a2 gap + noise
Read 7 more paragraphs, 473 words
Both prices wander, so the slope settles on its true value much faster than the usual one over the square root of the sample size. Stock showed this in 1987, and the property is called super consistency. It is good news for step one and bad news for step two. The ratio is pinned down early, so the real uncertainty sits in the test that follows, which has to tell a spread that returns slowly from one that never does.
The simplest rope is an Ornstein Uhlenbeck process: a spread pulled back toward a mean m at speed k and shaken by noise of size sigma.
Sample it once a session and it becomes the autoregression used for the half life, with phi equal to e raised to minus k. Two numbers follow from phi and from e, the daily noise.
The second line is why a z score means anything. For a true rope the long run size of the spread is fixed by the noise and by phi, and a z of two is a gap of two such sizes. If phi is one that size grows without limit, and no z score is worth reading.
The test itself is the regression in the fold below, written for the change in the spread: the change on its lagged level, a constant and one lagged change. The coefficient g on the level equals phi less one, and the test asks whether g is below zero by more than chance explains. Its t statistic does not follow the textbook t table when the null is a unit root. Dickey and Fuller simulated the right distribution in 1979, and the usual five percent cutoff for a series with a constant is about −2.86. A spread that is a residual from a fitted ratio is tamer than a random one, so the distribution moves left again. Phillips and Ouliaris worked out residual based tests in 1990, and the tables that followed give −3.34 for two series. The extra lagged change soaks up serial correlation in the daily changes.
Cointegration has a second half, and it is the half a trader cares about. Engle and Granger showed that if two prices are cointegrated, each must respond to the gap, so at least one of them moves back toward the other. Write each leg's change on the lagged gap:
With the gap defined as y less b x less a, a rope needs a1 below zero or a2 above zero, or both. If only a1 is nonzero, the Bank Nifty does the returning and the Nifty leads; if both are, they meet in the middle. Knowing which leg adjusts tells you where the profit would come from and which leg carries the risk. The two step test does not say. Johansen's method, next, does.
Reading the statistic
The test statistic is the t value of the spread's own lagged level in a Dickey Fuller regression, with one lagged change added. More negative is stronger evidence of a home. The usual Dickey Fuller table is the wrong ruler here. The regression in step one picked the slope that made the spread as calm as possible, so the spread looks tamer than a random one and the plain table rejects too easily. The Engle Granger values are stricter. For two series with a constant, the five percent value is about minus 3.34, and the one percent value is stricter again.
Half life and z score, in formulas
Fit the spread on its own previous value. The coefficient phi sits between zero and one when the spread pulls back.
s(t) = phi x s(t-1) + e
Half life =
minus ln 2 / ln phi
z = (s minus mean) / sd
A phi of 0.98 gives a half life of about 34 sessions: the gap closes half its distance in that time on average. The mean and sd in the z score come from a window, which is why the same day can read differently under different windows. If phi is at or above one the spread has no half life at all.
Which way round
A regression is not symmetric. Regress Nifty on Bank Nifty and you get one slope and one statistic. Swap them and both change, because ordinary least squares minimises errors in one variable only. In this sample the two directions gave different statistics and very different half lives, though both failed. If a pair passes in one direction and fails in the other, that is itself a warning. Say which leg is y.
Johansen: more than two series, and no favourite leg
Engle Granger has two limits. It needs a favourite leg, because the slope depends on which price is y, and it can find at most one rope. With three prices there can be two. Johansen's method of 1988 and 1991 drops both limits. It treats the prices as one vector, writes their changes as a vector autoregression with an error correction term, and asks how many independent ropes the data support.
The term this section turns on: Error correction
dY(t) = P Y(t−1) + G dY(t−1)
+ c + e
trace(r) = −T x sum of
ln(1 − L) over the L beyond r
Read 2 more paragraphs, 174 words
The matrix P has a rank r, and r is the number of ropes. Rank zero means none. For one rope, P splits into a column of adjustment speeds, the a's above, and a column of weights, the recipe for the spread. The trace test checks whether r is zero, then whether it is at most one, and so on, using the squared canonical correlations L between the changes and the lagged levels, largest first.
For two prices and a constant in the system, the five percent cutoffs from MacKinnon, Haug and Michelis are 15.49 for r equal to zero and 3.84 for r at most one. On the 300 sessions of the file the trace statistic for r equal to zero came to 7.7 with no lagged change in the system, 7.1 with one and 7.7 with two. All sit below 15.49, so the data give no rope, the same verdict as Engle Granger. The result also cannot change when the two indices swap places, which is the point of the method.
How long a sample, how long a half life
A half life is only useful next to the sample it came from. If the gap takes about as long as the whole file to close half its distance, the file holds almost no completed returns to learn from. A working rule is to want several half lives inside the sample, and ideally many separate stretches that left the mean and came back. Two years of daily closes is a few hundred sessions, so a half life of a month leaves room for only a handful of cycles. Short windows are noisy, long windows hide breaks. A relationship that held in one stretch can change when index weights change, when a regulation moves a sector, or when the two sets of stocks begin to be traded differently.
Many pairs, many chances
Statistical arbitrage means running a rule like this across many pairs or baskets, with small positions and a statistical edge in each. The danger is arithmetic. A test at the five percent level passes about one pair in twenty by luck alone. Screen twenty stocks and there are 190 pairs, so about nine or ten will pass with no home at all. A pair picked as the best of many and judged on the same days is the look ahead bias from the intuition module, only larger.

Worked example: the pair lab on its default settings
The pair lab regresses Bank Nifty on Nifty over every session from 1 Jul 2025 to 15 Sep 2026, fits the ratio on the first sixty percent, and holds it fixed on the rest. Here is the picture first, then the numbers.
Two indices that share stocks, and a gap that did not stay put
Every span of the spread stayed short of the Engle Granger cutoffs
Read 2 more paragraphs, 120 words
Step one on the formation window, the first sixty percent of sessions to 19 Mar 2026, gave a hedge ratio near 1.07. Step two gave a statistic well short of any cutoff. Held fixed over the remaining sessions, the spread did no better. Refitting the ratio on those sessions alone moved it by more than a quarter, a sign of how loosely the pair is tied.
The half life told the same story from another side. On the fitted span it ran past a hundred sessions, about two thirds of the span it was fitted on. On the held out span it fell to about twenty three, which looks tempting until you notice the spread itself had not returned.
What the held out spread did
The more useful picture is the z score of the frozen spread, month by month. For the first two months it sat close to zero. From June it spent most sessions beyond two usual sizes, and at the last close it was still there.
After the split the spread drifted away from its fitted mean and stayed away
Read one more paragraph, 93 words
A trader who entered at a z of two on 9 Jun 2026, the first session beyond it, would have seen a wider gap at three of the four later month ends. The held out test counted one stretch beyond two and no return through zero. Rolling windows of 60 sessions, stepped five sessions at a time, passed the five percent cutoff in two of 49 cases, about what chance alone gives. None of that is a verdict on every pair. It shows what the toolkit says when a pair has no rope.
Four more checks on the same sessions
I ran four checks that a careful reader would ask for. None needed new data.
- Lag choice. The chart above: no lag choice from zero to five changes the verdict.
- Johansen. A trace statistic of 7.1 with one lagged change, against 15.49. No rope.
- Rolling windows. I fitted the ratio afresh in 37 windows of 120 sessions, stepped five sessions at a time. None passed the five percent cutoff. The best statistic was −2.23 and the median −1.50.
- The ratio itself. It was 0.74 on the whole file, 1.07 on the first 180 sessions and 1.37 on the last 120. Across the 120 session windows it ran from 0.82 to 1.55, with a median of 1.24.
The same pair gave a hedge ratio anywhere from 0.74 to 1.55
Read one more paragraph, 72 words
The ratio is not just a statistical nuisance. Three Nifty lots were worth Rs 45,08,127 on 15 Sep 2026. A move of the ratio from 1.07 to 1.37, which is 28% of the earlier value, changes the hedge by Rs 13,68,917 of Bank Nifty on that one leg. Sized on the first window and held through the second, the position would have carried that much exposure the plan did not intend.
One day, four readings
Back to the opening. The same last close, measured four ways:
One close, four z scores: the window is a choice
None of the four is beyond two. The lesson is the spread between the readings, not any of them. A rule that fires at a z of two needs its window written down before the data is seen, and tested on days it did not shape.
Second example (model): a true rope the test would miss
Model, not market data. Suppose a spread really is a rope, with phi of 0.98 per session. That is a half life of 34.3 sessions. The daily noise is 0.4% of the leg value, so the long run size of the spread is 2.01%, about 5.0 times the noise. We watch it for 300 sessions, the length of our file. How likely is the Engle Granger test to say so?
se(phi) =
sqrt((1 − phi^2) / n)
t is about (phi − 1) / se
A true rope needs a half life under about nine sessions to pass at 300 sessions
Read 4 more paragraphs, 254 words
Least squares gives phi a standard error close to the square root of one less phi squared, over the number of sessions.
For these inputs the standard error is 0.0115 and the typical statistic is −1.74, against a cutoff of −3.34. On average the test misses a rope that is really there. The range for phi, two standard errors either side, runs from 0.9575 to 1.0025. The low end is a half life of 16 sessions. The high end is above one, which means no home at all. That is what 300 sessions say about a spread whose true half life is 34.3 sessions: somewhere between 16 and never.
Set the statistic equal to the cutoff and solve for phi. You get 0.928, a half life of 9.3 sessions. A rope faster than that passes in the typical sample. A rope slower than that does not, however real it is. The test has a speed it can see, and most of what a monthly pair trader would want sits below it.
This is the other side of the multiple testing warning. Test 190 pairs and about 9.5 pass by luck. Test one pair with a sensible reason to be tied and a long half life, and the test is likely to miss a rope that is real. Both errors are normal. The way out of both is the same: choose the pair for a reason outside the price history, fix the rule, and judge it on days it never saw.
Where this meets India
The closes used here are index closes, which no one can trade directly. A real pair would use two futures, each rolling every month, each with a lot that cannot be split, and each with its own costs. The ratio the regression asks for is a continuous number, and the exchange sells lots. The next module, pair trading with Indian stock futures, works through lots, roll, physical settlement and costs. More than two series need a different test, and a hedge ratio that moves through time needs a different estimator. Both belong to later, more advanced lessons.
- Which price you test. A real pair uses two futures, and a futures price is the spot price plus carry, so the spread built from futures has a jump at every monthly roll. Stitching contracts end to end puts a basis difference into the spread that has nothing to do with the rope. Test on the cash index or the stock, and treat the roll as a cost, not as a data point.
- Expiry day. NSE moved monthly contracts on the Nifty, Bank Nifty and other indices, and all stock derivatives, to the last Tuesday of the month, for contracts expiring on or after 1 Sep 2025 (NSE/FAOP/68747, 25 Jun 2025). Weekly Nifty contracts expire on Tuesdays.
- Settlement price. Until the new rule starts, an expiring contract settles by the closing price framework. SEBI's circular of 15 Oct 2026 (HO/47/11/11(3)2025-MRD-POD2/I/23843/2026, para 4.9 and para 6.1) moves index futures and options to the volume weighted average of the constituents over the last 30 minutes of continuous trading, and stock derivatives to the volume weighted average of the stock, from 7 Dec 2026. A pair held to expiry then settles on two averages and not on two closes.
- Cross margin. NSE Clearing lists offsets between index futures on eligible indices, and between index futures and their constituent stock futures. Its eligibility test for index pairs is a correlation of the index values and an overlap of constituents, not a cointegration test, and options are not considered. A pair that is cointegrated but fails the test gets no offset.
- Charges. STT on a futures sale rose to 0.05% from 1 Apr 2026, from 0.02% before (NSE/FATAX/73524, 31 Mar 2026). Every leg of every roll pays it on the sale, and a half life that forces rolls turns it into a running cost.
- The close changed inside the file. Until the switch, a stock's closing price was the volume weighted average of its last 30 minutes of continuous trading. For stocks with derivatives it has come from a closing auction since 3 Aug 2026 (SEBI circular of 16 Jan 2026, HO/47/11/11(3)2025-MRD-POD2/I/2765/2026, para 4.1 and para 6.1), and an index close is built from stock closes. The last 31 sessions of this file come after the switch. I did not test whether it moved either spread, and a careful study would check the join.

What the research says
Engle and Granger (1987) define the idea and prove the link to error correction. Series that need differencing once to become stationary are cointegrated if some combination of them is already stationary, and then the representation of the changes must contain the lagged gap. They also simulated critical values, which is why the strict table exists. Stock (1987) showed the slope converges at the faster rate. Phillips and Ouliaris (1990) derived the limit distributions of tests on the residuals of a fitted ratio, and MacKinnon's tables turned them into cutoffs. Johansen (1988, 1991) built the vector method that tests the number of ropes without choosing a leg.
Read one more paragraph, 132 words
None of this says a pair will pay. Gatev, Goetzmann and Rouwenhorst (2006) did not use a cointegration test at all. They matched stocks by the distance between normalised prices, and found profits for 1962 to 2002 that typically exceeded conservative cost estimates. Do and Faff (2010) found those profits declining over time, and in a later paper (2012) that after commissions, market impact and short selling fees about thirty basis points a month of risk adjusted return remained, among well matched pairs inside refined industry groups, and that both pairs trading and short term reversal were largely unprofitable after 2002. The test in this lesson tells you whether a spread looks like a rope. The evidence says the profit lies in the choice of pair and in the control of cost.
Stretch: when the toolkit is not enough
A ratio that keeps moving needs an estimator that moves with it: module E11 builds the filter. More than two series bring the Johansen machinery into trading, through baskets: module E10. Judging any of it honestly is a matter of walk forward design: module A29, and the arithmetic of many trials is in module E16.
Read the chart yourself
Open the pair lab linked below and change the split from sixty to eighty percent. Note the fitted statistic, the held out statistic and the hedge ratio each time. Ask whether any setting passes on both spans. Then swap which index is y and repeat. If you find a setting that passes, ask how many settings you tried. Every extra try is another chance for luck, and the fair answer to a pass found by searching is to test it on a later period that the search never touched.
Two terms to hold on to from 18.7
The common mistake
The claim: This pair passed the cointegration test, so the spread has to come back.
A pass means that on one sample the spread looked more like a rope than a wandering path, at an error rate of one in twenty at the five percent level. Across many pairs some pass by luck. Relationships also change, and a ratio fitted on one window moved by over a quarter on the next. Ask for four things before taking a result seriously: Engle Granger values and not the plain table, a half life short against the sample, a ratio frozen on one window and judged on a later one, and the number of pairs that were screened to find this one. Even then a pair can break.
- Using the plain table. A residual statistic of −3.0 passes the plain five percent cutoff of −2.86 and fails the Engle Granger cutoff of −3.34. The pair looks like a rope only because the ruler is too short.
- Refitting the ratio on the test window. It removes the one thing the test window was kept for. The ratio moved by 28% between our windows, which on three Nifty lots is Rs 13,68,917 of hedge.
- Reading a half life as a promise. A fitted half life of 34.3 sessions came with an honest range from 16 sessions to never. Plan the capital and the rolls for the slow end.
- Treating a miss as proof of no rope. At 300 sessions the test cannot see a half life above about 9.3 sessions. A fail on a slow pair means the evidence is thin, not that the tie is absent.
- Stitching futures into one series. The roll jump looks like a gap that closed. It is the basis changing month.
Where this section sits in module 18.7
What I'd keep from this
- Engle Granger regresses first, then tests the spread for a unit root.
- Use the strict Engle Granger values, not the plain table.
- Half life and z score both depend on the window you choose.
- Swapping which price is y changes the ratio and the statistic.
- Test many pairs and some pass by luck.

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