VECM Forecast
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.
The formula is as follows:
\[\text{Rank}\; r = \text{the number of leading Johansen trace statistics} (\text{det\_order} = 0,\; \text{k\_ar\_diff} \;\text{lags}) \text{that exceed their critical value at}\; \text{significance} (5\% \;\text{by default}) \text{;} r = 0 \;\text{raises an error}\] \[\Delta \text{Yₜ} = \alpha \cdot \text{beta'} \cdot \text{Yₜ₋₁} + \operatorname{Σ}(i = 1..k) \text{Γᵢ} \cdot \Delta \text{Yₜ₋ᵢ} + c + \text{epsilonₜ},\;\; \text{with Yₜ every ticker's column level (Adj Close by default)},\;\; k = \text{k\_ar\_diff} (1 \;\text{by default}) \text{and}\; c a \;\text{constant outside the cointegrating relation} (\text{statsmodels VECM with deterministic} = \text{"co"}),\;\; \text{fitted by Maximum Likelihood}\]- Forecast: the fitted recursion run forward
forecast_stepsperiods, in levels
VECM Forecast in Python or via the MCP
Install the Finance Toolkit with:
pip install financetoolkit -U
Then call get_vecm_forecast as shown below.
from financetoolkit import Toolkit
toolkit = Toolkit(
["GOOGL", "GOOG"],
api_key="FINANCIAL_MODELING_PREP_KEY",
start_date="2021-01-01",
end_date="2025-12-31",
)
# The two share classes of Alphabet are cointegrated: their prices cannot drift apart.
toolkit.econometrics.get_vecm_forecast()
Or, after setting up the Finance Toolkit MCP, ask:
What does a VECM fitted to the daily share prices of Alphabet's class A and class C shares from 2021 to 2025 forecast for the next five days?
Which returns:
| Step | GOOGL | GOOG |
|---|---|---|
| 1 | 312.569 | 313.352 |
| 2 | 312.75 | 313.553 |
| 3 | 312.929 | 313.747 |
| 4 | 313.109 | 313.941 |
| 5 | 313.289 | 314.135 |
Using Your Own Data
get_vecm_forecast runs on any data, not only prices: ratios, economic indicators, yield curves or your own dataset. Pass a DataFrame, a Series or a dictionary of them to Econometrics as data, with the dates in the rows or the columns, and set changes to how its changes are calculated: "percentage", "log", "difference" for rates and ratios, or None when the data are changes already. For example, for the monthly unemployment rates of the United States and Germany:
from financetoolkit import Economics, Econometrics
economics = Economics(start_date="2000-01-01")
unemployment = economics.get_unemployment_rate(
countries=["United States", "Germany"], period="monthly"
)
econometrics = Econometrics(data=unemployment, changes="difference")
econometrics.get_vecm_forecast()
Parameters
get_vecm_forecast accepts the following parameters.
| Parameter | Type | Description | Example |
|---|---|---|---|
period | str | The data frequency (daily, weekly, monthly, quarterly, or yearly). Defaults to “daily”. | "weekly" |
column | str | 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. | "Close" |
k_ar_diff | int | The number of lagged first differences to include as short-run dynamics. Defaults to 1. | 2 |
forecast_steps | int | The number of periods ahead to forecast. Defaults to 5. | 10 |
significance | float | 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. | 0.01 |
include_benchmark | bool | Whether to include “Benchmark” among the tickers modeled jointly. Defaults to False. | True |
rounding | int | None | The number of decimals to round the results to. Defaults to None. | 2 |