Hello,
I am new to this forum. I have an issue with my implementation of the Multivariate Stochastic Volatitlity model as in Meyer and Yu (2006). I Implemented the model in stan (see the attached MSV.stan file).
I simulate data and try to fit the model with the following R code. However I reveive the following error message.
Initialization between (-2, 2) failed after 100 attempts.
Try specifying initial values, reducing ranges of constrained values, or reparameterizing the model.
[1] “Error in sampler$call_sampler(args_list[[i]]) : Initialization failed.”
[1] “error occurred during calling the sampler; sampling not done”
and I can not figure out what the problem is. For debugging I printed out the paramter values but they are fine. THe content of the diagnostic_file
Sample generated by Stan
stan_version_major=2
stan_version_minor=16
stan_version_patch=0
init=random
enable_random_init=1
seed=1692406610
chain_id=1
iter=1000
warmup=500
save_warmup=1
thin=1
refresh=100
stepsize=1
stepsize_jitter=0
adapt_engaged=1
adapt_gamma=0.05
adapt_delta=0.8
adapt_kappa=0.75
adapt_t0=10
max_treedepth=10
sampler_t=NUTS(diag_e)
diagnostic_file=diag.txt
append_samples=0
does help me either, so I hope that any of you might know how to help me.
Best regards and thanks in advance
Chris
library(rstan)
simMSV <- function(N,k,B, Seps, mu, phi, Seta,TT){
library(mvtnorm)
eta <- matrix(rmvnorm(TT,c(rep(0,k)),Seta),nrow = TT,ncol = k)
u <- matrix(rmvnorm(TT,c(rep(0,k)),diag(k)),nrow = TT, ncol = k)
eps = matrix(rmvnorm(TT,c(rep(0,N)),Seps),nrow = TT, ncol = N)
h <- matrix(rep(0,kTT),nrow = TT,ncol = k)
h[1,] <- mu
for (t in 2:TT){
h[t,] <- mu + phi(h[t-1]-mu) + eta[t-1,]
}
f <- exp(h/2)u
y <- B%%t(f) + t(eps)
y = t(y)
result = matrix(cbind(y,exp(h/2)),nrow = TT,ncol = k+N)
colnames(result)<-c(sprintf(“Y%d”,seq(1,N,1)),sprintf(“vol%d”,seq(1,k,1)))
return(result)
}
R = 2
B = matrix(c(1,1,1,0,1,1.2),nrow = 3,ncol = 2)
Seps = matrix(c(0.49,0,0,0,0.09,0,0,0,0.2),nrow = 3, ncol = 3)
mu = c(-1,0.5)
phi = c(0.99,0.9)
Seta = matrix(c(0.1,0,0,0.4),nrow = 2,ncol = 2)
TT = 100
N = 3
k = 2
res = vector(“list”,R)
data = vector(“list”,R)
vol = matrix(data = NA, nrow = TT,ncol =R)
X = vector()
for (i in 1:R){
x = simMSV(3,2,B,Seps,mu,phi,Seta,TT)
X = cbind(X,x)
data[[i]] = list(y = t(x[,1:N]),TT=TT, N = 3, k = 2)
vol[,i] = t(x[,3])
}
write(X, file = “True_data”)
BurnIn = 500
Sampling = 1000
thin = 1
nchains = 1
#MonteCarlo <- foreach(i = 1:R, .combine = cbind, .packages = ‘rstan’) %dopar% {
rstan_options(auto_write = TRUE)
options(mc.cores = parallel::detectCores())
fit <- stan(file = ‘MSV2.stan’, data = data[[i]], pars = c(‘B’,‘phi’,‘mu’,‘seta2’,‘seps2’,‘h’),
iter = Sampling,warmup = BurnIn,thin = thin, chains =nchains,cores = nchains,diagnostic_file = “diag”)
res = summary(fit,probs = c(0.025,0.5,0.975))$summary
MSV2.stan (1.9 KB)