All data are computer-generated with known parameters (seed 2026). They are not TAIEX data.
set.seed(2026)
N <- 2500; BURN <- 500; TT <- N + BURN; nu <- 6; TEST_N <- 500; EST_N <- N - TEST_N
tstd <- function(n) rt(n, nu) / sqrt(nu / (nu - 2))
f <- numeric(TT); fs2 <- rep(1, TT); fe <- numeric(TT); zf <- tstd(TT)
x <- numeric(TT); s2 <- rep(1.5, TT); e <- numeric(TT); z <- tstd(TT)
for (t in 2:TT) {
fs2[t] <- 0.02 + 0.08 * fe[t - 1]^2 + 0.90 * fs2[t - 1]
fe[t] <- sqrt(fs2[t]) * zf[t]; f[t] <- 0.04 + fe[t]
s2[t] <- 0.03 + (0.03 + 0.10 * (e[t - 1] < 0)) * e[t - 1]^2 + 0.90 * s2[t - 1]
e[t] <- sqrt(s2[t]) * z[t]
x[t] <- 0.03 + 0.05 * x[t - 1] + 0.15 * f[t - 1] + e[t]
}
k <- (BURN + 1):TT
r <- x[k]; fr <- f[k]; true_var <- s2[k]
price <- 10000 * exp(cumsum(r) / 100)
est <- r[1:EST_N]; rt_test <- tail(r, TEST_N)
pf <- function(p) if (p < 0.001) "< 0.001" else paste("=", round(p, 3))
stats_row <- function(v) {
m <- mean(v); s <- sd(v)
c(Mean = m, SD = s, Min = min(v), Max = max(v),
Skewness = mean((v - m)^3) / s^3, Kurtosis = mean((v - m)^4) / s^4,
JarqueBera = unname(jarque.bera.test(v)$statistic),
ADF = unname(adf.test(v)$statistic), KPSS = unname(kpss.test(v)$statistic))
}
kable(cbind(Domestic = stats_row(r), Foreign = stats_row(fr)), digits = 3,
caption = "Table 3. Descriptive statistics and stationarity tests")
| Domestic | Foreign | |
|---|---|---|
| Mean | 0.058 | 0.054 |
| SD | 1.041 | 0.879 |
| Min | -6.878 | -5.923 |
| Max | 6.037 | 4.786 |
| Skewness | -0.032 | -0.242 |
| Kurtosis | 6.133 | 6.333 |
| JarqueBera | 1026.327 | 1185.011 |
| ADF | -12.245 | -13.974 |
| KPSS | 0.116 | 0.034 |
Log price: ADF p = 0.598, KPSS p = 0.01.
par(mfrow = c(3, 1), mar = c(3, 4.5, 1, 1))
plot(price, type = "l", col = "navy", xlab = "", ylab = "Index level")
plot(r, type = "l", col = "grey30", xlab = "", ylab = "Log return (%)")
plot(r^2, type = "l", col = "firebrick", xlab = "Trading day", ylab = "Squared return")
Figure 2. Price, returns and squared returns
bic <- sapply(0:3, function(p) sapply(0:3, function(q)
tryCatch(AIC(arima(est, order = c(p, 0, q)), k = log(EST_N)), error = function(e) NA)))
dimnames(bic) <- list(paste0("q=", 0:3), paste0("p=", 0:3))
kable(bic, digits = 1, caption = "BIC of ARMA(p, q) models")
| p=0 | p=1 | p=2 | p=3 | |
|---|---|---|---|---|
| q=0 | 5801.7 | 5806.3 | 5813.9 | 5821.1 |
| q=1 | 5806.3 | 5813.8 | 5821.5 | 5828.7 |
| q=2 | 5813.9 | 5814.2 | 5821.0 | 5828.6 |
| q=3 | 5821.2 | 5828.8 | 5828.6 | 5833.0 |
lb10 <- Box.test(est, 10, "Ljung-Box")$p.value
lb20 <- Box.test(est, 20, "Ljung-Box")$p.value
e2 <- (est - mean(est))^2; X <- embed(e2, 11)
LM <- (EST_N - 10) * summary(lm(X[, 1] ~ X[, -1]))$r.squared
spec <- function(model, dist) ugarchspec(variance.model = list(model = model, garchOrder = c(1, 1)),
mean.model = list(armaOrder = c(1, 0)), distribution.model = dist)
specs <- list(`GARCH-N` = spec("sGARCH", "norm"), `GARCH-t` = spec("sGARCH", "std"),
`EGARCH-N` = spec("eGARCH", "norm"), `EGARCH-t` = spec("eGARCH", "std"),
`GJR-N` = spec("gjrGARCH", "norm"), `GJR-t` = spec("gjrGARCH", "std"))
tab4 <- t(sapply(specs, function(sp) {
fit <- ugarchfit(sp, est, solver = "hybrid"); cf <- coef(fit); p <- persistence(fit)
c(alpha = cf[["alpha1"]], gamma = if ("gamma1" %in% names(cf)) cf[["gamma1"]] else NA,
beta = cf[["beta1"]], nu = if ("shape" %in% names(cf)) cf[["shape"]] else NA,
Persist = p, HalfLife = log(0.5) / log(p), LogLik = likelihood(fit),
BIC = unname(infocriteria(fit)["Bayes", 1]) * EST_N)
}))
kable(tab4, digits = 3, caption = "Table 4. Volatility models with AR(1) mean")
| alpha | gamma | beta | nu | Persist | HalfLife | LogLik | BIC | |
|---|---|---|---|---|---|---|---|---|
| GARCH-N | 0.086 | NA | 0.892 | NA | 0.978 | 30.804 | -2715.784 | 5469.573 |
| GARCH-t | 0.078 | NA | 0.905 | 7.633 | 0.983 | 39.770 | -2685.448 | 5416.502 |
| EGARCH-N | -0.086 | 0.141 | 0.978 | NA | 0.978 | 31.465 | -2697.489 | 5440.583 |
| EGARCH-t | -0.076 | 0.135 | 0.982 | 8.546 | 0.982 | 38.436 | -2674.076 | 5401.358 |
| GJR-N | 0.009 | 0.107 | 0.925 | NA | 0.987 | 53.628 | -2692.425 | 5430.455 |
| GJR-t | 0.014 | 0.096 | 0.928 | 8.748 | 0.990 | 65.786 | -2670.222 | 5393.651 |
Z <- embed(cbind(r, fr)[1:EST_N, ], 2) # columns: r_t, f_t, r_t-1, f_t-1
g <- function(y, keep) anova(lm(y ~ Z[, keep]), lm(y ~ Z[, 3:4]))
g1 <- g(Z[, 1], 3); g2 <- g(Z[, 2], 4)
fc <- lapply(specs, function(sp) as.data.frame(ugarchroll(sp, r, n.ahead = 1, forecast.length = TEST_N,
refit.every = 20, refit.window = "moving", window.size = EST_N, solver = "hybrid")))
tv <- tail(true_var, TEST_N); px <- rt_test^2 + 1e-8
qlike <- function(a, h) a / h - log(a / h) - 1
dm <- function(l1, l2) { d <- l1 - l2; n <- length(d); lr <- var(d)
for (j in 1:5) lr <- lr + 2 * (1 - j / 6) * cov(d[-(1:j)], d[1:(n - j)])
s <- mean(d) / sqrt(lr / n); c(DM = s, p = 2 * (1 - pnorm(abs(s)))) }
h0 <- fc[["GARCH-N"]]$Sigma^2
tab5 <- t(sapply(fc, function(d) { h <- d$Sigma^2
c(mean(qlike(px, h)), dm(qlike(px, h0), qlike(px, h)),
mean(qlike(tv, h)), dm(qlike(tv, h0), qlike(tv, h))) }))
tab5["GARCH-N", c(2, 3, 5, 6)] <- NA
colnames(tab5) <- c("QLIKE proxy", "DM proxy", "p proxy", "QLIKE true", "DM true", "p true")
kable(tab5, digits = 4, caption = "Table 5. Forecast accuracy (DM > 0: model beats GARCH-N)")
| QLIKE proxy | DM proxy | p proxy | QLIKE true | DM true | p true | |
|---|---|---|---|---|---|---|
| GARCH-N | 1.4988 | NA | NA | 0.0185 | NA | NA |
| GARCH-t | 1.5003 | -0.5173 | 0.6049 | 0.0168 | 1.8411 | 0.0656 |
| EGARCH-N | 1.5293 | -1.6930 | 0.0905 | 0.0103 | 3.1950 | 0.0014 |
| EGARCH-t | 1.5294 | -1.7215 | 0.0852 | 0.0097 | 3.4273 | 0.0006 |
| GJR-N | 1.5226 | -1.2137 | 0.2249 | 0.0094 | 3.6830 | 0.0002 |
| GJR-t | 1.5222 | -1.2554 | 0.2093 | 0.0084 | 4.4004 | 0.0000 |
gjr <- fc[["GJR-t"]]
hm <- sapply(0:(TEST_N - 1), function(i) mean(r[(1 + i):(EST_N + i)]))
oos_r2 <- 100 * (1 - sum((rt_test - gjr$Mu)^2) / sum((rt_test - hm)^2))
Out-of-sample R² of the return forecast: -0.06%.
plot(abs(rt_test), type = "l", col = "grey75", xlab = "Test day", ylab = "Daily volatility (%)")
lines(sqrt(tv), lwd = 2); lines(gjr$Sigma, col = "firebrick", lwd = 1.5)
lines(fc[["GARCH-N"]]$Sigma, col = "steelblue", lty = 2)
legend("topleft", c("|return|", "True volatility", "GJR-t", "GARCH-N"), bty = "n", cex = 0.8,
col = c("grey75", "black", "firebrick", "steelblue"), lty = c(1, 1, 1, 2))
Figure 3. One-day-ahead volatility forecasts
var_q <- function(p) gjr$Mu + gjr$Sigma * qdist("std", p, mu = 0, sigma = 1, shape = gjr$Shape)
kup <- function(hit, p) { n <- length(hit); x <- sum(hit); ph <- max(x / n, 1e-12)
LR <- -2 * ((n - x) * log(1 - p) + x * log(p) - (n - x) * log(1 - ph) - x * log(ph))
c(Violations = x, Expected = n * p, `Kupiec p` = 1 - pchisq(LR, 1)) }
naive_q <- mean(est) + sd(est) * qnorm(0.05)
kable(rbind(`GJR-t 95%` = kup(rt_test < var_q(0.05), 0.05),
`GJR-t 99%` = kup(rt_test < var_q(0.01), 0.01),
`Constant volatility 95%` = kup(rt_test < naive_q, 0.05)),
digits = 3, caption = "VaR backtests")
| Violations | Expected | Kupiec p | |
|---|---|---|---|
| GJR-t 95% | 23 | 25 | 0.678 |
| GJR-t 99% | 8 | 5 | 0.215 |
| Constant volatility 95% | 24 | 25 | 0.836 |
plot(rt_test, type = "l", col = "grey50", xlab = "Test day", ylab = "Return (%)",
ylim = range(rt_test, var_q(0.01)))
lines(var_q(0.05), col = "orange", lwd = 1.5); lines(var_q(0.01), col = "firebrick", lwd = 1.5)
hit <- rt_test < var_q(0.01); points(which(hit), rt_test[hit], col = "firebrick", pch = 19)
legend("topleft", c("Return", "95% VaR", "99% VaR"), col = c("grey50", "orange", "firebrick"),
lty = 1, bty = "n", cex = 0.8)
Figure 4. GJR-t Value-at-Risk
rf <- 0.015 / 252; ret <- exp(rt_test / 100) - 1
W <- list(`Buy-and-hold` = rep(1, TEST_N),
`Volatility targeting` = pmin(15 / (gjr$Sigma * sqrt(252)), 1.5),
`Market timing` = as.numeric(gjr$Mu / 100 > rf))
strat <- function(w, bp) ret * w + (1 - w) * rf - abs(diff(c(0, w))) * bp / 1e4
perf <- function(w, bp) { rr <- strat(w, bp); cum <- cumprod(1 + rr)
c(Return = 100 * (tail(cum, 1)^(252 / TEST_N) - 1), Vol = 100 * sd(rr) * sqrt(252),
Sharpe = mean(rr - rf) / sd(rr) * sqrt(252), MaxDD = 100 * min(cum / cummax(cum) - 1),
Turnover = mean(abs(diff(w)))) }
tab6 <- t(sapply(W, perf, bp = 10))
tab6 <- cbind(tab6, `Sharpe 0bp` = sapply(W, function(w) perf(w, 0)[["Sharpe"]]),
`Sharpe 30bp` = sapply(W, function(w) perf(w, 30)[["Sharpe"]]))
kable(tab6, digits = 3, caption = "Table 6. Strategy performance (10 bp cost unless stated)")
| Return | Vol | Sharpe | MaxDD | Turnover | Sharpe 0bp | Sharpe 30bp | |
|---|---|---|---|---|---|---|---|
| Buy-and-hold | 15.936 | 17.257 | 0.857 | -30.637 | 0.000 | 0.860 | 0.850 |
| Volatility targeting | 28.231 | 16.022 | 1.539 | -19.164 | 0.034 | 1.597 | 1.423 |
| Market timing | 15.512 | 16.341 | 0.873 | -28.906 | 0.080 | 1.001 | 0.616 |
cv <- sapply(W, function(w) cumprod(1 + strat(w, 10)))
matplot(cv, type = "l", lty = 1, lwd = 1.5, col = c("grey30", "firebrick", "steelblue"),
xlab = "Test day", ylab = "Growth of 1 unit")
abline(h = 1, col = "grey")
legend("topleft", names(W), col = c("grey30", "firebrick", "steelblue"), lty = 1, bty = "n", cex = 0.8)
Figure 5. Cumulative value, 10 bp cost