Các mô hình GARCH trong R
Kris Boudt
Professor of finance and econometrics

ugarchfilter() để phân tích động lực trung bình và biến động gần đâyugarchforecast() áp dụng cho đối tượng ugarchspec (thay vì ugarchfit()) để dự báo trung bình và biến động tương laimsftret: lợi nhuận ngày 1999–2017.Ước lượng mô hình tốt nhất dùng msftret có tại cuối 2010:
# Specify AR(1)-GJR GARCH model with skewed student t distribution
garchspec <- ugarchspec(mean.model = list(armaOrder = c(1,0)),
variance.model = list(model = "gjrGARCH"), distribution.model = "sstd")
# Estimate the model
garchfit <- ugarchfit(data = msftret["/2010-12"], spec = garchspec)
Đặt progarchspec là đặc tả dùng trong vận hành và dùng lệnh setfixed(progarchspec) <- as.list(coef(garchfit)):
progarchspec <- garchspec
setfixed(progarchspec) <- as.list(coef(garchfit))
Dùng hàm ugarchfilter():
garchfilter <- ugarchfilter(data = msftret, spec = progarchspec)
plot(sigma(garchfilter))

garchforecast <- ugarchforecast(data = msftret,
fitORspec = progarchspec,
n.ahead = 10) # Make predictions for next ten days
cbind(fitted(garchforecast), sigma(garchforecast))
2017-12-29 2017-12-29
T+1 0.0004781733 0.01124870
T+2 0.0003610470 0.01132550
T+3 0.0003663683 0.01140171
T+4 0.0003661265 0.01147733
T+5 0.0003661375 0.01155238
T+6 0.0003661370 0.01162688
T+7 0.0003661371 0.01170083
T+8 0.0003661371 0.01177424
T+9 0.0003661371 0.01184712
T+10 0.0003661371 0.01191948
Thay vì áp dụng mô hình đầy đủ để phân tích lợi nhuận quan sát, có thể dùng để mô phỏng log-lợi nhuận nhân tạo:
$$ r_{t} = \log(P_{t}) - \log(P_{t-1}) $$
Hữu ích để đánh giá tính ngẫu nhiên của lợi nhuận tương lai và tác động lên giá, vì giá tương lai bằng:
$$ P_{t + h} = P_{t} \exp(r_{t + 1} + r_{t + 2} + \ldots + r_{t + h}) $$
Dùng log-lợi nhuận trong ước lượng
# Compute log returns
msftlogret <- diff(log(MSFTprice))[-1]
Ước lượng mô hình và gán tham số cho mô hình mô phỏng
garchspec <- ugarchspec(mean.model = list(armaOrder = c(1, 0)),
variance.model = list(model = "gjrGARCH"),
distribution.model = "sstd")
# Estimate the model
garchfit <- ugarchfit(data = msftlogret, spec = garchspec)
# Set that estimated model as the model to be used in the simulation
simgarchspec <- garchspec
setfixed(simgarchspec) <- as.list(coef(garchfit))
Mô phỏng với hàm ugarchpath() cần chọn:
spec: mô hình GARCH xác định đầy đủm.sim: số chuỗi thời gian lợi nhuận mô phỏng cần cón.sim: số quan sát trong mỗi chuỗi mô phỏng (ví dụ 252)rseed: số để cố định hạt giống sinh ngẫu nhiên (cần cho tái lập)simgarch <- ugarchpath(spec = simgarchspec, m.sim = 4,
n.sim = 10 * 252, rseed = 12345)
Hàm fitted() cho lợi nhuận mô phỏng:
simret <- fitted(simgarch)
plot.zoo(simret)

plot.zoo(sigma(simgarch))

Vẽ 4 mô phỏng giá cổ phiếu trong 10 năm, giá đầu kỳ đặt bằng 1:
simprices <- exp(apply(simret, 2, "cumsum"))
matplot(simprices, type = "l", lwd = 3)

Các mô hình GARCH trong R