Fit a Vector Autoregression (VAR) across every ticker in the Toolkit instance and trace out the Impulse Response Function (IRF) – how a one-standard- deviation shock to each ticker propagates through the whole system over periods periods ahead.

Also known as: IRF.

A natural companion to get_var_forecast: rather than forecasting the levels forward, this traces out each ticker’s dynamic response to a shock in every ticker (including itself) – see time_series_model.get_impulse_response_function for the full formula, the Cholesky-orthogonalization used to identify the shocks, and why the ordering of tickers is an identifying assumption.

No programming experience? With the Finance Toolkit MCP server, AI assistants such as Claude and ChatGPT can calculate the Impulse Response Function (IRF) for you. Just ask in plain English.

Calculate the Impulse Response Function (IRF) in Python

The Impulse Response Function (IRF) is available in the Econometrics module of the open-source Finance Toolkit. Install it with:

pip install financetoolkit -U

Then call get_impulse_response_function as shown below.

from financetoolkit import Toolkit

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

toolkit.econometrics.get_impulse_response_function(period="quarterly", periods=5)

Which returns:

Horizon (‘AAPL’, ‘AAPL’) (‘AAPL’, ‘MSFT’) (‘MSFT’, ‘AAPL’) (‘MSFT’, ‘MSFT’)
0 0.1667 0.0865 0 0.0708
1 0.0075 -0.0196 0.0836 0.0553
2 -0.0274 -0.0192 0.0178 -0.0006
3 -0.0071 -0.0007 -0.0108 -0.0097
4 0.0033 0.0032 -0.0054 -0.002
5 0.0019 0.0008 0.0007 0.0013

Parameters

get_impulse_response_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 model. Defaults to “Return”.
  • lags (int, optional): The VAR order. Defaults to 1.
  • periods (int, optional): The number of periods ahead to trace the response out to. Defaults to 10.
  • orthogonalized (bool, optional): Whether to orthogonalize the shocks via a Cholesky decomposition of the residual covariance matrix – see time_series_model.get_impulse_response_function. Defaults to True.
  • include_benchmark (bool, optional): Whether to include “Benchmark” among the tickers modeled jointly. Defaults to False.
  • rounding (int | None, optional): The number of decimals to round the results to. Defaults to None.

The Econometrics module page introduces the module, and the sidebar lists all of its functions.

Share