I want to use the R package stochvol to fit a SV model to a DAX training set and use the output to estimate a rolling one-step-ahead forecast:

DAX2log<- (logret(DAX, demean=TRUE))^2
trainset <- DAX2log[1:1912]

SV <- svsample(trainset, priormu = c(-10, 1), priorphi = 
         c(20, 1.1), priorsigma = .1, draws = 50000, burnin = 5000)

SVroll <- function(svsampleOBJ, NumofForecast, Data)
  mu <- summary(svsampleOBJ)$para[1]
      phi <- summary(svsampleOBJ)$para[2]
  sigma <- summary(svsampleOBJ)$para[3]
  HSV <- vector(mode=c("double"),length=NoF)

  for(i in 1:NumofForecast)
    H <- mu + phi*(Data[i] - mu) + sigma
    HSV[i] <- exp(H/2)

 HSV <- SVroll(svsampleOBJ = SV,NumofForecast = 2000,
             Data = DAX2log[1913:length(DAx2log)])

The main problem with this code is that the model becomes deterministic, but I did not manage to extract further draws from the predict function for the rolling forecast.

How can I get those draws from the posterior distribution and is my formula adequate?

In addition, there seems to be some mix up in the units, since HSV is squared daily returns, while the input is in log.

  • 1
    $\begingroup$ Hi BeneSP, welcome to quant.SE! Thank you for asking your question here! $\endgroup$
    – Bob Jansen
    Aug 11 '14 at 15:14

You might want to have a look at the stochvol vignette (http://cran.r-project.org/web/packages/stochvol/vignettes/article.pdf), where this process is described in detail in Algorithm 1. In particular, if I understand you correctly, what you need is step 4b.

Now to your code:

1) It's not really a rolling forecast, because you estimate the model only once.

2) When predicting, in the first three lines of your function, you only use the posterior mean of the parameters (as a point estimate). Why not use the entire distribution? That way you can also handle parameter uncertainty properly.

3) In an SV model (as opposed to GARCH-type models), volatility is assumed to be a latent random variable, thus when predicting (line H <- ...), you might want to do so by drawing from the corresponding (normal) distribution instead of updating deterministically. That's exactly what predict.svdraws does. You could have a look at the code there and adapt it to your needs.

Best, Gregor


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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