JourneyMan
JourneyMan

Reputation: 117

simple Granger Casuality test using statsmodels.tsa.grangercausalitytests

I have several time-series files ( 540 rows x 6 columns ) that i would like to do a simple Granger Casuality test using statsmodels.tsa.grangercausalitytests

  from statsmodels.tsa.stattools  import   grangercausalitytests

my pandas dataframe ( df) contains the data in the following format

i tried to print the tests using Open and close columns with following:

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

but it does not work. Is there a way to perform Granger test on each Column ( Open, High, Low ) with Close i.e Open and close, High and close , low and close )

  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

Upvotes: 2

Views: 5040

Answers (1)

maximazzik
maximazzik

Reputation: 51

It requires 2-dimensional array, try this:

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

Upvotes: 3

Related Questions