Example 1: IBM returns

We will Ruey Tsay’s “Financial Time Series” webpage and upload IBM returns

#install.packages("fBasics")
#install.packages("timeSeries")
#install.packages("TSA")
#library("fBasics")
#library("timeSeries")
#library("TSA")

file = "http://faculty.chicagobooth.edu/ruey.tsay/teaching/fts3/m-ibm3dx2608.txt"
da = read.table(file,header=TRUE)
sibm=da[,2]
sibm2 = sibm^2
par(mfrow=c(1,2))
ts.plot(sibm,main="IBM returns")
ts.plot(sibm2,main="IBM squared returns")

acf(sibm,main="")
acf(sibm2,main="")

Ljung-Box test

Box.test(sibm,lag=30,type="Ljung")
## 
##  Box-Ljung test
## 
## data:  sibm
## X-squared = 38.241, df = 30, p-value = 0.1437
Box.test(sibm2,lag=30,type="Ljung")
## 
##  Box-Ljung test
## 
## data:  sibm2
## X-squared = 182.12, df = 30, p-value < 2.2e-16

Example 2: US real GNP

As an illustration, consider the quarterly growth rate of U.S. real gross national product (GNP), seasonally adjusted, from the second quarter of 1947 to the first quarter of 1991. Here we simply employ an AR(3) model for the data. Denoting the growth rate by \(r_t\) the fitted model is \[ r_t = 0.0047 + 0.348r_{t-1} + 0.179 r_{t-2} -0.142 r_{t-3} + a_t, \] with \({\hat \sigma}_a=0.0097\).

Alternatively, \[ r_t - 0.348r_{t-1} - 0.179 r_{t-2} + 0.142 r_{t-3} = 0.0047 + a_t, \] with the corresponding third-order difference equation \[ (1-0.348B-0.179B^2+0.142B^3)=0 \] or \[ (1+0.521B)(1-0.869B+0.274B^2)=0 \] The first factor \[ (1+0.521B) \] shows an exponentially decaying feature of the GNP.

Business cycles

The second factor \((1-0.869B+0.274B^2)\) confirms the existence of stochastic business cycles.
For an AR(2) model with a pair of complex characteristic roots, the average length of the stochastic cycles is \[ k = \frac{2\pi}{\cos^{-1}[\phi_1/(2\sqrt{-\phi_2})]} \] or \(k=10.62\) quarters, which is about 3 years.

R script and output

dgnp82 = "http://faculty.chicagobooth.edu/ruey.tsay/teaching/fts3/dgnp82.txt"
gnp=scan(file=dgnp82)

# To create a time-series object
gnp1=ts(gnp,frequency=4,start=c(1947,2))

par(mfrow=c(1,1))
plot(gnp1)
points(gnp1,pch="*")

Find the AR order

m1=ar(gnp,method="mle") 
m1$order 
## [1] 3
m2=arima(gnp,order=c(3,0,0))
m2
## 
## Call:
## arima(x = gnp, order = c(3, 0, 0))
## 
## Coefficients:
##          ar1     ar2      ar3  intercept
##       0.3480  0.1793  -0.1423     0.0077
## s.e.  0.0745  0.0778   0.0745     0.0012
## 
## sigma^2 estimated as 9.427e-05:  log likelihood = 565.84,  aic = -1121.68

In R, the intercept denotes the mean of the series.

(1-.348-.1793+.1423)*0.0077
## [1] 0.0047355

Residual standard error

sqrt(m2$sigma2) 
## [1] 0.009709322

Characteristic equation and solutions

p1=c(1,-m2$coef[1:3]) 
roots = polyroot(p1) 
roots
## [1]  1.590253+1.063882i -1.920152+0.000000i  1.590253-1.063882i

Compute the absolute values of the solutions

Mod(roots)
## [1] 1.913308 1.920152 1.913308

To compute average length of business cycles:

k=2*pi/acos(1.590253/1.913308)
k
## [1] 10.65638