# longMemory.ssc Examples used in Long Memory Time Series Modeling # Chapter # Updated for FM 3.0: July, 2007 # author: Eric Zivot # created: April 20, 2002 # updated: April 20, 2002 # updated: July 6, 2007 # # example using sp500 absolute returns tmp = acf(abs(sp500[,1]),lag=200) sp500.ar = ar(abs(sp500)) sp500.ar\$order tmp.mod = list(ar=as.vector(sp500.ar\$ar),sigma2=1,d=0) ar.acf = acf.FARIMA(tmp.mod, lag.max=200) lines(ar.acf\$lags,ar.acf\$acf/ar.acf\$acf[1]) # theoretical acf of fractionally integrated process d.pos = acf.FARIMA(list(d=0.3, sigma2=2), 100) d.pos\$acf = d.pos\$acf/d.pos\$acf[1] d.neg = acf.FARIMA(list(d=-0.3, sigma2=1), 100) d.neg\$acf = d.neg\$acf/d.neg\$acf[1] par(mfrow=c(2,1)) plot(d.pos\$lags, d.pos\$acf, type="h", main="d = 0.3", xlab="lags", ylab="ACF") plot(d.neg\$lags, d.neg\$acf, type="h", main="d = 0.3", xlab="lags", ylab="ACF") par(mfrow=c(1,1)) # R/S statistic args(rosTest) # modified R/S test rosTest(abs(sp500)) # unmodified R/S test rosTest(abs(sp500),bandwidth=0) # GPH test args(gphTest) gph.sp500 = gphTest(abs(sp500),taper=0) class(gph.sp500) names(gph.sp500) gph.sp500 gph.sp500\$std.err gph.sp500\$d - 2*gph.sp500\$std.err gph.sp500\$d + 2*gph.sp500\$std.err args(d.ros) d.ros(abs(sp500),minK=50,k.ratio=2,minNumPoints=10, output="H",plot=T) d.ros(abs(sp500),minK=50,k.ratio=2,minNumPoints=10, output="d",plot=F) 0.8393482-0.5 # fit with L1 regression d.ros(abs(sp500),minK=50,k.ratio=2,minNumPoints=10, output="H",method="l1",plot=F) # periodogram method args(d.pgram) d.pgram(abs(sp500),taper=0, output="H") 0.8741311 - 0.5 # EZ: 7/6/2007 # note: potential bug in d.pgram when method="l1". x variable # in l1 fit is on log scale and not log10 scale # Also, regression lines are not drawn on plots par(mfrow=c(1,2)) H.ls = d.pgram(abs(sp500),taper=0, output="d",plot=T) H.l1 = d.pgram(abs(sp500),taper=0, output="d",method="l1",plot=T) par(mfrow=c(1,1)) H.ls H.l1 # whittle's method args(d.whittle) d.whittle(abs(sp500),taper=0) # FARIMA models # construct daily volatility series ndx.vol = TA.garmanKlass(ndx.dat[,"Open"],ndx.dat[,"High"], ndx.dat[,"Low"],ndx.dat[,"Close"]) par(mfrow=c(2,1)) plot(ndx.vol,reference.grid=F) tmp=acf(log(ndx.vol),lag=200) par(mfrow=c(1,1)) args(FARIMA) # estimate FARIMA model with p=q=0) ndx.d = FARIMA(log(ndx.vol),p=0,q=0) class(ndx.d) names(ndx.d) summary(ndx.d) ndx.d\$m summary(ndx.d) coef(ndx.d) sqrt(vcov(ndx.d)) # estimate FARIMA model by minimizing BIC ndx.bic = FARIMA(log(ndx.vol),p.range=c(0,2), q.range=c(0,2), mmax=0) ndx.bic summary(ndx.bic) # compute confidence intervals ndx.bic\$CI plot(ndx.bic, ask=F) # estimate FARIMA by minimizing BIC and estimating m ndx.bic2 = FARIMA(log(ndx.vol),p.range=c(0,2), q.range=c(0,2), mmax=1) ndx.bic2\$m summary(ndx.bic2) # there appears to be canceling roots! ndx.bic2 = FARIMA(log(ndx.vol),p=1,q=1, mmax=1) summary(ndx.bic2) # estimate SEMIFAR model args(SEMIFAR) ndx.semi = SEMIFAR(log(ndx.vol),p.range=c(0,2),trace=F) class(ndx.semi) names(ndx.semi) ndx.semi summary(ndx.semi) plot(ndx.semi, which=c(1,2,5)) # choose options 2,3 and 6. # FIGARCH dell.garch = garch(dell.s~1, ~garch(1,1)) dell.egarch = garch(dell.s~1, ~egarch(1,1),leverage=T) dell.fgarch = fgarch(dell.s~1, ~figarch(1,1)) oldClass(dell.fgarch) summary(dell.fgarch) dell.fegarch = fgarch(dell.s~1, ~fiegarch(1,1),leverage=T) dell.fegarch summary(dell.fegarch) dell.comp = compare.mgarch(dell.garch,dell.egarch, dell.fgarch,dell.fegarch) dell.comp plot(dell.comp) plot(dell.comp,qq=T)