我想知道是否有更好的方法來測試,如果兩個變量是比下面的方法協整的:高效的協整檢驗在Python
import numpy as np
import statsmodels.api as sm
import statsmodels.tsa.stattools as ts
y = np.random.normal(0,1, 250)
x = np.random.normal(0,1, 250)
def cointegration_test(y, x):
# Step 1: regress on variable on the other
ols_result = sm.OLS(y, x).fit()
# Step 2: obtain the residual (ols_resuld.resid)
# Step 3: apply Augmented Dickey-Fuller test to see whether
# the residual is unit root
return ts.adfuller(ols_result.resid)
上述方法效果;然而,這不是非常有效。當我運行sm.OLS
時,計算了很多東西,而不僅僅是殘差,這當然增加了運行時間。我當然可以編寫自己的代碼來計算殘差,但我認爲這也不是很有效。
我正在尋找一個直接測試協同測試的構建測試。我在想Pandas
,但似乎無法找到任何東西。或者,也許有一個聰明的辦法來測試協整,而不需要運行迴歸或一些有效的方法。
我必須運行大量的協整測試,並且很好的改進我現有的方法。
嗨,大家好 - 自從上次回覆以來已經有幾年了。我想知道這裏有任何進展嗎?我認爲statsmodels還沒有一個協整檢驗方法,對嗎? – WillZ 2015-11-23 09:40:27