# Uploading package from Shumway and Stoffer's book install.packages("astsa") library(astsa) # Simple plots of Jonshon & Johnson returns plot(jj, type="o", ylab="Quarterly Earnings per Share") plot(diff(jj), type="o", ylab="Quarterly Earnings per Share") # All data sets available in the package data() par(mfrow=c(2,3)) ts.plot(nyse) ts.plot(salmon) ts.plot(chicken) ts.plot(UnempRate) ts.plot(birth) ts.plot(flu) # Playing around with DJIA - ACF y = djia[,4] ts.plot(y) y = diff(log(y)) par(mfrow=c(2,2)) ts.plot(y) acf(y) ts.plot(y^2) acf(y^2) # Box-Ljung test for DJIA and DJIA^2 Box.test(y,lag=30,type="Ljung") Box.test(y^2,lag=30,type="Ljung") # ACF for Canadian lynx and air passengers data par(mfrow=c(2,2)) plot(Lynx) acf(Lynx) plot(diff(log(AirPassengers))) acf(diff(log(AirPassengers))) # White noise and AR(1) processes set.seed(12435) e = rnorm(100,0,1) y = rep(0,100) for (t in 2:100) y[t] = 0.98*y[t-1]+e[t] par(mfrow=c(2,2)) ts.plot(e) acf(e) ts.plot(y) acf(y) # Stationary region for AR(2) processes # ------------------------------------- phi1 <- seq(from = -2.5, to = 2.5, length = 51) plot(phi1,1+phi1,lty="dashed",type="l", xlab="",ylab="",cex.axis=.8,ylim=c(-1.5,1.5)) abline(a = -1, b = 0, lty="dashed") abline(a = 1, b = -1, lty="dashed") title(ylab=expression(phi[2]),xlab=expression(phi[1]),cex.lab=.8) polygon(x = phi1[6:46], y = 1-abs(phi1[6:46]), col="gray") lines(phi1,-phi1^2/4) text(0,-.5,expression(phi[2]1-phi[1]),cex=.7) text(-1.75,.5,expression(phi[2]>1+phi[1]),cex=.7) points(1.75,-0.8,pch=16,col=1) points(0.9,0.05,pch=16,col=2)