Code for Stochvol example

#Load the data set
poundd<-read.table("StochVol.txt",header=T)

#Gaussian model
#we define the priors for the two hyperparameters and set starting values for the optimization procedure

model.g <- inla(ret~f(time,model="ar1",param=c(1,0.001,0,0.4),initial=c(4.8,5)),
                    family="stochvol",data=poundd)


# Student-t model
#here we choose to compute also the dic and the marginal likelihood
#moreover we ask the inla()function to return all the posterior marginals for the latent field
#and we 

model.t <- inla(ret~f(time,model="ar1",param=c(1,0.001,0,0.4),initial=c(2,3)),
           family="stochvol_t",data=poundd,control.compute=list(dic=T,mlik=T),
           control.predictor=list(return.marginals=T),control.inla=list(int.strategy="grid"))

#NIG model
model.nig <- inla(ret~f(time,model="ar1",param=c(1,0.001,0,0.4),initial=c(4.8,5)),
                    family="stochvol_nig",data=poundd)
Comments