Skip to main content

Three-stage hybrid HAR-LSTM-GARCH framework for realized volatility forecasting

Project description

harlstmgarch

A Python library implementing the three-stage hybrid HAR-LSTM-GARCH framework for realized volatility forecasting.

Authors:

The model

The framework follows a sequential decomposition principle:

Stage Component Role
1 HAR (Corsi, 2009) Linear filter for the persistent, multi-scale volatility dynamics (daily / weekly / monthly components, OLS)
2 LSTM Recurrent neural network that learns the non-linear patterns left in the HAR residuals
3 GARCH(1,1) Models the conditional variance of the hybrid forecast errors — time-varying prediction intervals for risk management

The point forecast is H_{t+1} = HAR_{t+1} + LSTM residual forecast, and Stage 3 wraps it in a 95% interval H_{t+1} ± 1.96 σ_{z,t+1}.

Reference: Ben Romdhane, W., & Boubaker, H. (2026). A Hybrid HAR-LSTM-GARCH Model for Forecasting Volatility in Energy Markets. Journal of Risk and Financial Management, 19(2), 77.

Installation

pip install -e .

Requires Python ≥ 3.10 with tensorflow, arch, statsmodels, pandas, scikit-learn, matplotlib.

Quick start

import numpy as np
from harlstmgarch import (
    HARLSTMGARCH, load_realized_measures,
    har_components, chronological_split, metrics,
)

rv = load_realized_measures("RealizedMeasures03_10.csv")["RV"]
df = har_components(np.log(rv))               # log-RV, HAR features
train, val, test = chronological_split(df, train=0.70, val=0.15)

model = HARLSTMGARCH(lstm_kwargs={"lookback": 20, "units": 32})
model.fit(train, val)
fc = model.forecast(test)                     # strictly one-step-ahead

print(metrics.scoreboard(
    np.exp(test["RV"]),
    {"HAR": np.exp(fc.har), "Hybrid": np.exp(fc.point)},
))
print("95% coverage:",
      metrics.interval_coverage(np.exp(test["RV"]),
                                np.exp(fc.lower), np.exp(fc.upper)))

Package layout

harlstmgarch/
├── data.py      # RV construction, HAR components, chronological split
├── har.py       # Stage 1 — HAR-RV model (OLS, statsmodels)
├── lstm.py      # Stage 2 — LSTM on HAR residuals (TensorFlow/Keras)
├── garch.py     # Stage 3 — GARCH(1,1) on hybrid errors (arch)
├── hybrid.py    # HARLSTMGARCH orchestrator
├── metrics.py   # RMSE/MAE/MAPE/R²/QLIKE, McLeod-Li, Diebold-Mariano
└── plots.py     # publication-quality figures
examples/
└── run_case_study.py   # full empirical case study (2003-2010 RV data)

Case study

examples/run_case_study.py reproduces the full pipeline on 1,842 days of realized volatility computed from intraday data (Sept 2003 – Dec 2010, spanning the Global Financial Crisis), evaluates HAR, standalone LSTM and the hybrid out-of-sample, runs McLeod-Li and Diebold-Mariano tests, and exports all figures and tables to assets/.

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

harlstmgarch-0.1.0.tar.gz (12.7 kB view details)

Uploaded Source

Built Distribution

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

harlstmgarch-0.1.0-py3-none-any.whl (13.6 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for harlstmgarch-0.1.0.tar.gz
Algorithm Hash digest
SHA256 9ffbc41a4905f542c278151cbcbc29b22f1ef8b46b67b1f5bde50273ef64a5e2
MD5 274b463132766b3ae992508bed1159ca
BLAKE2b-256 52863636c8ae2b8480c16af6639dd396ea9b3008cc2d2a3db315293fd2e89341

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for harlstmgarch-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8115fb6c5574db0801e90c6ff41f4b34da928a5b21295c8fdcc274c8522493b7
MD5 431f7072fad2ada70052cce3560104ab
BLAKE2b-256 d5f7ad63356f91665adb38ea4fc1a545c5ea1c968e24100771ac2c323a751012

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