makystats GitHub PyPI FR · EN

VAR

Vector autoregression in levels, native OLS estimation (coefficients, ICs, IRF, FEVD, Granger, JB, whiteness, graphical diagnostics).

Source README: makystats/var_model/README.md

Import

from makystats import VAR, select_var_order

Deterministic terms

detContent
nNone
cConstant (default)
tLinear trend only
ctConstant + trend
cttConstant + trend + quadratic

Example

from makystats import VAR

res = VAR(df[["DTS", "FMG"]], k_ar=1, det="c").fit()
print(res.summary())
print(res.aic, res.bic)                 # system ICs (−2ℓ/T)
print(res.fittedvalues.head())          # DataFrame, estimation index
print(res.resid.head())
print(res.forecast(5))                  # all variables
print(res.forecast(5, variables="DTS"))
print(res.forecast(5, conf_int=True, variables=["DTS", "FMG"]))
print(res.irf(10).to_wide()["DTS"])
print(res.fevd(10).to_wide()["DTS"])
print(res.test_causality("DTS", "FMG"))
print(res.test_normality())
print(res.test_whiteness(nlags=2))
res.plot_diagnostics(lags=12)

Order selection

order = select_var_order(data, maxlags=4, det="c", criterion="bic")
print(order.table)       # sorted by criterion (best on top), index = k_ar
print(order.best)        # p* for criterion
print(order.selected)    # {'aic': …, 'bic': …, 'hqic': …}

order = select_var_order(data, maxlags=4, return_best=True, criterion="aic")
order.best_model.summary()
order.best_model.forecast(3, variables="DTS")

Options aligned with select_order (ARMA-GARCH): criterion, return_best, verbose, common_sample (comparable ICs on the same T−maxlags sample).

Bridge to VECM

from makystats import select_coint_rank, VECM

p = order.best
k_ar_diff = p - 1
rank = select_coint_rank(data, k_ar_diff=k_ar_diff, test_case="3")
if rank.rank >= 1:
    model = VECM(data, k_ar_diff=k_ar_diff, coint_rank=rank.rank, det_case="3a").fit()
else:
    res = VAR(data, k_ar=p, det="c").fit()

API VARResults

Method / propertyRole
summary()Header + per-equation tables + diagnostics + system ICs
params / stderr / tvalues / pvaluesCoefficients
fittedvalues / residDataFrames, estimation index (data.index[k_ar:])
coef_table() / equation_stats()Per-equation coeffs and diagnostics
forecast(steps, conf_int=…, variables=…)Forecast; default = all variables
irf(periods).to_frame(), .to_wide(), .plot()
fevd(periods).to_frame(), .to_wide(), .plot()
test_causality(caused, causing)Granger (F)
test_normality()Multivariate Jarque–Bera
test_whiteness(nlags)Multivariate portmanteau
plot_diagnostics(lags=…, equations=…)One row per equation

forecast and variable filter

res.forecast(5)
res.forecast(5, variables="DTS")
res.forecast(5, variables=["FMG", "DTS"])   # order preserved
out = res.forecast(5, conf_int=True, variables="DTS")
# out["mean"], out["lower"], out["upper"]

Forecast remains a multivariate system internally; only the exposed result is filtered.

IRF and FEVD

irf = res.irf(10)
irf.to_frame()          # long: horizon, response, impulse, value
irf.to_wide()["DTS"]
irf.plot()

fevd = res.fevd(10)
fevd.to_wide()["DTS"]   # shares (rows sum to 1)
fevd.plot()

Reading FEVD. For equation DTS at horizon 5, shock[FMG] = 0.38 means about 38% of DTS forecast-error variance at 5 steps is attributable to FMG shocks (Cholesky order = column order).

Residual diagnostics

res.plot_diagnostics(lags=12)
res.plot_diagnostics(equations=["DTS"], lags=8)

One row per equation: standardised residuals, histogram + N(0,1)/KDE, Q-Q, ACF, ACF of squares. Residual correlation heatmap at the bottom.

System ICs (−2ℓ/T)

AIC = −2ℓ/T + 2k/T · BIC = −2ℓ/T + k log(T)/T
(summary() also reports the log|Σ̂| scale.)