Previous | Next  

ARCH-GARCH Models

Plot Return
n <- length(Y)#1: set length of vector Y
ret <- log(Y[-1]/Y[-n])#2: calculate log return
colors = c("red", "yellow", "green", "violet", "orange", "blue", "pink", "cyan")#3: define colors
barplot(ret, col=colors, main="Return", xlab="Y", ylab="Return (%)")#4: plot the return

ARCH-GARCH Using fGarch Package
n <- length(Y)#1: set length of vector Y
ret <- log(Y[-1]/Y[-n])#2: calculate log return
library("fGarch")#3: load the "fGarch" R package
#X.arch <- garchFit(formula=~garch(1,0), data=ret, trace=FALSE)#4: model ARCH(1)
X.garch <- garchFit(formula=~garch(1,1), data=ret, trace=FALSE)#5: model GARCH(1,1)
#summary(X.arch)#6: summary of ARCH(1)
summary(X.garch)#7: summary of GARCH(1,1)
barplot(ret)#8: plot return
#barplot(X.garch@residuals)#9: plot residuals

ARCH-GARCH Using TSeries Package
n <- length(Y)#1: set length of vector Y
ret <- log(Y[-1]/Y[-n])#2: calculate log return
library("tseries")#3: load the "tseries" R package
X.arch <- garch(ret, order=c(1,0))#4: model ARCH(1)
X.garch <- garch(ret, order=c(1,1))#5: model GARCH(1,1)
summary(X.arch)#6: summary of ARCH(1)
summary(X.garch)#7: summary of GARCH(1,1)
plot(X.garch) #8: plot GARCH model

Previous | Next