granger_causality

Defined in fynance.features.engineering

granger_causality(x, y, lag=1)[source]

Granger-causality F-test: does x help predict y?

Compares a restricted autoregression of y on its own lags with an unrestricted one that also includes lags of x. A small p-value means x Granger-causes y (adds predictive power beyond y’s past).

Parameters:
x, ynp.ndarray

One-dimensional series of equal length.

lagint, optional

Number of lags. Default 1.

Returns:
f_statfloat

F statistic of the restricted-vs-unrestricted comparison.

p_valuefloat

Associated p-value (low → x Granger-causes y).