Skip to content
All library documents

Rolling Out-of-Sample Forecasting for HAR-RV Models

Article Quant Q&A · Author: Niklas Lindeke

Summary

This discussion concerns producing a time series of out-of-sample forecasts from a heterogeneous autoregressive realized-volatility (HAR-RV) model. The model uses daily, weekly, and monthly realized-volatility measures, with weekly and monthly inputs formed as averages over five and twenty-two daily observations. The questioner estimates coefficients with OLS and HAC, or Newey–West, standard errors, then asks whether applying a rolling-window function to fitted predictions yields the desired weekly forecasting exercise.

The response does not provide a forecasting procedure or validate the code. Instead, it raises a caution about rolling windows in a different context: a cited paper argues that clustering time-series sequences may be unhelpful. That caveat applies if clustering is part of the workflow, but the question describes HAR-RV regression and does not establish that it uses clustering. Thus the exchange highlights the need to distinguish rolling estimation and genuine out-of-sample prediction from smoothing or transforming already fitted predictions, while leaving the implementation and forecast interpretation unresolved.

Key ideas

  • HAR-RV forecasting relates realized volatility to daily, weekly, and monthly volatility measures.
  • The example forms its weekly and monthly averages over five and twenty-two daily observations.
  • HAC or Newey–West estimation addresses dependence in regression errors but does not itself define an out-of-sample forecasting scheme.
  • Applying a rolling window to fitted predictions is not shown to produce the intended forecast series.
  • The cited warning about sequence clustering is conditional and does not answer the HAR-RV coding question.

Tags

Full text
# Moving window forecasting in Python


# Moving window forecasting in Python












I am looking to create some code that will out-of-sample forecast the HAR-RV model.

The model itself is formulated as the following, and the betas are estimated through HAC-OLS or Newey-West.

Where weekly and monthly are 5 and 22 daily averages of the daily RV, but if you're interested read more about it here.

So I have all the data and parameters ready in pandas dataframes.

I now wish to forecast on moving windows so that I can obtain a time series that will show me how the entire period would have been predicted on a weekly basis.

So my problem is now that I dont really know how to write something like that. I dont really know how I should interpret the forecasting of this model.

I have seen very intuitive models for forecasting GARCH, but I am having a hard time coming up with the proper equation for forecasting HARRV, and so forth trouble programming it.

This is what I have accomplished.

This code:

```
Model = smf.ols(formula='RVFCAST ~ RV1 + RV5 + RV22', data = df).fit(use_correction=True)
mdl = Model.get_robustcov_results(cov_type='HAC', maxlags=1, use_correction=True)
#print(mdl.summary());
#print(pd.stats.ols.OLS(y=df['RVFCAST'], x=df[['RV1', 'RV5', 'RV22']], nw_lags=1))

actual = pd.DataFrame(0.0005 + 0.272 * df.RV1 + -0.0486 * df.RV5 + 0.7061 * df.RV22)

pred = pd.DataFrame(mdl.predict())

rw = pd.rolling_window(pred, window = 5, win_type = 'blackman')
```

As you see I used the `rolling_window` function which I believe applies a rolling window analysis, and the data/function applied is the "pred" which, as you can see, is a OLS prediction from my previous HAC-OLS.

But all in all, I have no idea if what I have done is correct at all, if the rolling_window function does what I want it to do, so my question is whether or not this is correct or just gobbledygook.

## Answer by babelproofreader (score -1)

https://quant.stackexchange.com/a/17716

I can't directly answer your question about coding for HAR-RV models, but before you do anything with rolling windows I suggest you look at the paper here. Essentially the paper claims that clustering on time series sequences ( i.e. rolling windows ) is useless, so if your HAR-RV model involves clustering in anyway you'll need to think very carefully about how you apply it.

Shown in full with attribution under the source's licence. Licence: CC BY-SA 4.0 (Stack Exchange)

This summary was written by Stratmill's research agent from the original; it is not a copy of the source.