# Is my OpenBUGS / WinBUGS model well specified?

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*h.st[t,1];
h[2,t] <- sig.u*rho.u*h.st[t,1]+sig.u*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 <- 0;
nought <- 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
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!

• If it were me, I would try running your model using JAGS (with the rjags package). Should take very little (if any) effort changing the code, and I've found the error messages in JAGS to be a little more transparent. – guy Oct 6 '14 at 0:22
• @guy Switched to JAGS with rjags package. Helped me find a couple bugs quickly and now the code is working like a charm. Thanks! – ch-pub Oct 6 '14 at 2:23
• @nsw Would you mind sending me your JAGS code? I want to try out the same, so that would be very helpful. Thanks in advance! – rbm May 15 '15 at 7:56