Fit a Vector Error Correction Model (VECM) across every (cointegrated) ticker in the Toolkit instance and forecast forecast_steps periods ahead.

Also known as: VECM, error correction model (for the multivariate/cointegrated case).

A VECM keeps a VAR’s short-run dynamics while ALSO letting each asset’s price change react to how far the system currently sits from its long-run equilibrium (the cointegrating relationship(s) among the tickers, taken from cointegration_model.get_johansen_cointegration) – see time_series_model.get_vecm_forecast for the full formula, estimation method and verification notes.

No programming experience? With the Finance Toolkit MCP server, AI assistants such as Claude and ChatGPT can calculate the VECM Forecast for you. Just ask in plain English.

Calculate the VECM Forecast in Python

The VECM Forecast is available in the Econometrics module of the open-source Finance Toolkit. Install it with:

pip install financetoolkit -U

Then call get_vecm_forecast as shown below.

from financetoolkit import Toolkit

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

# AAPL/MSFT alone aren't cointegrated in this sample -- add Benchmark to the
# system to get one that is.
toolkit.econometrics.get_vecm_forecast(period="quarterly", include_benchmark=True)

Which returns:

Step AAPL MSFT Benchmark
1 131.672 237.052 380.084
2 136.414 266.892 404.920
3 147.872 281.265 413.975
4 154.833 289.048 413.568
5 152.306 273.929 396.546

Parameters

get_vecm_forecast 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 “Adj Close” – a VECM needs price LEVELS (non-stationary, cointegrated series), not returns, the same input get_johansen_cointegration expects.
  • k_ar_diff (int, optional): The number of lagged first differences to include as short-run dynamics. Defaults to 1.
  • forecast_steps (int, optional): The number of periods ahead to forecast. Defaults to 5.
  • significance (float, optional): The significance level (one of 0.01, 0.05, 0.10) at which the Johansen trace test determines the cointegrating rank. Defaults to 0.05.
  • 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