I've just started trying to use OpenBUGS for Bayesian analysis of stochastic volatility models. In particular, I'm trying to calculate stochastic covariance, similar to the DC-MSV model specified by Meyer and Yu (2006).
I found WinBUGS code online in Applied Bayesian Hierarchical Methods by Congdon which implements the DC-MSV model (Meyer & Yu 2006). With some minor modifications, my model (saved as msv01.txt) is as follows:
model
{
for (t in 1:T)
{
D[t] <- exp(h[1,t]+h[2,t])*(1-rho.e*rho.e);
y.Prec[t,1,1] <- exp(h[2,t])/D[t];
y.Prec[t,2,2] <- exp(h[1,t])/D[t];
y.Prec[t,1,2] <- -rho.e*exp(0.5*h[1,t]+0.5*h[2,t])/D[t];
y.Prec[t,2,1]<- y.Prec[t,1,2];
y[t,1:2] ~dmnorm(nought[1:2],y.Prec[t,,]);
}
# log volatility VAR
for (p in 1:P)
{
h.st[1,p] ~dnorm(mu[p],1)
for (t in 2:T)
{
h.st[t,p] ~dnorm(h.mu[t,p],1);
h.mu[t,p] <- mu[p] + ph[p]*(h.st[t-1,p]-mu[p]);
}
}
for (t in 1:T)
{
h[1,t] <- sig.u[1]*h.st[t,1];
h[2,t] <- sig.u[2]*rho.u*h.st[t,1]+sig.u[2]*sqrt(1-rho.u*rho.u)*h.st[t,2];
}
# priors
for (p in 1:P)
{
inv.sig2.u[p] ~dgamma(1,1);
sig.u[p] <- 1/sqrt(inv.sig2.u[p]);
phstar[p] ~dbeta(19,1);
ph[p] <- 2*phstar[p] -1;
mu[p] ~dnorm(0,1);
}
rho.e ~dunif(-1,1);
rho.u ~dunif(0,1);
nought[1] <- 0;
nought[2] <- 0;
}
Is this model well specified? I'm using the R2OpenBUGS
package to call the program from within R. I receive no error messages in R. The OpenBUGS log is as follows:
model is syntactically correct
data loaded (variables not in the model: y.XLF, y.XLE)
model compiled
initial values generated, model initialized
model is updating
1000 updates took 2 s
model is updating
So, it appears there are no problems with the model. However, the Traphandler opens and it appears that there may actually be some problem with my multivariate normal specification producing an undefined real number. I'm having difficulty figuring out why? Is this a problem with my statistical model or a problem with the code? I suspect it's a problem in my model. The Traphandler is as follows:
For what it's worth, my R code is relatively simple, given by:
library("R2OpenBUGS") # For SV models
y <- 100*etf[2:100,1:2]/etf[1:99,1:2]-100
myData <- c(y = y, T = nrow(y), P = 2)
msv0.bug <- bugs(data = myData, inits = NULL, parameters.to.save = c("h", "y.Prec"),
model = "msv0.txt", n.iter = 11000, n.burnin = 1000, n.chains = 1, DIC = FALSE,
OpenBUGS.pgm = "c:/Program Files (x86)/OpenBUGS/OpenBUGS323/OpenBUGS.exe", debug = TRUE)
Any guidance would be appreciated. Thank you!