Solved – Getting cointegration vectors using Johansen method

cointegrationself-studyvector-error-correction-model

I'm trying to understand better Johansen method so I developed an example 3.1 given by the book Likelihood-Based-Inference-Cointegrated-Autoregressive-Econometrics where we have three processes:

$$X_{1t} = \sum_{i=1}^t \epsilon_{1i} + \epsilon_{2t}$$

$$ X_{2t} = \alpha \sum_{i=1}^t \epsilon_{1i} + \epsilon_{3t} $$

$$ X_{3t} = \epsilon_{4t}$$

so the cointegration vectors should be [a, -1, 0] and [0, 0 1], but when I run Johansen method I can't get them.

The code I'm trying is the following:

import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
from statsmodels.tsa.stattools import adfuller
from statsmodels.tsa.johansen import coint_johansen

mu, sigma = 0, 1 # mean and standard deviation
n = 1000

s1 = np.random.normal(mu, sigma, n)
s2 = np.random.normal(mu, sigma, n)
s3 = np.random.normal(mu, sigma, n)

x_1t = np.cumsum(s1)+s2
x_2t = 7*np.cumsum(s1)+s3
x_3t = s3

#Creating Pandas object
todays_date = datetime.datetime.now().date()
index = pd.date_range(todays_date-datetime.timedelta(10), periods=n, freq='D')
y = pd.DataFrame(index=index, data={'col1': x_1t, 'col2': x_2t, 'col3':x_3t} )

p = 4
jres = coint_johansen(y, 0, p)

I've tried for several p-values and I can't get the cointegration vectors, I know I'm doing something wrong.
Thanks.

Best Answer

I've found the answer. If it is helpful for somebody, can check the following notebook:

http://nbviewer.ipython.org/github/mapsa/seminario-doc-2014/blob/master/cointegration-example.ipynb