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.

enter image description here

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(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.


1 Answer 1


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.

  • $\begingroup$ But what method of backtesting forecasting strenght would be best if that would be the case? $\endgroup$ Commented May 11, 2015 at 10:06
  • $\begingroup$ "clustering algorithms" have little or nothing to do with volatility calculations, so this post appears to be off topic $\endgroup$
    – Alex C
    Commented Sep 6, 2015 at 20:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.