# NOT RUN {
# Get the data from Quandl
library("Quandl")
d <- Quandl("NASDAQOMX/OMXS30", start_date="2012-01-02",
end_date="2014-01-02", type="zoo")
y <- as.numeric(100 * diff(log(d$"Index Value")))
# Estimate the marginal posterior for phi
pmhOutput <- particleMetropolisHastingsSVmodel(y,
initialTheta = c(0, 0.9, 0.2),
noParticles=500,
noIterations=1000,
stepSize=diag(c(0.05, 0.0002, 0.002)))
# Plot the estimate
nbins <- floor(sqrt(1000))
par(mfrow=c(3, 1))
hist(pmhOutput$theta[,1], breaks=nbins, main="", xlab=expression(mu),
ylab="marginal posterior", freq=FALSE, col="#7570B3")
hist(pmhOutput$theta[,2], breaks=nbins, main="", xlab=expression(phi),
ylab="marginal posterior", freq=FALSE, col="#E7298A")
hist(pmhOutput$theta[,3], breaks=nbins, main="",
xlab=expression(sigma[v]), ylab="marginal posterior",
freq=FALSE, col="#66A61E")
# }
Run the code above in your browser using DataLab