Model Fitting
Firstly, we need to simulate our model based on an initial parameter setup. As we can see below, the model with such parameter doesn’t fit well to the observed demeaned log return.
params_test <- c(
sigma_nu = exp(-3.5),
mu_h = -0.025,
phi = expit(4),
sigma_eta = exp(-0.07),
G_0 = 0,
H_0=0
)
We will use 3 level parameters to fit our model.
run_level <- 3
NADQ_Np <- switch(run_level, 50, 1e3, 2e3)
NADQ_Nmif <- switch(run_level, 5, 100, 200)
NADQ_Nreps_eval <- switch(run_level, 4, 10, 20)
NADQ_Nreps_local <- switch(run_level, 5, 20, 20)
NADQ_Nreps_global <- switch(run_level, 5, 20, 100)
## Loading required package: foreach
##
## Attaching package: 'foreach'
## The following objects are masked from 'package:purrr':
##
## accumulate, when
## Loading required package: iterators
## Loading required package: rngtools
## est se
## -1.824468e+03 9.647541e-02
NADQ_rw.sd_rp <- 0.02
NADQ_rw.sd_ivp <- 0.1
NADQ_cooling.fraction.50 <- 0.5
NADQ_rw.sd <- rw_sd(sigma_nu = 0.02,
mu_h = 0.02,
phi = 0.02,
sigma_eta = 0.02,
G_0 = ivp(0.1),
H_0 = ivp(0.1)
)
summary(r.if1$logLik,digits=5)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 3447 3460 3462 3466 3466 3509
The maximum likelihood is 3510. Through such local search, the optimal value of \(\sigma_\nu\)is roughly between (0, 0.005), the optimal value of \(\mu_h\) is around -10, the optimal value of \(\phi\)is roughly between (0.8, 0.85) and the optimal value of \(\sigma_eta\) is roughly between (0, 50).
By trying different starting point we will be able to find the global optimized parameters for our model.
pairs(~logLik+sigma_nu+mu_h+phi+sigma_eta,
data=subset(r.if1,logLik>max(logLik)-300))
Create a box to search the best parameters globally.
NADQ_box <- rbind(
sigma_nu=c(0.005,0.05),
mu_h =c(-1,0),
phi = c(0.95,0.99),
sigma_eta = c(0.5,1),
G_0 = c(-2,2),
H_0 = c(-1,1)
)
stew(file=paste0("box_eval_",run_level,".rda"),{
if.box <- foreach(i=1:NADQ_Nreps_global,
.packages='pomp',.combine=c, .export=c('if1', 'NADQ_box')) %dopar% {mif2(if1[[1]],
params=apply(NADQ_box,1,function(x)runif(1,x)))}
L.box <- foreach(i=1:NADQ_Nreps_global,
.packages='pomp',.combine=rbind,.export = c('NADQ_Nreps_eval', 'NADQ.filt', 'if', 'NADQ_Np')) %dopar% {
logmeanexp(replicate(NADQ_Nreps_eval, logLik(pfilter(
NADQ.filt,params=coef(if.box[[i]]),Np=NADQ_Np))),
se=TRUE)}
})
timing.box <- .system.time["elapsed"]
r.box <- data.frame(logLik=L.box[,1],logLik_se=L.box[,2],
t(sapply(if.box,coef)))
if(run_level>1) write.table(r.box,file="NADQ_params.csv",
append=TRUE,col.names=FALSE,row.names=FALSE)
summary(r.box$logLik,digits=5)
## Min. 1st Qu. Median Mean 3rd Qu. Max.
## 3446 3459 3463 3469 3471 3513
The iteration shows that the global maximum log likelihood is 3510.
From the figure shown above, we can see that \(\sigma_{\eta}\) converges at near 0.005; \(\sigma_{\nu}\) converges at near 0; \(G_0\) converges at near 0.5; \(\phi\) converges at near 0.8. Meanwhile, \(H_0\) and \(\mu_h\) do not converge.