Model GARCH di R
Kris Boudt
Professor of finance and econometrics

ugarchfilter() untuk menganalisis dinamika mean dan volatilitas terbaruugarchforecast() pada objek ugarchspec (alih-alih ugarchfit()) untuk memprediksi mean dan volatilitas mendatangmsftret: return harian 1999–2017.Cocokkan model terbaik menggunakan msftret hingga akhir 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)
Definisikan progarchspec sebagai spesifikasi untuk produksi dan gunakan instruksi setfixed(progarchspec) <- as.list(coef(garchfit)):
progarchspec <- garchspec
setfixed(progarchspec) <- as.list(coef(garchfit))
Gunakan fungsi 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
Alih-alih menerapkan model lengkap untuk menganalisis return teramati, Anda dapat mensimulasikan log-return buatan:
$$ r_{t} = \log(P_{t}) - \log(P_{t-1}) $$
Berguna untuk menilai keacakan return masa depan dan dampaknya pada harga, karena harga di masa depan adalah:
$$ P_{t + h} = P_{t} \exp(r_{t + 1} + r_{t + 2} + \ldots + r_{t + h}) $$
Gunakan log-return dalam estimasi
# Compute log returns
msftlogret <- diff(log(MSFTprice))[-1]
Estimasi model dan tetapkan parameter ke model simulasi
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))
Simulasi dengan fungsi ugarchpath() memerlukan pilihan:
spec: model GARCH yang terdefinisi penuhm.sim: jumlah deret waktu return tersimulasikan yang diinginkann.sim: jumlah observasi per deret waktu simulasi (mis. 252)rseed: angka untuk mengatur seed pembangkitan simulasi (untuk reproduksibilitas)simgarch <- ugarchpath(spec = simgarchspec, m.sim = 4,
n.sim = 10 * 252, rseed = 12345)
Metode fitted() memberikan return tersimulasikan:
simret <- fitted(simgarch)
plot.zoo(simret)

plot.zoo(sigma(simgarch))

Memplot 4 simulasi harga saham selama 10 tahun, dengan harga awal 1:
simprices <- exp(apply(simret, 2, "cumsum"))
matplot(simprices, type = "l", lwd = 3)

Model GARCH di R