Skip to content
All library documents

Using Johansen Cointegration Vectors to Form Pairs Trading Spreads

Article Quant Q&A · Author: floorscrapers

Summary

The document asks how to turn the output of a Johansen cointegration test into a spread for a two-stock pairs trading strategy. The trader contrasts the method with a spread formed from an ordinary least squares hedge ratio, where one stock is reduced by a multiple of the other. The displayed test output includes trace and maximum eigenvalue statistics, critical values, eigenvectors, and eigenvalues; the question is which vector supplies the weights for a candidate spread.

The material is a question rather than a complete procedure or answer. It does not establish which cointegration rank to select, explain how to normalize a vector, or discuss whether the resulting spread is stationary and tradable out of sample. Those choices matter: the test’s evidence for cointegration depends on the selected significance threshold, and the spread weights need consistent interpretation before they can be used in a strategy. No trading results or validation evidence are provided.

Key ideas

  • Johansen testing estimates cointegrating vectors that can serve as weights in a multi-asset spread.
  • The proposed use is to construct a two-stock pairs trading spread from the test output.
  • Trace and eigenvalue statistics are compared with critical values to assess cointegration rank.
  • The document leaves normalization, rank selection, and strategy validation unresolved.

Tags

Full text
# Johansen cointegration Test for spread generation


# Johansen cointegration Test for spread generation












I'm using the python statsmodels version of the johansen cointegration test and I'm looking for some advice on how best to generate the spread used within a pairs trading algorithm.

For example I've got the following output from the Johansen test of 2 stocks:

```
--------------------------------------------------
--> Trace Statistics
variable statistic Crit-90% Crit-95%  Crit-99%
r = 0    13.7837 13.4294 15.4943 19.9349
r = 1    0.6236 2.7055 3.8415 6.6349
--------------------------------------------------
--> Eigen Statistics
variable statistic Crit-90% Crit-95%  Crit-99%
r = 0    13.16 12.2971 14.2639 18.52
r = 1    0.6236 2.7055 3.8415 6.6349
--------------------------------------------------
eigenvectors:
 [[ 0.04981179  0.00546497]
 [-0.08553954  0.02214011]]
--------------------------------------------------
eigenvalues:
 [0.0510797  0.00248153]
--------------------------------------------------
```

Now I can see that I have some level of cointegration and I understand that the first row of the eigenvectors represents the best estimators for cointegration, but how should I use them in my code. I've previously calculated spread like so (when using beta from an OLS on the two stocks): `stock1 - B * stock2`

However now I've switched to using the Johansen method I believe I'm presented with two estimators to use for each price series but I'm unsure of how to use them.

I'd be grateful for some advice ?

Shown in full with attribution under the source's licence. Licence: CC BY-SA 4.0 (Stack Exchange)

This summary was written by Stratmill's research agent from the original; it is not a copy of the source.