Time Series PDF
Time Series PDF
Time Series PDF
Math 667
Al Nosedal
Department of Mathematics
Indiana University of Pennsylvania
1. Judgemental methods.
1. Judgemental methods.
2. Extrapolation (or Time Series) methods, and
1. Judgemental methods.
2. Extrapolation (or Time Series) methods, and
3. Econometric (or causal) methods.
2
1
Y(t)
0
1
0 10 20 30 40
Observation number
T + 2Ta Tb
(4) E(R) =
T
s
2Ta Tb (2Ta Tb T )
(5) Stdev(R) =
T 2 (T 1)
When T > 20, the distribution of R is roughly Normal.
Time Series Analysis and Forecasting p. 10/11
Example: Runs test
R E(R)
(8) Z= = 0.32
Stdev(R)
nk
1X
(11) (k) = (Y (t) Y )(Y (t + k) Y )
n
t=1
(k)
(12) (k) =
(0)
y<-3:12
return(result)
}
my.auto(y)
y<-3:12
auto.lag1<-acf(y,lag=1)$acf[2]
auto.lag1
y<-rnorm(25)
0.8
0.4
ACF
0.0
0.4
0 2 4 6 8
Lag
250
200
sales
150
0 10 20 30 40
1:N
250
200
new.sales
150
Time
Stereo Sales
1.0
0.6
ACF
0.2
0.2
0 2 4 6 8 10 12
Lag
1
(14) V ar(k ) '
T
Thus, having plotted the correlogram, we can plot
approximate 95% confidence limits at1/T 2/ T , which
are often further approximated to 2/ T .
350
300
Daily demand
250
200
150
0 20 40 60 80
Time
0.2
0 2 4 6 8 10
Lag
60
40
y
20
0
Index
1.0
0.8
0.6
ACF
0.4
0.2
0.0
0 5 10 15 20 25 30
Lag
3200
closing Dow avg
2800
2400
2000
Time
(15) Yt = Yt1 + + t
(16) DYt = + t
(17) Ft+1 = Yt + YD
Given the monthly Dow Jones data in the file dow.txt, check
that it satisfies the assumptions of a random walk, and use
the random walk model to forecast the value for April 1992.
We have already seen that the Dow Jones series itself is not
random, due to the upward trend, so we form the differences
diff.dow<-diff(index)
ts.diff<-ts(diff.dow)
plot(ts.diff,col=blue,
ylab=first difference, main=Time Series
Plot of Differences)
abline(h=mean(diff.dow),col=red)
100 200
first difference
0
200
0 10 20 30 40 50
Time
1.0
0.6
ACF
0.2
0.2
0 2 4 6 8 10 12
Lag
forecast<-function(y){
diff<-diff(y)
y.diff.bar<-mean(diff) #average difference
last<-length(y) #last observation
F.next<-y[last]+y.diff.bar
new.y<-c(y,F.next)
list(Y(t)=y,Y(t+1)=new.y,F(t+1)=F.next)
forecast.N<-function(y,N){
for (i in 1:N){
new<-forecast(original)$Y(t+1)
original<-new
}
list(Y(t)=y,N=N,Y(t+N)=original)
3000
2500
2000
0 10 20 30 40 50
Time
set.seed(1)
y <- e <- rnorm(100)
for (t in 2:100) {
y[t]<-0.7*y[t-1] + e[t]}
plot(y,type=l,col=blue)
acf(y)
(18) Yt = + t + t
where, as in previous regression equations, is the
intercept, is the slope, and t is an error term.
(19) Yt = c exp(bt)ut
(20) ln(Yt ) = a + bt + t
Time Series Analysis and Forecasting p. 65/11
Exercise: Intel
The file intel.txt contains quarterly sales data for the chip
manufacturing firm Intel from the beginning of 1986 through
the second quarter of 1996. Each sales value is expressed
in millions of dollars. Check that an exponential trend fits
these sales data fairly well. Then estimate the relationship
and interpret it.
Suppose that Y (t) = [4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15].
(21) Lt = Yt + (1 )Lt1
(22) Ft+k = Lt
HoltWinters filtering
30000
Observed / Fitted
25000
20000
obs
forecasts
Time
Time Series Analysis and Forecasting p. 76/11
Example: Exxon (R code)
exxon<-read.table(file="exxon.txt",
header=TRUE)
sales<-exxon$Sales
new.sales<-ts(sales,start=c(1986,1),
end=c(1996,2),freq=4)
mod1<-HoltWinters(new.sales,alpha=0.1,
beta=FALSE,gamma=FALSE)
plot(mod1,xlim=c(1986,1998))
lines(predict(mod1,n.ahead=6),col="red")
legend(1992,20000,c("obs","forecasts"),
col=c("black","red"),lty=c(1,1),bty="n")
HoltWinters filtering
3500
Observed / Fitted
3000
2500
2000
Time
Time Series Analysis and Forecasting p. 83/11
Example: Dow Jones (R code)
dow<-read.table(file="dow.txt",header=TRUE)
index<-dow$Dow
DJI<-ts(index,start=c(1988,1),end=c(1992,3),
freq=12)
mod1<-HoltWinters(DJI,beta=FALSE,gamma=FALSE)
### predictions
plot(mod1,xlim=c(1988,1994),
ylim=c(1800,3700))
preds<-predict(mod1,n.ahead=12)
lines(preds,col="red")
HoltWinters filtering
3500
Observed / Fitted
3000
2500
2000
Time
Time Series Analysis and Forecasting p. 85/11
R code (Holts Model)
mod2<-HoltWinters(DJI,gamma=FALSE)
#Fitting Holts model
### predictions
plot(mod2,xlim=c(1988,1994),
ylim=c(1800,3700))
preds<-predict(mod2,n.ahead=12)
lines(preds,col=red)
HoltWinters filtering
5000
Observed / Fitted
3000
1000
Time
mod.coke<-HoltWinters(sales)
# Holt-Winters model
### predictions
plot(mod.coke,ylim=c(1000,6000),
xlim=c(1986,1998))
preds<-predict(mod.coke,n.ahead=6)
lines(preds,col=red)
Model Identification
Parameter estimation
Diagnostic checking
Iteration
White Noise
Moving Average Process (MA)
Autoregressive Process (AR)
sim.ar<-arima.sim(list(ar=c(0.7)),n=1000)
sim.ma<-arima.sim(list(ma=c(0.6)),n=1000)
par(mfrow=c(2,1))
## AR process
par(mfrow=c(2,1))
## MA process
sim.ar<-arima.sim(list(ar=c(0.4,0.4)),n=1000)
sim.ma<-arima.sim(list(ma=c(0.6,-0.4)),n=1000)
par(mfrow=c(2,1))
## AR process
par(mfrow=c(2,1))
## MA process
sim.ar<-arima.sim(list(ar=c(0.4,0.3,0.2)),
n=1000)
sim.ma<-arima.sim(list(ma=c(0.6,-0.4,0.5)),
n=1000)
par(mfrow=c(2,1))
## AR process
par(mfrow=c(2,1))
## MA process