#======================================================= #These code fragments illustrate the use of the positions() function to #select part of a timeseries, the used of acf(), the use of qqnorm(), and #some graphics tools. #They are taken from Z&W Pages 62, 67, and 71 where you will find futher context. #==================================================================== $Z&W Page 62 r.msft = getReturns(DowJones30[,"MSFT"],type="continuous") r.msft@title = "Daily returns on Microsoft" sample.2000 = (positions(r.msft) > timeDate("12/31/1999") & positions(r.msft) < timeDate("1/1/2001")) par(mfrow=c(2,2)) plot(r.msft[sample.2000],ylab="r.msft") r.acf = acf(r.msft[sample.2000]) hist(seriesData(r.msft)) qqnorm(seriesData(r.msft)) #Z&W Say: "The daily returns on Microsoft resemble a white noise process. The qqplot, #however, suggests that the tails of the return distribution are fatter #than the normal distribution. Notice that since the hist and qqnorm functions #do not have methods for “timeSeries” objects the extractor function #seriesData is required to extract the data frame from the data slot #of r.msft." #Z&W page 67 (Modified) uscn.id = 100*(lexrates.dat[,"USCNF"]- lexrates.dat[,"USCNS"]) colIds(uscn.id) = "USCNID" uscn.id@title = "US/CA 30 day interest rate differential" par(mfrow=c(2,1)) plot(uscn.id,reference.grid=F) abline(h=0) tmp = acf(uscn.id) plot(tmp$acf,type="h", xlab="Lag", ylab="ACF", main="ACF of USCD.id") abline(h=0) #Z&W say: "The interest rate differential is clearly persistent: autocorrelations are #significant at the 5% level up to 15 months. #Z&W page 71 (Modified) #Monthly Real Interest Rates #The “timeSeries” object varex.ts in the S+FinMetrics module contains #monthly data on real stock returns, real interest rates, inflation and #real output growth. colIds(varex.ts) smpl = (positions(varex.ts) > timeDate("12/31/1960")) irate.real = varex.ts[smpl,"RF.REAL"] par(mfrow=c(2,2)) acf.plot(acf(irate.real, plot=F)) plot(irate.real, main="Monthly Real Interest Rate") tmp = acf(irate.real, type="partial") #Z&W Say: The SACF and SPACF indicate that the real interest rate might be modeled #as an AR(2) or AR(3) process.