# Estimate rolling stochastic volatility forecast using stochvol in R

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)
}
return(HSV)
}

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.

-
Hi BeneSP, welcome to quant.SE! Thank you for asking your question here! – 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.