setwd("~/teaching/time-series/ts2015spring/data") da=read.table("m-intc7308.txt",header=T) library(fGarch) intc=log(da[,2]+1) ###---------------------------------------------------------------------------- ### ARCH models ###---------------------------------------------------------------------------- ## The next command fits an ARCH(1) model. m1=garchFit(intc~garch(1,0),data=intc,trace=F) summary(m1) plot(m1) ## The next command fits an ARCH(1) model with Student-t dist. m3=garchFit(intc ~ garch(1,0),data=intc,trace=F, cond.dist='std') summary(m3) ## The next command fits an ARCH(1) model with skew Student-t dist. m4=garchFit(intc ~ garch(1,0),data=intc,cond.dist='sstd', trace=F) ###---------------------------------------------------------------------------- ### GARCH models ###---------------------------------------------------------------------------- ## The next command fits a GARCH(1,1) model m2=garchFit(intc ~ garch(1,1),data=intc,trace=F) summary(m2) ## Next, fit an ARMA(1,0)+GARCH(1,1) model with Gaussian noises. m5=garchFit(intc ~ arma(1,0)+garch(1,1),data=intc,trace=F) ## Example 3.3 (P. 134) library(fGarch) sp5=scan(file='sp500.dat') plot(sp5,type='l') m1=garchFit(~arma(3,0)+garch(1,1),data=sp5,trace=F) summary(m1) ## Below, fit a GARCH(1,1) model with Student-t distribution. m2=garchFit(~ garch(1,1),data=sp5,trace=F,cond.dist="std") summary(m2) ## Obtain standardized residuals. stresi=residuals(m2,standardize=T) plot(stresi,type='l') Box.test(stresi,10,type='Ljung') predict(m2,5) ## GARCH(1, 1)-M model ## http://faculty.chicagobooth.edu/ruey.tsay/teaching/bs41202/sp2013/garchM.R source("garchM.R") garchM(sp5) ## More GARCH models with "rugarch" package ## http://cran.at.r-project.org/web/packages/rugarch/vignettes/Introduction_to_the_rugarch_package.pdf library("rugarch") spec = ugarchspec() data(sp500ret) fit = ugarchfit(spec = spec, data = sp5) show(fit)