Skip to main content

Multivariate VARMA modelling — exact maximum-likelihood estimation, forecasting and diagnostics

Project description

drvarma

Exact maximum-likelihood estimation, forecasting and diagnostics of multivariate VARMA (vector ARMA) models — in pure Python, with an optional compiled C engine for speed.

import numpy as np
from drvarma import Model, datasets

series = datasets.simulate_varma(phi=[np.diag([0.5, 0.4, 0.3])], sigma=np.eye(3),
                                 n=300, mu=[100., 50., 75.], seed=1,
                                 names=["A", "B", "C"])
m = Model(series, p=2, q=0, include_mean=True).fit()
print(m.phi, m.sigma, m.loglik)
levels, lo, hi = m.forecast(12, bands=True)     # + 95% bands
print(m.diagnostics())                          # Hosking Q, Jarque-Bera

drvarma fits a stationary Gaussian VARMA(p, q), Φ(B)(wₜ − μ) = Θ(B) aₜ, aₜ ~ N(0, Σ), by exact maximum likelihood (no conditional/back-forecasting approximation), and gives forecasts (+ error bands), impulse responses, variance decompositions, residual diagnostics and volatility.

What this provides. drvarma is a pure-Python implementation of Mauricio's exact-likelihood algorithm for multivariate VARMA (1995 JASA / 1997 AS 311): an innovations-form factorisation that evaluates the exact Gaussian likelihood directly on the VARMA form, without a state-space / Kalman filter, maximised by a faithful factored-BFGS quasi-Newton. Exact ML for VARMA is also available in Python through state-space methods (e.g. statsmodels' Kalman-filter VARMAX); what drvarma adds is a faithful port of this specific, non-Kalman algorithm — which, as far as we know, is not otherwise available in Python — together with the surrounding forecasting/IRF/FEVD/diagnostics toolkit. It runs with no compiled code; the optional C engine is only an accelerator.

Install

pip install drvarma                       # pure-Python (numpy + scipy)

Optional extras: drvarma[plots] (matplotlib + pyfug charts), drvarma[forecast-report] (HTML forecast reports), drvarma[c-engine] (build the CFFI C engine — needs GSL dev headers, ~10–100× faster but optional).

Features

  • Exact-ML estimation of stationary VARMA(p, q) for general dimension m, with mean, diagonal AR/MA/covariance restrictions, and optional Hannan–Rissanen two-step start.
  • Forecasting in original units: level, period and annual variation, each with standard errors and 95 % bands; plus fixed-parameter recursive (out-of-sample) forecasting.
  • Structural analysis: orthogonalised impulse responses, accumulated responses, long-run gain, and the forecast-error variance decomposition.
  • Diagnostics: Hosking multivariate portmanteau, multivariate Jarque–Bera, per-series ACF/PACF and two-sided cross-correlation (CCF).
  • Volatility: exponential-weight and moving-window residual covariance.
  • Transforms: Box-Cox + regular/seasonal differencing and harmonic deseasonalisation (with re-seasonalised forecasts).
  • I/O & reports: .inp reader/writer, C-format .out/.forecast/ .recursive text reports, an HTML forecast report per series, and matplotlib charts.

Everything runs with no compiled code. The optional CFFI engine wraps the validated drvarma C core and is bit-compatible with the pure-Python path on well-conditioned problems — an accelerator only. The numerical methods are tabulated below; see docs/DEVELOPER_GUIDE.md for the complexity discussion and a pure-Python vs hybrid vs C performance study.

Command line

drvarma IPC3 3 0 -mean -deseason auto -forecast 24        # writes IPC3.out, .forecast
drvarma IPC3 3 0 -mean -forecast 24 -html                # + HTML report per series
drvarma IPC3 3 0 -mean -estwin 200 -forecast 12          # recursive (.recursive)
drvarma IPC3 3 0 -mean -volexp 0.05 20 -volmov 20        # volatility (.volexp/.volmov)

<file>.inp in, text reports out. Flags: -mean -diagar -diagma -diagcov -m {1,2} -twostep -deseason [auto|force] -scale S -forecast H -html -estwin N -volexp [α w] -volmov [w] (λ, d, D come from the .inp header).

Documentation

Numerical methods

Algorithm Reference Used for
Exact Gaussian VARMA log-likelihood (innovations factorisation, not Kalman) Mauricio (1995) JASA; Mauricio (1997) AS 311 Exact likelihood (drvarma._as311)
Factored-BFGS quasi-Newton + Dennis–Schnabel line search Dennis & Schnabel (1983) ML optimisation (drvarma._qnewt.raxopt)
Concentrated objective f1ᵐ·f2 (σ² profiled, Σ = σ²·Q) Mauricio (1995) JASA §3 Conditioning; covariance / std errors
Hannan–Rissanen two-step Hannan & Rissanen (1982) VARMA start (-twostep)
Companion-form Lyapunov / autocovariances Mauricio (1997) AS 311 Stationary covariance, ψ-weights
Orthogonalised IRF & FEVD (Cholesky of Σ) Lütkepohl (2005) Structural analysis
Hosking multivariate portmanteau; multivariate Jarque–Bera Hosking (1980); Jarque & Bera (1980) Residual diagnostics
Exponential / moving-window conditional covariance Volatility (drvarma.volatility)

Cross-references: Mauricio (2002, JTSA 23(4)) and Shea (1989, AS 242) are the other efficient exact-likelihood methods compared in the literature.

Authors and licence

drvarma is developed by David E. Guerrero and Arthur B. Treadway, based on the exact-likelihood algorithms designed and coded by José Alberto Mauricio.

Released under the GNU General Public License v2.0 or later (GPL-2.0-or-later) — see COPYING.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

drvarma-0.1.0.tar.gz (148.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

drvarma-0.1.0-py3-none-any.whl (76.6 kB view details)

Uploaded Python 3

File details

Details for the file drvarma-0.1.0.tar.gz.

File metadata

  • Download URL: drvarma-0.1.0.tar.gz
  • Upload date:
  • Size: 148.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for drvarma-0.1.0.tar.gz
Algorithm Hash digest
SHA256 ed042a35858afd779c08761ab4e74749a6bc6870e022b4e26744c8d3b7452816
MD5 cb5724f050068ffc732e701533a8721f
BLAKE2b-256 279e40f1b8b4a8fa032ca1ed786dced0901b9317324d47cd7ada3fad205086e4

See more details on using hashes here.

File details

Details for the file drvarma-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: drvarma-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 76.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for drvarma-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e66d9b5251ffc3dfdaf701f9fa94c9f0a4f5db8b6935c19818a3942d6f2622f1
MD5 504588b9934c7ca01f42c0cccc3a5f05
BLAKE2b-256 52d03a347265a3ecf0ebb21bf5a429cc3d40aad39999efb6db7777a2b740d390

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page