gpt4 book ai didi

python - statsmodels coint_johansen 哪个协整关系最强?

转载 作者:行者123 更新时间:2023-12-03 21:29:12 26 4
gpt4 key购买 nike

下面是一个包含 3 个时间序列的示例,(我相信)应该根据定义进行协整。然而,只有一个协整关系给出了协整时间序列。

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))

我的问题是:
  • 为什么在 ADF 测试中只有一个 timeseries 协整,这个例子应该没​​有问题找到协整序列?
  • 我怎么知道我应该使用哪种可能的协整关系来获得最协整的时间序列。在示例中,它是第三个,但我的测试表明,到目前为止情况并非总是如此。
  • 最佳答案

  • 你不能用 ADF 检验来检验协整。使用 ADF 测试,您只能测试时间序列的平稳性。
  • 有两种主要的方法来测试时间序列之间的协整。您必须选择最适合您的数据的方法,例如样本大小或时间序列的数量。
    https://corporatefinanceinstitute.com/resources/knowledge/other/cointegration/
    另一种检查时间序列之间关系的方法是互相关函数(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/
  • 关于python - statsmodels coint_johansen 哪个协整关系最强?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45495471/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com