Take the 47 Nifty 50 stocks with clean price histories from 10 Sep 2025 to 15 Sep 2026. Every group of three is a possible basket, 16,215 of them. I split the year in two and ran a five percent cointegration test on every basket in the first half. About one basket in nineteen passed, almost exactly what luck alone would give. Then I ran the same test on the second half. The baskets that had passed did not pass more often than the rest, they passed slightly less often. Then I ran the published principal component method of Avellaneda and Lee on 44 of the same stocks for 179 sessions from 24 Dec 2025 to 15 Sep 2026, at eight settings, and none of them could be told from zero. This lesson moves from pairs to baskets and factors: what principal components separate, why a filter that looks like a test of mean reversion passes pure noise, what the Johansen test asks, and what a screen of thousands tells you about itself. Dated NSE data, nothing live, nothing a view.
3By the end you can
- Build eigenportfolios from a correlation matrix, read eigenvalues against the noise edge, and compute an s score step by step.
- Say why a reversion speed filter on cumulative residuals cannot tell reversion from noise, and what test replaces it.
- Cost a residual rule in whole lots, short selling rules, position limits and charges for Indian stock futures.

The idea, plainly
Why more than two names
The cointegration toolkit tested one pair. A pair depends on a single partner, and if that partner has news, the pair breaks. A basket spreads the dependence. The idea of statistical arbitrage on baskets is to take the move that all stocks share out of each stock, and then look at what is left. The leftover is a stock's own part: its news, its flows, its noise. If some of the leftover tends to drift back, a rule can try to harvest it. Whether it drifts back is the question, and this lesson tests it on dated data.
Principal components: the shared moves
Take daily returns of the stocks, standardise each, and form the correlation matrix. Its eigenvectors are the shared moves, called factors, and its eigenvalues say how much of the total variance each one carries. The first is nearly always the market: every stock loads on it with the same sign. On 250 sessions to 15 Sep 2026 it carried 30.3% of the variance of the 47 stocks, and the portfolio it describes had a correlation of 0.97 with the Nifty 50. The next ones are blocks of stocks that move together beyond the market, such as a sector. The average pair correlation in the file was 0.26.
Qi(j) = vi(j) / si
Fj = Σi Qi(j) Ri
The maths: factors and the noise edge
Let Z hold standardised returns, T rows by N columns.
R = Z'Z / T
R v_k = lambda_k v_k
F_k = Z v_k
edge = (1 + sqrt(N/T))^2
The eigenvalues of R sum to N, so lambda_k / N is the share of variance of factor k. The edge is the largest eigenvalue pure noise would give as T grows, and the smallest is (1 minus the same root) squared. For 47 stocks and 250 sessions the ratio N over T is 0.188, and the edge 2.06. It is an asymptotic result, so with a few hundred sessions it is a guide, not a line. Laloux, Cizeau, Bouchaud and Potters (1999) and Plerou and co-authors (2002) brought this random matrix test to financial correlation matrices, and Bai and Ng (2002) built information criteria for the number of factors.
Strip out the shared moves, then ask whether the leftover reverts
Read 3 more paragraphs, 177 words
Avellaneda and Lee turn each eigenvector into a tradable portfolio. The amount invested in stock i for factor j is the eigenvector entry divided by the stock's own volatility, and the factor's return is the sum of those amounts times the stock returns.
Dividing by volatility turns the correlation eigenvector into rupee weights: a volatile stock gets a smaller holding for the same loading. The factor returns are uncorrelated by construction. The first eigenportfolio held all 47 stocks long, with an effective number of names of 41.5. The second was a long short portfolio with 27 names long, and one name held 10.6% of its gross weight. That is not diversified, and it matters later when the weights must be turned into lots.
The hard part is how many factors to keep. A random matrix of the same size also produces eigenvalues, and the largest of them is not zero. For N stocks and T sessions the edge of the noise is known in closed form. Only eigenvalues above it are likely to be real structure.
The residual and its speed: the Avellaneda and Lee recipe
With the factors in hand, regress each stock's last sixty returns on them. What the regression leaves unexplained is the stock's residual return. Add the residuals day by day and you get a path X. The paper models that path as an Ornstein Uhlenbeck process, which in daily steps is an autoregression of order one.
X(t+1) = a + b X(t) + z
kappa = −ln(b) / dt
m = a / (1 − b)
s_eq = sqrt( var(z) / (1 − b^2) )
s = (X − m) / s_eq
Read 2 more paragraphs, 236 words
A b below one means the path reverts. The speed kappa converts it to a yearly rate, with dt one session as a share of a year, one over 252, the equilibrium mean is m and its usual size is s_eq. The score s is the distance from m in units of s_eq. The paper keeps a stock only if kappa is above 8.4, a reversion time of under half the sixty day window, and uses entry and exit thresholds on s: open a long at s below minus 1.25, open a short at s above 1.25, close a short when s falls below 0.75, close a long when s rises above minus 0.50. The windows are 252 days for the correlation matrix and 60 days for the regression and the autoregression, with one dollar long in the stock and the matching amounts short in the factors. The authors assumed a cost of five basis points a trade, ten round trip.
Their abstract reports what the strategy earned in US stocks: after costs, an average annual Sharpe ratio of 1.44 over 1997 to 2007, much stronger before 2003, and 0.9 over 2003 to 2007. A strategy built on sector funds instead of statistical factors saw a similar fall after 2002. They also tie the summer of 2007 to the unwinding of long short equity funds described by Khandani and Lo.
The bridge problem: a filter that passes noise
One detail of the recipe is easy to miss. The path X is the running sum of regression residuals, and a regression with a constant makes its residuals add to zero over the window. So X starts at zero and ends at zero. A random walk forced to end where it began is a bridge, and an autoregression fitted to a bridge finds a coefficient below one even when there is no reversion at all. The kappa filter then passes almost everything.
The filter passed 98.5% of pure noise and 97.7% of the Nifty names
Read 2 more paragraphs, 121 words
I tested that on pure noise: sixty independent random residuals, summed into a bridge, fitted by the same autoregression, twenty thousand times with a fixed seed. Model, not market data.
The median kappa of pure noise was 31.2, a half life of 5.6 sessions. On 15 Sep 2026 the median kappa of the real residuals was 44.2, a half life of 4.0 sessions. The real residuals look as fast as noise. That is not a finding that they do not revert, only that the filter cannot tell them apart from noise, so it cannot be the evidence of reversion. The test has to be forward: sign the position on the s score, hold it, and measure the next days.
Johansen: a test made for baskets
The Engle Granger test of the toolkit lesson regresses one price on the others and tests the leftover. For three names it gives a different answer depending on which one you put on the left. The Johansen test treats all the prices alike. It asks how many independent combinations of them are stationary. That number is the rank r. If r is zero the prices have no home. If it is one there is one combination that keeps returning, with weights the test also gives you.
The maths: rank and the trace statistic
dY_t = Pi Y(t-1) + c + e_t
Pi = alpha beta'
trace = -T sum ln(1-lam_i)
sum over i above r
Pi is the matrix that pulls the prices back. Its rank is r. The lambda_i come from a matrix built from the regression residuals, and the trace statistic for r equal to zero uses all of them. The statistic is compared with cutoffs. The published tables assume a long sample, so here I simulated the cutoffs for each sample length, drawing random walks and running the same test.
India: what the rules do to a basket
- The short side. SEBI's broad framework for short selling (the annexure to MRD/DoP/SE/Dep/Cir-14/2007, 20 Dec 2007) allows every class of investor to short sell, but not naked: all investors must deliver at settlement. Institutions may not square off intraday. Securities in F&O are eligible. A retail investor's overnight short is therefore a stock future, a lent share under the securities lending scheme, or nothing.
- Which stocks. Under SEBI/HO/MRD/MRD-PoD-2/P/CIR/2024/116 (30 Aug 2024) a stock stays in derivatives only if it ranks among the top 500 by average daily traded value, with a market wide position limit of at least Rs 1,500 crore, average daily delivery value of at least Rs 35 crore and median quarter sigma order size of at least Rs 75 lakh. A stock that fails for three months exits, and cannot come back for a year. A basket drawn from today's list is not a basket of last year.
- Lots and settlement. Stock futures expire monthly, on the last Tuesday for contracts expiring on or after 1 Sep 2025 (NSE/FAOP/68747, 25 Jun 2025), and are physically settled for all stocks (SEBI/HO/MRD/DOPI/CIR/P/2018/161, 31 Dec 2018). From 7 Dec 2026 stock contracts keep trading to 3:45 pm on expiry day and settle on the volume weighted average of the last 30 minutes (HO/47/11/11(3)2025-MRD-POD2/I/23843/2026, para 4.2.5 and para 4.9).
- Limits and bans. The market wide limit of a stock is the lower of 15% of free float and 65 times average daily delivery value, floored at 10% of free float, and a client may hold 10% of it. At 95% of the limit the stock is in a ban period and trades must reduce the end of day position (SEBI/HO/MRD/TPD-1/P/CIR/2025/79, para 5.2, para 5.3 and para 5.8). A stop on one of ten legs breaks the hedge of the other nine.
- Margin. Initial margin and extreme loss margin are collected upfront from clients by trading members (SEBI/HO/MRD/TPD-1/P/CIR/2024/132, para 5.1.2). Margin is worked out stock by stock: a long in one stock does not offset a short in another.
- Costs. STT is 0.05% on the sale of a future (NSE/FATAX/73524, 31 Mar 2026) and the exchange charges Rs 183 per crore of traded value on each side of a future (NSE/FA/73061, 27 Feb 2026). A round trip on one futures leg is 8.66 basis points before brokerage, GST, stamp duty and the SEBI fee, against the ten of the paper.
The term this section turns on: Rank
What the research says
Lo and MacKinlay (1990) asked when the profits of a contrarian rule on US stocks are due to overreaction. They showed that part of them comes from stocks leading and lagging each other, which is a reason to strip out the common factors before reading a residual. Avellaneda and Lee (2010) did that with principal components and sector funds, found strong risk adjusted returns before 2003 and weaker ones after, and read the losses of August 2007 as a crowded trade coming apart. Khandani and Lo (2011) studied that month with factor and transaction data. Gatev, Goetzmann and Rouwenhorst (2006), and Do and Faff (2010, 2012), found the same pattern for simple pairs: profits that fell over time and shrank once costs were counted. The shared lesson is that a contrarian rule on residuals is a research hypothesis with a decaying edge. On Indian data over 179 sessions it is not distinguishable from zero.
Worked example: a year of Nifty 50 stocks
How many factors are real
On the last two hundred and fifty daily returns to 15 Sep 2026, the first factor carries 30.3% of all the variance in the file. That is the market. The chart shows the first five eigenvalues against the noise edge.
Three factors rise above the noise edge; the rest cannot be told from noise
The second factor is an IT block against metals, energy and power
Read one more paragraph, 59 words
Three factors clear the edge and the fourth falls just short of it. The second factor is dominated by the IT names and the third pulls the metals, power and energy stocks against the rest. Averaging each group's loadings on a factor, scaled so that a loading of one means an equal share, shows which block each factor is.
The recipe on 15 Sep 2026, one name
Take the 44 stocks with clean histories and fit the Avellaneda and Lee model at the close of 15 Sep 2026: 120 sessions for the correlation matrix, three factors, 60 sessions for the regression and the autoregression. 43 of 44 names passed the speed filter. Ten had a score beyond 1.25 in absolute value, 6 to open as shorts and 4 as longs. Take the name with the highest score and walk through it.
- The autoregression of its cumulative residual gave a = −0.0084 and b = 0.7335.
- Reversion speed: minus the log of b, times 252, is 78.1 a year, a half life of 2.2 sessions.
- Equilibrium mean m is a over (1 minus b), −0.0314. Averaged over all stocks m is 0.0007, which the paper subtracts to centre the means.
- The variance of the autoregression error is 0.000087. Divided by (1 minus b squared) and rooted, s_eq is 0.0137.
- The cumulative residual ends at zero by construction, so s is minus the centred mean over s_eq, which is 2.34.
Read one more paragraph, 59 words
The score of 2.34 is above 1.25, so the rule sells this stock to open, with the matching factor hedges long. A half life of 2.2 sessions says the residual would close its gap in two or three days. That is the bridge speaking: the same recipe on pure noise gives a median half life of 5.6 sessions.
Do the residuals revert? Eight settings
Now run the recipe forward. On each of 179 sessions from 24 Dec 2025 to 15 Sep 2026 I estimated everything on the data up to that close, set positions by the entry and exit rule, held to the next close and booked the next day's residual return, with no look ahead. Eight settings: one, three or five factors with a 40 or 60 session window, and one factor built from the Nifty 50 alone, a hedge a retail account could actually trade in the index future. The result is a mean return per day in basis points of capital, where each stock is allotted an equal share.
Eight settings, four slightly positive, none distinguishable from zero
Read one more paragraph, 165 words
Before costs six of the eight settings were positive and the best mean was 0.83 basis points a day, with a t value of 0.75. After the statutory charges four were positive and four negative, from −0.98 to 0.38. After adding the paper's own five basis points a trade on top, none of the eight was positive. With a t value of two as the usual hurdle and eight tries, a best t of 0.75 is what luck would give: the best of eight pure noise draws is expected to reach about one and a half. The strategy held 15.7 stocks on average, kept a position open for about 8 sessions, and turned over between 2.9 and 4.6 position changes a day. At 4.33 basis points a side for a stock leg, the charges for the three factor, 60 session setting were 0.30 basis points of capital a day, against a gross return of 0.25. The charges took the whole gross return.
Johansen on a basket of three large banks
Take three large banks, with their log prices for the same year. The trace statistic of the whole sample is above the five percent cutoff for its length. Split the year and neither half is.
The basket passed on the whole year and on neither half
Read one more paragraph, 50 words
The weights of the combination moved too. The weight on the second bank was negative in the first half and large and positive in the second. A relationship that reverses sign has no hedge ratio to hold. The module on Kalman hedge ratios asks whether letting the weights drift helps.
Screening every basket
One basket proves little. All of them show what a screen does. I ran the test on every one of the sixteen thousand baskets in each half.
Of the baskets that passed once, fewer than chance passed again
Read one more paragraph, 91 words
The first half passed five and a quarter percent of baskets, close to the five percent the cutoff promises, so the cutoffs behave as they should on this sample. The second half passed fewer. Of the baskets that passed in the first half, under two in a hundred passed again, below the rate for baskets overall. Choosing the best baskets from the first half and trading them in the second would have picked nothing. That is the answer to a screen of thousands: it finds what the data happened to do.
Second example (model): turning weights into lots
Model, not market data for the capital; the lot values are from the file. On 15 Sep 2026 one lot of a stock future was worth between Rs 4,30,796 and Rs 10,89,242, with a median of Rs 6,15,955. The Nifty lot was Rs 15,02,709. Suppose a rule wants to hold Rs 10 lakh of each of ten legs. Each leg rounds to a whole lot. Rounding errors came to a median of 14.6% of the target, a mean of 15.2% and as much as 32.9% on the worst name. At Rs 25 lakh a leg the median error was 6.5% and at Rs 50 lakh 2.7%.
Read 2 more paragraphs, 195 words
The hedge is worse. A Rs 10 lakh long position hedged against the first eigenportfolio puts a median of Rs 22,299 into each of the 47 hedge stocks, below half a lot in every one. To make the median hedge leg a single lot, the position would need about Rs 3.01 crore. That is why a retail version of this rule hedges with the index future and not with the eigenportfolio, a one factor hedge, the weakest of the eight settings above.
Capacity is a separate limit. Take a stock with a free float of Rs 50,000 crore and average daily delivery value of Rs 200 crore. Its market wide limit is the lower of 15% of free float, Rs 7,500 crore, and 65 times delivery value, Rs 13,000 crore, so Rs 7,500 crore. A client may hold 10% of it, Rs 750 crore, and the ban test fires at 95% of the limit, Rs 7,125 crore of futures equivalent open interest across all participants. Those are not the numbers that bind a book of a few crore. What binds is the lot, the spread and the cost of trading ten legs a day.
What this test leaves out
Six of the fifty stocks were left out of the backtest and three of the static analysis, for a one day price move of more than a quarter in the window, which in an end of day file is a split, a bonus issue or a demerger and not a return, or for an incomplete history. Prices are the cash underlying, not futures, so they carry no basis and no roll. Dividends sit inside the returns: an ex-dividend drop looks like a negative residual that needs no explanation. The rule held equal sized positions and took the closing prices as fills. None of that is how a desk would trade it, and each omission flatters the result a little. A result that is weak with the flattering version is weaker with the realistic one.
Appendix: how the cutoffs and the bridge test were made
The published trace cutoffs are for a very long sample. For a sample of a hundred and twenty five sessions the true cutoff is higher. I drew three thousand random walks of the exact length with a small drift, three series each, ran the same trace statistic on them, and took the ninety fifth percentile. As a check, the first half passed five and a quarter percent of baskets, and a long sample of five thousand sessions reproduced the published cutoffs to within about half a point. The bridge test drew twenty thousand vectors of sixty independent normal residuals, subtracted their mean so that the cumulative sum ends at zero, and fitted the same autoregression. The numbers are a method of mine, not a standard.

Stretch: what would have to be true
A residual rule needs three things at once: factors stable enough to estimate, residuals that really revert, and costs below the size of the reversion. The first is the noise edge, the second the forward test, the third the lot and the charge. The Kalman filter of module E11 lets the loadings move through time, which helps with the first. Judging the results honestly is a matter of walk forward design and the arithmetic of many trials: module A29 and module E16.
The common mistake
The claim: This basket of stocks passed a cointegration test, so the spread has to come back.
A pass is a statement about one sample, at an error rate. Across many baskets, some pass by luck, and in this file those that passed in the first half did not pass again in the second. The weights of the basket moved with the window, and the factors that a rule strips out are in part noise below the edge. Before taking a basket seriously, count how many were screened, hold the weights fixed on days the search never saw, include statutory costs for every leg, and ask how many settings were tried.
- Trusting the speed filter. A kappa above 8.4 passed 98.5% of pure noise. It is not evidence of reversion.
- Counting only the best of eight. A mean of 0.83 basis points before costs is the best of eight tries and a t of 0.75. The eight together average 0.26 before costs and −0.11 after statutory charges.
- Hedging with a basket that cannot be lotted. A Rs 10 lakh position needs about Rs 3.01 crore before the median hedge leg is one lot.
- Ignoring the short side rules. A cash short without a borrowed share must be squared the same day. Overnight, it is a future, with a monthly expiry and delivery on the last day.
- Trading a list that has moved. A stock that fails the eligibility test for three months leaves derivatives and cannot return for a year (SEBI/HO/MRD/MRD-PoD-2/P/CIR/2024/116, para 3.1 and para 3.5).

What I'd keep from this
- Eigenvector weights divided by volatility give eigenportfolios; only eigenvalues above the noise edge count.
- The s score is a residual path's distance from its mean, in usual sizes.
- A cumulative residual ends at zero, so the speed filter passes 98.5% of pure noise.
- Eight settings run forward were all within noise; charges took the gross return.
- Hedging with eigenportfolios needs crores before one leg reaches a single lot.
- Baskets that passed once did not pass again more often than chance.
Two terms to hold on to from 18.13
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