Professional Documents
Culture Documents
Time Series: Chapter 5 - Forecasting
Time Series: Chapter 5 - Forecasting
Time Series: Chapter 5 - Forecasting
Chapter 5 - Forecasting
1 Introduction
3 Holt-Winters Approach
n def
Ybn+h ≡ Yn+h = E(Yn+h |Yn , Yn−1 , . . . , Y1 )
n
Yn+h is a function of the observation (Y1 , . . . , Yn ) used for prediction
Yn+h is the unknown future value
Forecast error
n
en (h) = Yn+h − Yn+h
Variance of forecast error
h i
n n
Pn+h = Var(en (h)|Yn , . . . , Y1 ) = E (Yn+h − Yn+h )2 |Yn , . . . , Y1
1 Introduction
3 Holt-Winters Approach
1 Introduction
3 Holt-Winters Approach
n
p
iii) 95% Prediction interval: Yn+h ± 1.96 Var(en (h)|Yn , . . . , Y1 )
Forecasting (Time Series) Chapter 5 7 / 36
...
Box and Jenkins Approach: Example 1 (General Version)
Example : AR(1) : Yt = αYt−1 + Zt , Zt ∼ N (0, σ 2 )
Causal Representation: Yt = ∞ i
P
i=0 α Zt−i .
i)
ii) Forecast:
∞
X
n
Yn+h = E(Yn+h |Yn , Yn−1 , . . . , Y1 ) = E( αi Zn+h−i |Yn , . . . , Y1 )
i=0
∞
X ∞
X
= αi Zn+h−i = αh αi Zn−i = αh Yn .
i=h i=0
n Ph−1 i
iii) Forecast error: en (h) = Yn+h − Yn+h = i=0 α Zn+h−i
iv) Variance of forecast error:
h−1
n
X 1 − α2h
Pn+h = Var(en (h)) = σ 2 α2i = σ 2 .
i=0
1 − α2
q
1−α2h
v) 95% Prediction interval: αh Yn ± 1.96σ 1−α2
Forecasting (Time Series) Chapter 5 8 / 36
...
Box and Jenkins Approach: Example 1 (Recursive Version)
Example : AR(1) : Yt = αYt−1 + Zt , Zt ∼ N (0, σ 2 )
i) 1-Step forecast
n
Yn+1 = E(Yn+1 |Yn , . . . , Y1 ) = E(αYn + Zn+1 |Yn , . . . , Y1 ) = αYn
n
en (1) = Yn+1 − Yn+1 = Zn+1
n 2
Pn+1 = Var(en (1)|Yn , . . . Y1 ) = E(Zn+1 ) = σ2
ii) 2-Step forecast
n n
Yn+2 = E(αYn+1 + Zn+2 |Yn , . . . , Y1 ) = αYn+1 = α2 Yn
n n
en (2) = Yn+2 − Yn+2 = α(Yn+1 − Yn+1 ) + Zn+2 = αZn+1 + Zn+2
n
Pn+2 = Var(en (2)|Yn , . . . Y1 ) = σ 2 (1 + α2 )
1 Introduction
3 Holt-Winters Approach
1 Introduction
3 Holt-Winters Approach
Prediction: (n + h − dk ≤ n)
n
Yn+h = `n + hbn + sn+h−dk
Other choices: Pn
|Yt −Ytt−1 |
MASE (mean absolute scaled error): Pt=d+1
n
|Yt −Yt−d |
t=d+1
1
Pn |Yt −Ytt−1 |
SMAPE (symmetric mean abs. % error): n t=d+1 (|Yt |+|Y t−1 |)/2
t
n
1
|Yt − Ytt−1 |
P
MAE (mean absolute error) t−d t=d+1
1 Introduction
3 Holt-Winters Approach
1 Introduction
3 Holt-Winters Approach
R-code:
ttbill=read.table("D://ustbill.dat")
ttbill=ttbill[,-1]
ttbill=as.vector(t(ttbill))
par(mfrow=c(2,2))
plot.ts(ttbill)
acf(ttbill)
plot.ts(log(ttbill))
acf(log(ttbill))
R-code:
lntbill=log(ttbill)
dlntbill=diff(lntbill)
par(mfrow=c(2,2))
plot.ts(dlntbill)
acf(dlntbill)
pacf(dlntbill,30)
Forecasting procedure:
1. Fit an AR(6) to {Yt }t=1,...,n and obtain forecasts Ybn+h
2. Recover X
b t+h from Ybt by “integrating”:
X
b n+h = Ybn+h + X
b n+h−1
3. Recover tbill
d
n+h as
tbill
d
n+h = exp(Xn+h ) = exp(Yn+h ) exp(Xn+h−1 )
b b b
= exp(Ybn+h )tbill
d
n+h−1
ttbill=as.ts(ttbill);tfore=as.ts(tfore)
ts.plot(ttbill[457:462],tfore,lty=c(1:2)) # 1-solid, 2-dashed, 3-dotted
leg.names=c("Actual","Forecast") # Draw legend
legend("topleft",leg.names,lty=c(1:2))
The forecasts for the first four months are reasonably well
The later forecasts get worse as the prediction variability grows with
time
Forecasting (Time Series) Chapter 5 28 / 36
...
Treasury Bill Example: Prediction Intervals
library(forecast)
par(mfrow=c(3,1))
plot(forecast(fit))
fore=exp(as.vector(forecast(fit)$mean))
lower=exp(forecast(fit)$lower[,2]); upper=exp(forecast(fit)$upper[,2])
ts.plot(c(ttbill,fore)); lines(c(ttbill,lower),lty=2); lines(c(ttbill,upper),lty=2)
HW=HoltWinters(ttbill);HW=HoltWinters(ttbill,gamma=F)
plot(HW,predict(HW,6, prediction.interval = TRUE))
Bottom: Holt-Winters
forecasts for tbillt
1 Introduction
3 Holt-Winters Approach
library(tseries)
tsdiag(arma.fit)
ACF-pass!
Ljung-Box test-pass!
pred=predict(arma.fit,n.ahead=12)
inc=trend[60]-trend[59]
fore=trend[60]+inc*(1:12)+seasonal[1:12]+pred$pred
fore.up=fore+1.96*pred$se
fore.low=fore-1.96*pred$se
ts.plot(cbind(test,fore,fore.up,fore.low),col=c(1,2,4,4))
AccDeatht = Tt + St + Yt
ARMA(3,1) model
Yt = 1.03Yt−1 − 0.11Yt−2 − 0.20Yt−2
+Zt − 0.96Zt−1 , Zt ∼ N (0, 41981)
Prediction
data=c(x,test);fore=c(x,fore)
up=c(x,fore.up);low=c(x,fore.low)
ts.plot(cbind(fore,up,low,data),col=c(2,4,4,1))
HW=HoltWinters(x);
plot(HW,predict(HW,12,prediction.interval=T))
Forecasting (Time Series) Chapter 5 36 / 36