Professional Documents
Culture Documents
rt = 0.005 + 0.2rt1 + at
1
U.S. quarterly real GNP growth rate: 1947.II to 1991.I
0.04
0.03
0.02
0.01
gnp
0.00
0.01
0.02
Time
This model also has two parameters ( and 1). It explicitly uses
the mean of the series. It is less commonly used in the literature,
but is the model representation used in R.
a2
5. Variance: Var(rt) = 121
.
2
10
8
unrate
6
4
Time
Figure 2: U.S. monthly unemployment rate (total civilian, 16 and older) from January 1948
to February 2011
3
7. Forecast (minimum squared error): Suppose the forecast origin
is n. For simplicity, we shall use the model representation in (1)
and write xt = rt . The model then becomes xt = 1xt1 +at.
Note that forecast of rt is simply the forecast of xt plus .
xn(`) = `1xn,
In particular, as ` ,
5
that the magnitude of the forecast becomes half of that of the forecast
origin. For an AR(1) model, this mean
1
xn(k) = xn.
2
Thus, k1 xn = 12 xn. Consequently, the half-life of the AR(1) model
ln(0.5)
is k = ln(|1 |) . For example, if 1 = 0.5, the k = 1. If 1 = 0.9, then
k 6.58.
AR(2) model:
(1 1B 2B 2)rt = 0 + at.
` = 1`1 + 2`1, ` 2.
1. y1=arima.sim(model=list(ar=c(1.3,-.4)),1000)
2. y2=arima.sim(model=list(ar=c(.8,-.7)),1000)
Check the ACF and PACF of the above two simulated series.
Building an AR model
Order specification
7
2. Akaike information criterion
2`
AIC(`) = ln(`2) + ,
T
for an AR(`) model, where `2 is the MLE of residual vari-
ance.
Find the AR order with minimum AIC for ` [0, , P ].
3. BIC criterion:
` ln(T )
BIC(`) = ln(`2) + .
T
Needs a constant term? Check the sample mean.
Model checking:
1. Residual: obs minus the fit, i.e. 1-step ahead forecast errors
at each time point.
2. Residual should be close to white noise if the model is ade-
quate. Use Ljung-Box statistics of residuals, but degrees of
freedom is m g, where g is the number of AR coefficients
used in the model.
8
Series : dgnp
0.3 0.2
Partial ACF
0.1 0.0
0.1
0 5 10 15 20
Lag
Box-Ljung test
data: x
X-squared = 43.2345, df = 10, p-value = 4.515e-06
Call:
ar(x = x, method = "mle")
Coefficients:
1 2 3 % An AR(3) is specified.
0.3480 0.1793 -0.1423
9
Order selected 3 sigma^2 estimated as 9.427e-05
> names(m1)
[1] "order" "ar" "var.pred" "x.mean" "aic"
[6] "n.used" "order.max" "partialacf" "resid" "method"
[11] "series" "frequency" "call" "asy.var.coef"
Box-Ljung test
data: m1$resid
X-squared = 7.0808, df = 10, p-value = 0.7178
Coefficients:
ar1 ar2 ar3 intercept % Fitted model is
0.3480 0.1793 -0.1423 0.0077 % y(t)=0.348y(t-1)+0.179y(t-2)
s.e. 0.0745 0.0778 0.0745 0.0012 % -0.142y(t-3)+a(t),
% where y(t) = x(t)-0.0077
> Box.test(m2$residuals,lag=10,type=Ljung)
Box-Ljung test
data: m2$residuals
X-squared = 7.0169, df = 10, p-value = 0.7239
>
> p1=c(1,-m2$coef[1:3]) % Further analysis of the fitted model.
10
> roots=polyroot(p1)
> roots
[1] 1.590253+1.063882e+00i -1.920152-3.530887e-17i 1.590253-1.063882e+00i
> Mod(roots)
[1] 1.913308 1.920152 1.913308
> k=2*pi/acos(1.590253/1.913308)
> k
[1] 10.65638
$se
Time Series:
Start = 177
End = 184
Frequency = 1
[1] 0.009709322 0.010280510 0.010686305 0.010688994
[5] 0.010689733 0.010694771 0.010695511 0.010696190
11
[1] 758 4
> acf(rate)
> acf(diff(rate))
> par(mfcol=c(2,1))
> acf(rate)
> acf(diff(rate))
> m1=ar(diff(rate),method="mle")
> m1$order
[1] 12
> m1
Call:
ar(x = diff(rate), method = "mle")
Coefficients:
1 2 3 4 5 6 7 8
0.0172 0.2229 0.1523 0.0943 0.1309 -0.0022 -0.0287 0.0114
9 10 11 12
-0.0080 -0.1072 0.0300 -0.1121
data: diff(rate)
t = 0.9252, df = 756, p-value = 0.3551
alternative hypothesis: true mean is not equal to 0
95 percent confidence interval:
-0.008150105 0.022681148
sample estimates:
mean of x
0.007265522
> m1=arima(rate,order=c(12,1,0))
> m1
Call:
arima(x = rate, order = c(12, 1, 0))
Coefficients:
ar1 ar2 ar3 ar4 ar5 ar6 ar7 ar8 ar9
0.0176 0.2233 0.1526 0.0946 0.1311 -0.0021 -0.0286 0.0115 -0.0079
s.e. 0.0362 0.0364 0.0372 0.0378 0.0380 0.0382 0.0383 0.0380 0.0379
ar10 ar11 ar12
-0.1069 0.0304 -0.1117
s.e. 0.0374 0.0366 0.0366
12
sigma^2 estimated as 0.03867: log likelihood = 156.67, aic = -287.34
> tsdiag(m1,gof=24)
> m2=arima(y,order=c(2,1,1),seasonal=list(order=c(1,0,1),period=12))
Error in NCOL(x) : object y not found
> m2=arima(rate,order=c(2,1,1),seasonal=list(order=c(1,0,1),period=12))
> m2
Call:
arima(x=rate,order=c(2,1,1),seasonal=list(order=c(1,0,1),period=12))
Coefficients:
ar1 ar2 ma1 sar1 sma1
0.5868 0.2385 -0.5826 0.5717 -0.8269
s.e. 0.0628 0.0395 0.0582 0.0708 0.0512
13
Moving-average (MA) model
Model with finite memory!
Some daily stock returns have minor serial correlations and can be
modeled as MA or AR models.
MA(1) model
Form: rt = + at at1
Autocovariance:
14
3. Multi-step ahead: rn(`) = for ` > 1.
Thus, for an MA(1) model, the multi-step ahead forecasts
are just the mean of the series. Why? Because the model
has memory of 1 time period.
4. Multi-step ahead forecast error:
en(`) = an+` an+`1
Invertibility:
MA(2) model
Form: rt = + at 1at1 2at2. or
rt = + (1 1B 2B 2)at.
15
Stationary with E(rt) = .
Building an MA model
Specification: Use sample ACF
Sample ACFs are all small after lag q for an MA(q) series. (See
test of ACF.)
rt = + at + 1at1 + + q atq ,
16
instead of the usual minus sign in . Consequently, care needs to be
exercised in writing down a fitted MA parameter in R. For instance,
an estimate 1 = 0.5 of an MA(1) in R indicates the model is
rt = at 0.5at1.
Example:Daily log return of the value-weighted index
R demonstration
> setwd("C:/Users/rst/teaching/bs41202/sp2011")
> library(fBasics)
> da=read.table("d-ibmvwew6202.txt")
> dim(da)
[1] 10194 4
Call:
arima(x = vw, order = c(0, 0, 1))
Coefficients:
ma1 intercept
0.1465 0.0396 % The model is vw(t) = 0.0396+a(t)+0.1465a(t-1).
s.e. 0.0099 0.0100
$se
Time Series:
Start = 10195
End = 10199
Frequency = 1
[1] 0.8823290 0.8917523 0.8917523 0.8917523 0.8917523
17
Mixed ARMA model: A compact form for flexible models.
Focus on the ARMA(1,1) model for
1. simplicity
rt = 1rt1 + 0 + at 1at1.
1 = 1 [1a2/Var(rt)] 6= 1.
rt = 0 + at + 1rt1 + 2rt2 +
rt = + at + 1at1 + 2at2 +
19
For a `-step ahead forecast, the forecast error is
Var[en(`)] = (1 + 12 + + `1
2
)a2.
Unit-root Nonstationarity
Random walk
Form pt = pt1 + at
i=0 i=0
20
Nonstationary
Strong memory
differencing
MA model: mean
Continuously compounded?
Unit-root test
Let pt be the log price of an asset. To test that pt is not predictable
(i.e. has a unit root), two models are commonly employed:
pt = 1pt1 + et
pt = 0 + 1pt1 + et.
i=1
The t-ratio of the OLS estimate of is the ADF unit-root test statis-
tic. Again, the statistic has a non-standard limiting distribution.
22
Example: Consider the log series of U.S. quaterly real GDP se-
ries from 1947.I to 2009.IV. (data from Federal Reserve Bank of St.
Louis). See q-gdpc96.txt on the course web.
R demonstration
> library(fUnitRoots)
> help(UnitrootTests) % See the tests available
>da=read.table(q-gdpc96.txt,header=T)
>gdp=log(da[,4])
Title:
Augmented Dickey-Fuller Test
Test Results:
PARAMETER:
Lag Order: 4
STATISTIC:
Dickey-Fuller: -1.7433
P VALUE:
0.4076 # cannot reject the null hypothesis of a unit root.
Call:
ar(x = x)
Coefficients:
1 2 3
0.3429 0.1238 -0.1226
23
constant is used.
The subcommand include.mean=T in the arima command.
Coefficients:
ar1 ar2 ar3 ar4 ar5 ar6 ar7 ar8 ar9
0.0716 0.1754 0.1455 0.1152 0.1152 0.0042 -0.0264 0.0143 -0.0132
s.e. 0.0366 0.0374 0.0367 0.0375 0.0377 0.0379 0.0378 0.0376 0.0374
ar10 ar11 ar12 outlier23
-0.1099 0.0474 -0.1343 -0.810
s.e. 0.0369 0.0365 0.0366 0.135
Call:
arima(x = rate, order = c(12, 1, 0), xreg = data.frame(outlier22, outlier23))
Coefficients:
ar1 ar2 ar3 ar4 ar5 ar6 ar7 ar8 ar9
0.1037 0.2033 0.1238 0.1043 0.0763 0.0308 -0.0179 -0.0045 -0.0141
24
s.e. 0.0362 0.0365 0.0372 0.0378 0.0383 0.0382 0.0380 0.0380 0.0377
ar10 ar11 ar12 outlier22 outlier23
-0.0939 0.0631 -0.1351 1.1735 -0.2840
s.e. 0.0374 0.0366 0.0366 0.1388 0.1374
Coefficients:
ar1 ar2 ma1 sar1 sma1 outlier22
0.6871 0.1524 -0.5902 0.5457 -0.8152 1.2994
s.e. 0.0700 0.0443 0.0637 0.0724 0.0518 0.1175
Coefficients:
ar1 ar2 ma1 ma2 sar1 sma1 outlier22
1.5913 -0.6824 -1.5017 0.6946 0.5702 -0.8289 1.3103
s.e. 0.1058 0.1033 0.1035 0.0886 0.0700 0.0483 0.1171
25