Johansen test for Cointegrating Time Series Analysis in R

J.Korn

January 22, 2019

A test due to Johansen[1] allows us to determine if three or more time series are cointegrated. This would be useful analysis to translate into a mean reversion trading strategy.

The following three times series data sets will be used for the example:

## [1] "GOOG"
GOOG.Open GOOG.High GOOG.Low GOOG.Close GOOG.Volume GOOG.Adjusted
1102.09 1122.310 1096.010 1114.22 1072400 1114.22
1120.00 1128.227 1115.000 1115.65 1315100 1115.65
1099.00 1128.000 1093.800 1127.46 1217300 1127.46
1135.82 1135.820 1100.020 1102.89 679000 1102.89
1110.53 1127.500 1108.480 1124.27 1066700 1124.27
1123.58 1140.930 1120.737 1140.17 996100 1140.17
## [1] "AAPL"
AAPL.Open AAPL.High AAPL.Low AAPL.Close AAPL.Volume AAPL.Adjusted
184.10 186.21 183.80 185.50 17365200 181.4822
186.29 187.19 182.91 185.11 22737700 181.1006
183.82 187.30 183.42 187.18 17731300 183.1258
187.79 187.95 183.54 183.92 13954800 179.9364
185.26 186.41 184.28 185.40 16604200 181.3844
185.42 188.43 185.20 187.97 17485200 183.8987
## [1] "IBM"
IBM.Open IBM.High IBM.Low IBM.Close IBM.Volume IBM.Adjusted
138.10 140.54 137.95 140.04 4523700 130.5398
140.32 141.36 139.61 139.70 3710100 130.2229
138.28 140.22 138.20 139.86 3405400 130.3720
140.65 140.94 139.37 139.57 1963200 130.1017
140.48 141.43 139.93 141.43 3744700 131.8355
141.53 142.94 141.17 142.48 2849000 132.8143

The following variables will be used to hold backward: (Close Price)

GOOGAdj = unclass(GOOG$GOOG.Close)
AAPLAdj = unclass(AAPL$AAPL.Close)
IBMAdj = unclass(IBM$IBM.Close)

##The Johansen Test produces the following results:

## 
## ###################### 
## # Johansen-Procedure # 
## ###################### 
## 
## Test type: trace statistic , with linear trend in cointegration 
## 
## Eigenvalues (lambda):
## [1] 4.449165e-03 3.125569e-03 1.804695e-03 6.938894e-18
## 
## Values of teststatistic and critical values of test:
## 
##           test 10pct  5pct  1pct
## r <= 2 |  5.54 10.49 12.25 16.26
## r <= 1 | 15.15 22.76 25.32 30.45
## r = 0  | 28.84 39.06 42.44 48.45
## 
## Eigenvectors, normalised to first column:
## (These are the cointegration relations)
## 
##               GOOG.Close.l2 AAPL.Close.l2 IBM.Close.l2   trend.l2
## GOOG.Close.l2      1.000000     1.0000000     1.000000  1.0000000
## AAPL.Close.l2     -1.439142   -17.5234126   -15.570925  0.1619705
## IBM.Close.l2       3.571236    -1.8561071     2.470901 -3.7774703
## trend.l2          -0.293524     0.5046487     0.748573 -0.1262161
## 
## Weights W:
## (This is the loading matrix)
## 
##              GOOG.Close.l2 AAPL.Close.l2  IBM.Close.l2      trend.l2
## GOOG.Close.d -0.0051307496 -7.289428e-04  2.125545e-04  3.210602e-18
## AAPL.Close.d -0.0004784436  6.136602e-05  1.478564e-04 -2.436872e-20
## IBM.Close.d  -0.0011838080  2.052026e-04 -6.299388e-05  1.538684e-18
## 
## ##################################################### 
## # Johansen-Procedure Unit Root / Cointegration Test # 
## ##################################################### 
## 
## The value of the test statistic is: 5.5436 15.151 28.836
10pct 5pct 1pct
r <= 2 | 10.49 12.25 16.26
r <= 1 | 22.76 25.32 30.45
r = 0 | 39.06 42.44 48.45
plotres(jotest)

plot(jotest)

##Reference:

[1] Johansen, S. (1991) Estimation and Hypothesis Testing of Cointegration Vectors in Gaussian Vector Autoregressive Models, Econometrica 59 (6): 1551-1580