library("forecast")
library("rugarch") # ARCH/GARCH models
Loading required package: methods
Loading required package: parallel
Attaching package: 'rugarch'
The following object is masked from 'package:stats':
sigma
Daily GM Returns (September 1, 1987 - November 30, 1987)
data <- read.csv("http://ptrckprry.com/course/forecasting/data/gm.csv")
date <- as.Date(data$date)
time <- seq_along(date)
ret.GM <- data$GM # daily return
plot(date, ret.GM, xlab="Date", ylab="Daily Return", type="l", col=2)
crash <- which(date == "1987-10-19")
text(date[crash], ret.GM[crash], "Oct 19, 1987")
boxplot(ret.GM[time < crash - 1], ret.GM[time > crash + 1],
names=c(paste("To", strftime(date[crash - 1], "%b %d")),
paste("From", strftime(date[crash + 1], "%b %d"))),
ylab="Daily Return", col=2)
par(mfrow=c(1,2))
Acf(ret.GM)
Pacf(ret.GM)
plot(date, ret.GM^2, xlab="Date", ylab="Sq. Return", type="l", col=2)
par(mfrow=c(1,2))
Acf(ret.GM^2)
Pacf(ret.GM^2)
Simulated Series
set.seed(0)
n <- 100
t <- 1:n
# ARCH(1)
arch1.spec = ugarchspec(variance.model = list(garchOrder=c(1,0)),
mean.model = list(armaOrder=c(0,0)),
fixed.pars=list(mu = 0, omega=0.25, alpha1=0.5))
arch1.sim <- ugarchpath(arch1.spec, n.sim=n)
arch1 <- drop(arch1.sim@path$seriesSim)
# ARCH(2)
arch2.spec = ugarchspec(variance.model = list(garchOrder=c(2,0)),
mean.model = list(armaOrder=c(0,0)),
fixed.pars=list(mu = 0, omega=0.25, alpha1=0.6, alpha2=0.35))
arch2.sim <- ugarchpath(arch2.spec, n.sim=n)
arch2 <- drop(arch2.sim@path$seriesSim)
Corresponding Integrated Series
arch1.int <- cumsum(arch1)
arch2.int <- cumsum(arch2)
Time Series Plots
ARCH(1)
par(mfrow=c(1,2))
plot(t, arch1, type="l", col=4)
plot(t, arch1.int, type="l", col=4)
ARCH(2)
par(mfrow=c(1,2))
plot(t, arch2, type="l", col=5)
plot(t, arch2.int, type="l", col=5)
Raw Series
par(mfrow=c(1,2))
Acf(arch1)
Pacf(arch1)
Squares
par(mfrow=c(1,2))
Acf(arch1^2)
Pacf(arch1^2)
Raw Series
par(mfrow=c(1,2))
Acf(arch2)
Pacf(arch2)
Squares
par(mfrow=c(1,2))
Acf(arch2^2)
Pacf(arch2^2)