qmle <- function(r, start = c(mean(r), 0.05, 0.10, 0.85)) {
f <- optim(start, nll, r = r, control = list(maxit = 5000, reltol = 1e-12))
f <- optim(f$par, nll, r = r, method = "BFGS", control = list(reltol = 1e-12))
th <- f$par
H <- optimHess(th, nll, r = r) # numerical T * J-hat
S <- sapply(1:4, function(k) { h <- rep(0, 4); h[k] <- 1e-5
(ell(th + h, r) - ell(th - h, r)) / 2e-5 }) # T x 4 numerical scores
Hi <- solve(H)
out <- list(theta = th, se_hess = sqrt(diag(Hi)),
se_bw = sqrt(diag(Hi %*% crossprod(S) %*% Hi)))
lapply(out, setNames, c("mu", "omega", "alpha", "beta"))
}
set.seed(2026)
n <- 3000; th0 <- c(0.05, 0.05, 0.10, 0.85)
eta <- rt(n, df = 5) / sqrt(5 / 3) # Student-t(5), scaled to variance 1
r_sim <- numeric(n); s2 <- th0[2] / (1 - th0[3] - th0[4]); e_prev <- 0
for (t in 1:n) {
s2 <- th0[2] + th0[3] * e_prev^2 + th0[4] * s2
e_prev <- sqrt(s2) * eta[t]; r_sim[t] <- th0[1] + e_prev
}
fit_sim <- qmle(r_sim)
round(rbind(truth = th0, estimate = fit_sim$theta,
se_Hessian = fit_sim$se_hess, se_BW = fit_sim$se_bw), 4)