statsmodels coint_johansen which co-integration relations are the strongest?

Viewed 2485

Below is an example with 3 timeseries that (I believe) should be co-integrated by definition. However only one of the co-integration relations gives a co-integrated timeseries.

np.random.seed(1234)
nums = np.random.normal(size=10000)
z = np.cumsum(nums)
p = .3*z + np.random.normal(size=10000)
q = .6*z + np.random.normal(size=10000)
r = .2*z + np.random.normal(size=10000)

ordering1 = np.stack((p,q,r),axis=1)
from statsmodels.tsa.vector_ar.vecm import coint_johansen
jres1 = coint_johansen(ordering1, 0, 1)
d1 = np.dot(ordering1,jres1.evec[0])
plt.plot(d1)
d2 = np.dot(ordering1,jres1.evec[1])
plt.plot(d2)
d3 = np.dot(ordering1,jres1.evec[2])
plt.plot(d3)

from statsmodels.tsa.stattools import adfuller
def ADF(v, max_d=1, level='10%'):
    adf = adfuller(v, max_d)
    if adf[0] < adf[4][level]:
        return True
    else:
        return False
print(ADF(d1))
print(ADF(d2))
print(ADF(d3))

My questions are:

  1. Why is only one timeseries co-integrated in the ADF test, this example should have no problem finding co-integrated series?

  2. How can I know which of the possible co-integration relations I should use in order to get the most co-integrated timeseries. In the example it was number three but my tests has shown that this is by far not always the case.

1 Answers
  1. You can not test co-integration with ADF test. With ADF test, you can only test the time series' stationarity.

  2. There are two main methods to test the co-integration between the time series. You have to choose a methods that suits your data best, such as the sample size or number of the time series. https://corporatefinanceinstitute.com/resources/knowledge/other/cointegration/

    Another way to check the relationship between time series is Cross correlation function (CCF): https://support.minitab.com/en-us/minitab/18/help-and-how-to/modeling-statistics/time-series/how-to/cross-correlation/interpret-the-results/all-statistics-and-graphs/

Related