HAR-RV Forecast
Calculate the Corsi (2009) Heterogeneous Autoregressive Realized Volatility (HAR-RV) forecast of future daily Realized Variance, per asset.
Volatility clustering happens across multiple, overlapping time horizons at once. HAR-RV captures this cheaply – without the numerical optimization a GARCH-family fit requires (see get_garch) – by regressing future daily Realized Variance on trailing daily, weekly and monthly average Realized Variance components. The daily Realized Variance itself can be constructed in several ways via estimator: the simplest is the squared daily return, while the OHLC range-based estimators (see get_volatility, which exposes the same estimators via its own method parameter) use the daily (pre-period-aggregation) term behind each of those estimators instead, which is more statistically efficient since it uses the daily trading range rather than only the close-to-close move.
For more information about the method, see the following paper:
- Corsi, F. (2009). “A Simple Approximate Long-Memory Model of Realized Volatility.” Journal of Financial Econometrics, 7(2), 174-196.
Also known as: HAR-RV model, Corsi’s HAR model, Heterogeneous Autoregressive model.
No programming experience? With the Finance Toolkit MCP server, AI assistants such as Claude and ChatGPT can calculate the HAR-RV Forecast for you. Just ask in plain English.
Calculate the HAR-RV Forecast in Python
The HAR-RV Forecast is available in the Risk module of the open-source Finance Toolkit. Install it with:
pip install financetoolkit -U
Then call get_har_rv_forecast as shown below.
from financetoolkit import Toolkit
toolkit = Toolkit(["AMZN", "TSLA"], api_key="FINANCIAL_MODELING_PREP_KEY")
toolkit.risk.get_har_rv_forecast(estimator="squared_return").tail()
Which returns:
| Date | AAPL | MSFT | Benchmark |
|---|---|---|---|
| 2022-12-23 | 0.0004 | 0.0002 | 0.0001 |
| 2022-12-27 | 0.0004 | 0.0002 | 0.0001 |
| 2022-12-28 | 0.0006 | 0.0003 | 0.0002 |
| 2022-12-29 | 0.0006 | 0.0006 | 0.0002 |
| 2022-12-30 | NaN | NaN | NaN |
The last row is NaN since there is no 2022-12-31 return yet to forecast against.
Parameters
get_har_rv_forecast accepts the following parameters:
- estimator (str, optional): How to construct the daily Realized Variance input, one of “squared_return”, “parkinson”, “garman_klass” or “rogers_satchell”. Defaults to “squared_return”.
- weekly_window (int, optional): The trailing window (in trading days) for the weekly RV component. Defaults to 5.
- monthly_window (int, optional): The trailing window (in trading days) for the monthly RV component. Defaults to 22.
- horizon (int, optional): The number of days ahead to forecast. Defaults to 1.
- rounding (int | None, optional): The number of decimals to round the results to. Defaults to 4.
- growth (bool, optional): Whether to calculate the growth of the HAR-RV forecast values over time. Defaults to False.
- lag (int | list[int], optional): The lag to use for the growth calculation. Defaults to 1.
- standardize (bool, optional): Whether to standardize (Z-Score) the result. When combined with growth=True, standardizes the growth values instead of the raw values. Defaults to False.
Related Risk Metrics
The Risk module page introduces the module, and the sidebar lists all of its functions.