使用statsmodels.tsa.grangercausalitytests进行简单的Granger Casuality测试

时间:2017-04-17 01:10:10

标签: python-3.x statsmodels

我有几个时间序列文件(540行x 6列),我想使用statsmodels.tsa.grangercausalitytests进行简单的Granger Casuality测试

  from statsmodels.tsa.stattools  import   grangercausalitytests

我的pandas dataframe(df)包含以下格式的数据

我尝试使用以下开放和关闭列打印测试:

 print(grangercausalitytests([df[Open], df[Close]], maxlag=15, addconst=True, verbose=True))

但它不起作用。有没有办法对每个列(开,高,低)进行格兰杰测试,即关闭,即打开和关闭,高和关闭,低和关闭

  Epochtime     Open       High       Low        Close      Vol

  1486094520, 808.11000, 808.11000, 808.11000, 808.11000, 100
  1486094580, 809.45000, 809.45000, 809.45000, 809.45000, 100
  1486094820, 809.99000, 809.99000, 809.99000, 809.99000, 100
  1486095540, 811.45000, 811.45000, 811.45000, 811.45000, 100
  1486095840, 811.30000, 811.30000, 811.01000, 811.01000, 300
  1486095900, 810.76000, 810.76000, 810.76000, 810.76000, 100
  1486096200, 812.00000, 812.00000, 812.00000, 812.00000, 100

1 个答案:

答案 0 :(得分:1)

它需要二维数组,请尝试以下操作:

print(grangercausalitytests(df[['Open', 'Close']], maxlag=15, addconst=True, verbose=True))