Calculate the Granger causality test, for every ordered pair of tickers in the Toolkit instance, of whether the second helps predict the first.

“Granger causality” is a statement about predictive power, not true causation: one asset is said to Granger-cause another if past values of the first, combined with past values of the second itself, predict the second significantly better than past values of the second alone.

For more information about the method, see the following paper:

  • Granger, C.W.J. (1969). “Investigating Causal Relations by Econometric Models and Cross-Spectral Methods.” Econometrica, 37(3), 424-438.

Also known as: Granger causality test, predictive causality, lead-lag test.

Granger Causality in Python

Install the Finance Toolkit with:

pip install financetoolkit -U

Then call get_granger_causality as shown below.

from financetoolkit import Toolkit

toolkit = Toolkit(["AAPL", "MSFT"], api_key="FINANCIAL_MODELING_PREP_KEY")

toolkit.econometrics.get_granger_causality(period="weekly", max_lag=3)

Which returns:

Dependent Independent F-Statistic P-Value Granger-Causes (5%)
AAPL MSFT 2.4852 0.0630 False
MSFT AAPL 0.3750 0.7712 False

Parameters

The function accepts the following parameters:

  • period (str, optional): The data frequency (daily, weekly, monthly, quarterly, or yearly). Defaults to “daily”.
  • column (str, optional): The historical data column to test. Defaults to “Return”, since Granger causality assumes a stationary series (unlike the ADF/Engle-Granger tests, which operate on price levels on purpose).
  • max_lag (int, optional): The number of lags of both assets to include in the regressions. Defaults to 5.
  • include_benchmark (bool, optional): Whether to include “Benchmark” among the tickers paired up. Defaults to False.
  • rounding (int | None, optional): The number of decimals to round the results to. Defaults to None.
Share