Skip to content

Add HAR model for realized volatility (Corsi 2009)#855

Open
hass-nation wants to merge 1 commit into
bashtage:mainfrom
hass-nation:feat/har-model
Open

Add HAR model for realized volatility (Corsi 2009)#855
hass-nation wants to merge 1 commit into
bashtage:mainfrom
hass-nation:feat/har-model

Conversation

@hass-nation

Copy link
Copy Markdown

Summary

Adds HAR (Heterogeneous Autoregressive model for realized volatility), the standard workhorse model for forecasting realized variance in high-frequency financial econometrics (Corsi 2009, JFE).

The model regresses today's realized variance on daily, weekly, and monthly rolling averages of past realized variance:

RV_t = c + β_d·RV_{t-1} + β_w·RV̄_{t-1:t-5} + β_m·RV̄_{t-1:t-22} + ε_t

Estimation is OLS with optional Newey-West HAC standard errors.

Interface

from arch.univariate.har import HAR

har = HAR(rv_series, lags=[1, 5, 22])   # pandas Series of realized variances
res = har.fit(cov_type='robust')
print(res.summary())
res.forecast(horizon=5)

New file

arch/univariate/har.pyHAR and HARResult classes

HARResult attributes

  • params / param_names — OLS coefficients
  • rsquared — R²
  • pvalues, std_errors, tvalues — HAC-robust inference
  • predict(start, end) — in-sample fitted values
  • forecast(horizon) — recursive multi-step forecast
  • summary() — formatted text table

Tests

29/29 pass (arch/tests/test_har.py). Coverage: params shape, R² range, fitted-values shape, multi-step forecast, p-values in [0,1], custom lags, HAC vs OLS SEs, manual OLS verification.

Reference

Corsi, F. (2009). A Simple Approximate Long-Memory Model of Realized Volatility. Journal of Financial Econometrics, 7(2), 174–196.

Implements the Heterogeneous Autoregressive (HAR-RV) model as a
standalone OLS estimator in arch/univariate/har.py, with Newey-West
HAC standard errors, multi-step forecasting, and a text summary table.
29 tests added in arch/tests/test_har.py covering params, R-squared,
fitted values, forecasting, custom lags, input validation, and
numerical equivalence with manual OLS.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@codecov

codecov Bot commented Jun 28, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 99.10714% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 99.53%. Comparing base (543f44c) to head (90ea290).

Files with missing lines Patch % Lines
arch/univariate/har.py 98.59% 1 Missing and 1 partial ⚠️
arch/tests/test_har.py 99.48% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #855      +/-   ##
==========================================
- Coverage   99.54%   99.53%   -0.01%     
==========================================
  Files          78       80       +2     
  Lines       15818    16154     +336     
  Branches     1294     1315      +21     
==========================================
+ Hits        15746    16079     +333     
- Misses         38       39       +1     
- Partials       34       36       +2     
Flag Coverage Δ
adder 99.49% <99.10%> (-0.01%) ⬇️
subtractor 99.49% <99.10%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@bashtage

Copy link
Copy Markdown
Owner

This PR makes no sense. There is already a mean HAR which works as expected for RV.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants