When using the statstools cointegration function to test for cointegration with default parameters between two sine waves with a 1 period lag, coint() returns that there is no cointegration. Running a manual ADF test on residuals of the two waves shows that of course there is.

import statsmodels.tsa.stattools as ts
import statsmodels.api as sm

sin = pd.DataFrame(pd.Series([np.sin(x) for x in np.arange(0,50,0.1)]).rename('sin1'))
sin['sin2'] = sin['sin1'].shift(1)
sin['resid'] = sin['sin1'] - sin['sin2']
sin = sin.dropna()

def cointegration_test(y, x):
    ols_result = sm.OLS(y, x).fit() 
    return ts.adfuller(ols_result.resid)

# No cointegration found
ts.coint(sin['sin1'], sin['sin2'])
#(-0.0012969, 0.9858, array([-3.91856695, -3.34842679, -3.05297743]))

#Cointegration found
#(-388.12, 0.0, 1, 497, {'1%': -3.443,  '5%': -2.86,  '10%': -2.56}, -30440.043)

I believe this is down to the underlying lag logic in coint(), setting maxlag=1 does enable coint() to find cointegration however maxlag=2 and it reverts to finding nothing.

Is this behaviour correct? And if so what is the correct way of parameterising coint() such that it returns the result I expect (The two waves are cointegrated)?


1 Answer 1


Two sine waves cannot be cointegrated because a sine wave is not an integrated process; a sine wave does not have a unit root. Only integrated processes can be cointegrated. Therefore, the fact that the Dickey-Fuller test rejects a unit root in the residuals of a regression of $Y$ (e.g. sine wave number 1) on $X$ (e.g. sine wave number 2) does not automatically mean $Y$ and $X$ are cointegrated. I do not know how the different Python functions work, but I suppose that if you supply non-integrated series where integrated ones are expected and this problem is not checked internally in the function, the function may falsely conclude there is cointegration.

  • $\begingroup$ Thanks Richard, could a way of modifying the test be to give the initial sine wave a low but persistent trend to make it an integrated process (non-stationary) ? Then checking the residuals between that and a similar but lagged series? $\endgroup$
    – rbonallo
    Commented Feb 24, 2021 at 8:49
  • 1
    $\begingroup$ @rbonallo, if you care about cointegration, the trend must be stochastic, not deterministic. Add a random walk to your series, and then you will have an integrated process + a deterministic part (sine wave) which is still an integrated process. $\endgroup$ Commented Feb 24, 2021 at 8:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.