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
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.
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.
The term this section turns on: Half life
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.
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.
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.
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.
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.

Key takeaways
- 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.
Two terms to hold on to from 18.7
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