VAR Forecast
Fit a Vector Autoregression (VAR) across every ticker in the Toolkit instance and forecast forecast_steps periods ahead.
A VAR models several series jointly: each ticker’s value is regressed on lags past values of all tickers, including its own. Each asset’s future can therefore depend on its own history and on the history of the others, without deciding in advance which one drives which.
The formula is as follows:
\[Y_{t} = c + \text{SUM\_\{l} = \text{1\}} ^{\text{\{lags\}}} (\Phi_{l} \cdot Y_{\text{t-l}}) + e_{t},\;\; \text{with}\; Y_{t} \;\text{every ticker's}\; \text{column} (\text{Return by default}) \text{and}\; \text{lags} = 1 \;\text{by default}\]- Each equation is an OLS regression on a constant and the
lagslagged values of all tickers
Where Y_t holds the values of all tickers at time t and each Phi_l is a matrix of coefficients. Because every equation has the same regressors, the model is estimated exactly by a separate OLS regression per ticker. Forecasts are produced by running the fitted equations forward one step at a time, feeding each forecast back in as the most recent lag. The coefficients show how shocks spread between assets; get_impulse_response_function and get_variance_decomposition summarise that, and get_granger_causality tests whether one ticker helps predict another. A VAR assumes stationary series, so returns are generally more suitable than prices (see get_augmented_dickey_fuller).
For more information about the method, see the following paper:
- Sims, C.A. (1980). “Macroeconomics and Reality.” Econometrica, 48(1), 1-48.
Also known as: VAR model, vector autoregressive model.
VAR Forecast in Python or via the MCP
Install the Finance Toolkit with:
pip install financetoolkit -U
Then call get_var_forecast as shown below.
from financetoolkit import Toolkit
toolkit = Toolkit(
["^VIX", "^VIX3M"],
api_key="FINANCIAL_MODELING_PREP_KEY",
start_date="2021-01-01",
end_date="2025-12-31",
)
toolkit.econometrics.get_var_forecast(column="Adj Close", forecast_steps=20)
Or, after setting up the Finance Toolkit MCP, ask:
What does a VAR model fitted to the daily levels of the VIX and the three-month VIX from 2021 to 2025 forecast for the next 20 days?
Which returns:
| Step | ^VIX | ^VIX3M |
|---|---|---|
| 1 | 15.2712 | 18.3667 |
| 2 | 15.5578 | 18.5342 |
| 3 | 15.8138 | 18.6846 |
| 4 | 16.0425 | 18.82 |
| 5 | 16.2471 | 18.9418 |
| 6 | 16.4301 | 19.0517 |
| 7 | 16.5941 | 19.1509 |
| 8 | 16.7411 | 19.2406 |
| 9 | 16.873 | 19.322 |
| 10 | 16.9915 | 19.3958 |
| 11 | 17.0981 | 19.4629 |
| 12 | 17.1942 | 19.5241 |
| 13 | 17.2808 | 19.58 |
| 14 | 17.359 | 19.6311 |
| 15 | 17.4298 | 19.6781 |
| 16 | 17.494 | 19.7213 |
| 17 | 17.5523 | 19.7611 |
| 18 | 17.6053 | 19.7979 |
| 19 | 17.6536 | 19.8321 |
| 20 | 17.6978 | 19.8639 |
Using Your Own Data
get_var_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_var_forecast()
Parameters
get_var_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 “Return”. | "Return" |
lags | int | The VAR order. Defaults to 1. | 2 |
forecast_steps | int | The number of periods ahead to forecast. Defaults to 5. | 10 |
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 |