R
擬合 GARCH (1,1) - R 中具有協變量的模型
我在時間序列建模方面有一些經驗,比如簡單的 ARIMA 模型等等。現在我有一些表現出波動性聚類的數據,我想嘗試從對數據擬合 GARCH (1,1) 模型開始。
我有一個數據系列和一些我認為會影響它的變量。所以在基本的回歸術語中,它看起來像:
但是我完全不知道如何將其實現為 GARCH (1,1) - 模型?我已經查看了
rugarch
-package 和fGarch
-package inR
,但是除了可以在 Internet 上找到的示例之外,我還沒有做任何有意義的事情。
這是一個使用
rugarch
包和一些假數據的實現示例。該函數ugarchfit
允許在平均方程中包含外部回歸量(注意下面代碼中的 in 的使用external.regressors
)fit.spec
。為了修正符號,模型是
在哪裡和表示時間的協變量,以及對參數和創新過程的“通常”假設/要求. 示例中使用的參數值如下。
## Model parameters nb.period <- 1000 omega <- 0.00001 alpha <- 0.12 beta <- 0.87 lambda <- c(0.001, 0.4, 0.2)
下圖顯示了協變量系列和以及系列. 下面
R
提供了用於生成它們的代碼。## Dependencies library(rugarch) ## Generate some covariates set.seed(234) ext.reg.1 <- 0.01 * (sin(2*pi*(1:nb.period)/nb.period))/2 + rnorm(nb.period, 0, 0.0001) ext.reg.2 <- 0.05 * (sin(6*pi*(1:nb.period)/nb.period))/2 + rnorm(nb.period, 0, 0.001) ext.reg <- cbind(ext.reg.1, ext.reg.2) ## Generate some GARCH innovations sim.spec <- ugarchspec(variance.model = list(model = "sGARCH", garchOrder = c(1,1)), mean.model = list(armaOrder = c(0,0), include.mean = FALSE), distribution.model = "norm", fixed.pars = list(omega = omega, alpha1 = alpha, beta1 = beta)) path.sgarch <- ugarchpath(sim.spec, n.sim = nb.period, n.start = 1) epsilon <- as.vector(fitted(path.sgarch)) ## Create the time series y <- lambda[1] + lambda[2] * ext.reg[, 1] + lambda[3] * ext.reg[, 2] + epsilon ## Data visualization par(mfrow = c(3,1)) plot(ext.reg[, 1], type = "l", xlab = "Time", ylab = "Covariate 1") plot(ext.reg[, 2], type = "l", xlab = "Time", ylab = "Covariate 2") plot(y, type = "h", xlab = "Time") par(mfrow = c(1,1))
ugarchfit
如下進行擬合。## Fit fit.spec <- ugarchspec(variance.model = list(model = "sGARCH", garchOrder = c(1, 1)), mean.model = list(armaOrder = c(0, 0), include.mean = TRUE, external.regressors = ext.reg), distribution.model = "norm") fit <- ugarchfit(data = y, spec = fit.spec)
參數估計是
## Results review fit.val <- coef(fit) fit.sd <- diag(vcov(fit)) true.val <- c(lambda, omega, alpha, beta) fit.conf.lb <- fit.val + qnorm(0.025) * fit.sd fit.conf.ub <- fit.val + qnorm(0.975) * fit.sd > print(fit.val) # mu mxreg1 mxreg2 omega alpha1 beta1 #1.724885e-03 3.942020e-01 7.342743e-02 1.451739e-05 1.022208e-01 8.769060e-01 > print(fit.sd) #[1] 4.635344e-07 3.255819e-02 1.504019e-03 1.195897e-10 8.312088e-04 3.375684e-04
對應的真值為
> print(true.val) #[1] 0.00100 0.40000 0.20000 0.00001 0.12000 0.87000
下圖顯示了具有 95% 置信區間的參數估計值和真實值。下面
R
提供了用於生成它的代碼。plot(c(lambda, omega, alpha, beta), pch = 1, col = "red", ylim = range(c(fit.conf.lb, fit.conf.ub, true.val)), xlab = "", ylab = "", axes = FALSE) box(); axis(1, at = 1:length(fit.val), labels = names(fit.val)); axis(2) points(coef(fit), col = "blue", pch = 4) for (i in 1:length(fit.val)) { lines(c(i,i), c(fit.conf.lb[i], fit.conf.ub[i])) } legend( "topleft", legend = c("true value", "estimate", "confidence interval"), col = c("red", "blue", 1), pch = c(1, 4, NA), lty = c(NA, NA, 1), inset = 0.01)