Free trial
Menu
Free toolNo sign-up

Test Two NSE Stocks for Statistical Cointegration

A cointegration test checks whether two stock prices share a stable long-run relationship, so that the gap between them tends to return to an average. It is the statistical foundation of pairs trading. Two stocks can be highly correlated and still not be cointegrated; this tester tells you whether a pair's spread behaves in a way a pairs strategy can trade.

Engle–Granger cointegration test
1.372Hedge ratio (β)

Units of B against one unit of A

ADF statistic−4.17Cointegrated at the 1% level
Half-life2.3 daysTime to close half a gap
Current z-score0.49The spread is near its average
Critical values for two series
LevelCritical valueResult
1%−3.90Pass
5%−3.34Pass
10%−3.04Pass

Spread = A − (β × B + α), with α 237.96, from 120 rows. The test uses no lags; statistical software adds lag selection and p-values.

How pairs trading works, from test to trade.Read the pairs trading guide

This guide explains what the tester calculates, how to read its results, a worked example, the half-life of mean reversion and the pitfalls of cointegration testing.

What the tester calculates

Using the Engle–Granger method on a formation period, such as the last year of daily closes:

  1. Hedge ratio (β): the slope from regressing the price of stock A on the price of stock B. It tells you how many units of B to hold against one unit of A.
  2. Spread: A − β × B for each day.
  3. ADF statistic and p-value: an Augmented Dickey–Fuller test on the spread. A more negative statistic and a lower p-value suggest the spread is stationary, meaning it tends to revert.
  4. Half-life: an estimate of how many days the spread takes to close half of a gap from its average.
  5. Current z-score: how far today's spread is from its average, in standard deviations.

Reading the results

ResultWhat it suggests
p-value below 0.05Evidence of cointegration at the 5% level
p-value between 0.05 and 0.10Weak evidence
p-value above 0.10No reliable evidence of cointegration
Short half-life, such as under 20 daysThe spread reverts quickly enough to trade
Very long half-lifeReversion may be too slow to be useful

A worked example

This is a hypothetical result for two stocks in the same sector over one year of daily data:

  • Hedge ratio: 0.82
  • ADF statistic: −3.9, p-value: 0.01
  • Half-life: 6 trading days
  • Current z-score: +2.1

The low p-value suggests the pair is cointegrated over this period, the half-life suggests gaps have closed within about a week on average, and the current z-score shows the spread is stretched. A pairs strategy might sell A and buy 0.82 units of B in value terms, with an exit when the z-score returns to 0. See the pairs trading guide for full rules.

The half-life of mean reversion

The half-life comes from regressing the daily change in the spread on the previous day's spread. If the slope is λ (a negative number for a mean-reverting spread):

Half-life = −ln(2) ÷ λ

A spread with a half-life of 6 days closes half of any gap in about 6 days on average. It also guides a sensible maximum holding period for trades.

Choosing the order of the pair

The Engle–Granger test can give different results depending on which stock is A and which is B. Run it both ways. If one direction passes and the other does not, treat the evidence as weaker. The Johansen test, which handles both directions at once and can test more than two series, is an alternative.

Pitfalls

  • Spurious results. With many pairs tested, some will pass by chance. Testing 100 pairs at the 5% level can produce around five false positives. Prefer pairs with a clear economic link.
  • Relationships break. Mergers, regulation, management changes or business shifts can end a relationship permanently. Re-test regularly and use stops.
  • Formation-period bias. A pair chosen because it looks good on one period should be tested on the next period before trading.
  • Corporate actions. Splits, bonuses and dividends must be adjusted for, or they will distort the spread.
  • Execution. Trading the pair needs both legs, often through stock futures for overnight shorts in India, with lot sizes that rarely match the hedge ratio exactly.

Correlation vs cointegration

CorrelationCointegration
MeasuresWhether returns move togetherWhether price levels share a stable relationship
Needed for pairs tradingHelpful as a first filterEssential
Can two stocks have one without the other?YesYes

The stock correlation matrix is a useful first screen; this tester is the second step.

Start your free trial

Connect your broker, build a strategy and test it on paper before a single live order goes out.

Frequently asked questions

What is a cointegration test?

A statistical test of whether a combination of two price series, such as A minus a multiple of B, tends to return to a stable average.

What p-value means two stocks are cointegrated?

A p-value below 0.05 is the usual threshold for evidence of cointegration. It is evidence, not proof, and it can change with the period tested.

How long should the test period be?

Commonly one to two years of daily data. Longer periods give more data but may include old relationships that no longer hold.

Can cointegration change over time?

Yes. Relationships can weaken or break, so pairs should be re-tested regularly.

Sources

  • Engle, R. F. and Granger, C. W. J. (1987). Co-Integration and Error Correction: Representation, Estimation, and Testing. Econometrica, 55(2), 251–276
  • Johansen, S. (1991). Estimation and Hypothesis Testing of Cointegration Vectors in Gaussian Vector Autoregressive Models. Econometrica, 59(6), 1551–1580
  • Chan, E. P. (2013). Algorithmic Trading: Winning Strategies and Their Rationale. Wiley
The result on this page is hypothetical. Statistical tests do not guarantee future relationships between prices. This tool and guide are for education and are not investment advice.