Sei sulla pagina 1di 60

# Time Series Analysis and

Forecasting
Introduction to Time Series Analysis
A time-series is a set of observations on a quantitative
variable collected over time.
Examples
Dow Jones Industrial Averages
Historical data on sales, inventory, customer counts,
interest rates, costs, etc
Businesses are often very interested in forecasting time
series variables.
Often, independent variables are not available to build a
regression model of a time series variable.
In time series analysis, we analyze the past behavior of
a variable in order to predict its future behavior.
Methods used in Forecasting
Regression Analysis
Time Series Analysis (TSA)
A statistical technique that uses time-
series data for explaining the past or
forecasting future events.
The prediction is a function of time
(days, months, years, etc.)
No causal variable; examine past behavior
of a variable and and attempt to predict
future behavior
Components of TSA
Time Frame (How far can we predict?)
short-term (1 - 2 periods)
medium-term (5 - 10 periods)
long-term (12+ periods)
No line of demarcation
Trend
Gradual, long-term movement (up or down) of
demand.
Easiest to detect
Components of TSA (Cont.)
Cycle
An up-and-down repetitive movement in demand.
repeats itself over a long period of time
Seasonal Variation
An up-and-down repetitive movement within a trend
occurring periodically.
Often weather related but could be daily or weekly
occurrence
Random Variations
Erratic movements that are not predictable because
they do not follow a pattern
Time Series Plot
Actual Sales
\$0
\$500
\$1,000
\$1,500
\$2,000
\$2,500
\$3,000
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
Time Period
S
a
l
e
s

(
i
n

\$
1
,
0
0
0
s
)
Components of TSA (Cont.)
Difficult to forecast demand because...
There are no causal variables
The components (trend, seasonality,
cycles, and random variation) cannot
always be easily or accurately
identified
Some Time Series Terms
Stationary Data - a time series variable exhibiting
no significant upward or downward trend over
time.
Nonstationary Data - a time series variable
exhibiting a significant upward or downward trend
over time.
Seasonal Data - a time series variable exhibiting
a repeating patterns at regular intervals over
time.
Approaching Time Series Analysis
There are many, many different time series
techniques.
It is usually impossible to know which technique
will be best for a particular data set.
It is customary to try out several different
techniques and select the one that seems to
work best.
To be an effective time series modeler, you need
to keep several time series techniques in your
tool box.
Measuring Accuracy
We need a way to compare different time series
techniques for a given data set.
Four common techniques are the:

mean absolute deviation,

mean absolute percent error,

the mean square error,

root mean square error.
Y Y
i i
i
n
n

1
( )
MSE =
Y Y
i i
i
n
n

2
1
MSE RMSE =

n
i
i
i i
n
1
Y
Y

Y
100
= MAPE
We will focus on MSE.
Extrapolation Models
Extrapolation models try to account for the past
behavior of a time series variable in an effort to
predict the future behavior of the variable.
( )

, , , Y Y Y Y
t t t t
f
+
=
1 1 2

## Well first talk about several extrapolation techniques

that are appropriate for stationary data.
An Example
Electra-City is a retail store that sells audio and video
equipment for the home and car.
Each month the manager of the store must order
merchandise from a distant warehouse.
Currently, the manager is trying to estimate how many
VCRs the store is likely to sell in the next month.
He has collected 24 months of data.

Moving Averages

Y
Y Y Y
t t-1 t- +1
t
k
k
+
=
+ +
1
No general method exists for determining k.
We must try out several k values to see what works best.
Implementing the Model
A Comment on Comparing MSE
Values
Care should be taken when comparing MSE
values of two different forecasting techniques.
The lowest MSE may result from a technique that
fits older values very well but fits recent values
poorly.
It is sometimes wise to compute the MSE using
only the most recent values.
Forecasting With The Moving Average
Model

. Y
Y Y
2
36 +35
2
25
24 23
355 =
+
= =
Forecasts for time periods 25 and 26 at time period 24:

. Y
Y Y
2
35.5+36
2
26
25 24
3575 =
+
= =
Weighted Moving Average
The moving average technique assigns equal weight
to all previous observations

Y
1
Y
1
Y
1
Y
t t-1 t - -1 t k
k k k
+
= + + +
1

The weighted moving average technique allows for
different weights to be assigned to previous
observations.

Y Y Y Y
t t -1 t - -1 t k k
w w w
+
= + + +
1 1 2

where 0 and s s =

w w
i i
1 1
We must determine values for k and the w
i

Implementing the Model
Using optimal values for the
weights that minimizes the MSE
Forecasting With The Weighted
Moving Average Model

. . . Y Y Y
25 1 24 2 23
0 291 36 0 709 35 353 = + = + = w w
Forecasts for time periods 25 and 26 at time period 24:
80 . 35 36 709 . 0 3 . 35 291 . 0 Y Y

24 2 25 1 26
= + = + = w w
Exponential Smoothing

(

) Y Y Y Y
t t t t +
= +
1
o
where 0 1 s s o
It can be shown that the above equation is equivalent to:

( ) ( ) ( ) Y Y Y Y Y
t t t t
n
t n +
= + + + + +
1 1
2
2
1 1 1 o o o o o o o
Examples of Two
Exponential Smoothing Functions
28
30
32
34
36
38
40
42
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
Time Period
U
n
i
t
s

S
o
l
d
Number of VCRs Sold
Exp. Smoothing alpha=0.1
Exp. Smoothing alpha=0.9
Implementing the Model
Forecasting With The
Exponential Smoothing Model

(

) . . ( . ) . Y Y Y Y
25 24 24 24
3574 0 268 36 3574 3581 = + = + = o
Forecasts for time periods 25 and 26 at time period 24:

(

)

(

)

. Y Y Y Y Y Y Y Y
26 25 25 25 25 25 25 25
3581 = + ~ + = = o o

## . , Y for = 25, 26, 27,

t
t = 3581
Note that,
Seasonality
Seasonality is a regular, repeating
pattern in time series data.
May be additive or multiplicative in
nature...
Multiplicative Seasonal Effects
1 2 3 4 5 6 7 8 9 1 0 1 1 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 2 0 2 1 2 2 2 3 2 4 2 5
Tim e Pe r iod
1 2 3 4 5 6 7 8 9 1 0 1 1 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 2 0 2 1 2 2 2 3 2 4 2 5
Tim e Pe r iod
Stationary Seasonal Effects
Stationary Data With
p n t t n t + +
+ = S E Y

where
1
)E - (1 ) S - Y ( E

+ =
t t-p t t
o o
p t t t t
+ = )S - (1 ) E - Y ( S | |
1 0
1 0
s s
s s
|
o
p represents the number of seasonal periods
E
t
is the expected level at time period t.
S
t
is the seasonal factor for time period t.
Implementing the Model
Seasonal Effects Model
Forecasts for time periods 25 - 28 at time period 24:
4 24 24 24
S E Y

+ +
+ =
n n
00 . 363 45 . 8 55 . 354 S E Y

21 24 25
= + = + =
73 . 336 82 . 17 55 . 354 S E Y

22 24 26
= = + =
13 . 401 58 . 46 55 . 354 S E Y

23 24 27
= + = + =
82 . 322 73 . 31 55 . 354 S E Y

24 24 28
= = + =
Stationary Data With
Multiplicative Seasonal Effects
p n t t n t + +
= S E Y

where
1
)E - (1 ) /S Y ( E

+ =
t t-p t t
o o
p t t t t
+ = )S - (1 ) /E Y ( S | |
1 0
1 0
s s
s s
|
o
p represents the number of seasonal periods
E
t
is the expected level at time period t.
S
t
is the seasonal factor for time period t.
Implementing the Model
Forecasting With The Multiplicative
Seasonal Effects Model
Forecasts for time periods 25 - 28 at time period 24:
4 24 24 24
S E Y

+ +
=
n n
26 . 359 015 . 1 95 . 353 S E Y

21 24 25
= = =
83 . 334 946 . 0 95 . 353 S E Y

22 24 26
= = =
03 . 401 133 . 1 95 . 353 S E Y

23 24 27
= = =
80 . 322 912 . 0 95 . 353 S E Y

24 24 28
= = =
Trend Models
Trend is the long-term sweep or general
direction of movement in a time series.
Well now consider some nonstationary time
series techniques that are appropriate for
data exhibiting upward or downward trends.
An Example
WaterCraft Inc. is a manufacturer of personal water crafts (also known as jet
skis).
The company has enjoyed a fairly steady growth in sales of its products.
The officers of the company are preparing sales and manufacturing plans
for the coming year.
Forecasts are needed of the level of sales that the company expects to
achieve each quarter.
Double Exponential Smoothing
(Holts Method)
E
t
is the expected base level at time period t.
T
t
is the expected trend at time period t.
t t n t
nT E Y

+ =
+
where
E
t
= oY
t
+ (1-o)(E
t-1
+ T
t-1
)
T
t
= |(E
t
E
t-1
) + (1-|) T
t-1
0 1 1 s s s s o | and 0
Implementing the Model
Using optimal values for and that
minimizes the MSE
Forecasting With Holts Model
Forecasts for time periods 21 through 24 at time period 20:

. . . Y E T
21 20 20
1 23368 1 1521 2488 9 = + = + =

. . . Y E T
22 20 20
2 23368 2 1521 26410 = + = + =

. . . Y E T
23 20 20
3 23368 3 1521 27931 = + = + =

. . . Y E T
24 20 20
4 23368 4 1521 29452 = + = + =
20 20 20
T E Y

n
n
+ =
+
Seasonal Effects

p n t t t n t
n
+ +
+ + = S T E Y

where
( ) ) T )(E - (1 S Y E
1 1
+ + =
t t p t t t
o o
( )
1 1
)T - (1 E E T

+ =
t t t t
| |
( )
p t t t t
+ = )S - (1 E Y S
1 0
1 0
1 0
s s
s s
s s

|
o
Implementing the Model
The Linear Trend Model

Y X
t
b b
t
= +
0 1 1
where X
1
t
t =
For example:
X X X
1 1 1
1 2 3
1 2 3 = = = , , ,
Implementing the Model
Forecasting With The Linear Trend Model
Forecasts for time periods 21 through 24 at time period 20:

. . . Y X
21 0 1 1
21
3751 92 6255 21 2320 3 = + = + = b b

. . . Y X
22 0 1 1
22
3751 92 6255 22 2412 9 = + = + = b b

. . . Y X
23 0 1 1
23
3751 92 6255 23 25056 = + = + = b b

. . . Y X
24 0 1 1
24
3751 92 6255 24 2598 2 = + = + = b b
The TREND() Function
TREND(Y-range, X-range, X-value for prediction)
where:
Y-range is the spreadsheet range containing the dependent Y
variable,
X-range is the spreadsheet range containing the independent X
variable(s),
X-value for prediction is a cell (or cells) containing the values for
the independent X variable(s) for which we want an estimated value
of Y.
Note: The TREND( ) function is dynamically updated whenever any inputs to
the function change. However, it does not provide the statistical information
provided by the regression tool. It is best two use these two different
approaches to doing regression in conjunction with one another.

Y X X
t
b b b
t t
= + +
0 1 1 2 2
where X and X
1 2
2
t t
t t = =
Implementing the Model
Model
Forecasts for time periods 21 through 24 at time period 20:
8 . 2598 21 617 . 3 21 671 . 16 67 . 653 X X Y

2
2 2 1 1 0 21
21 21
= + + = + + = b b b
0 . 2771 22 617 . 3 22 671 . 16 67 . 653 X X Y

2
2 2 1 1 0 22
22 22
= + + = + + = b b b
4 . 2950 23 617 . 3 23 671 . 16 67 . 653 X X Y

2
2 2 1 1 0 23
23 23
= + + = + + = b b b
1 . 3137 24 617 . 3 24 671 . 16 67 . 653 X X Y

2
2 2 1 1 0 24
24 24
= + + = + + = b b b
Computing Multiplicative
Seasonal Indices
We can compute multiplicative seasonal
adjustment indices for period p as
follows:
S
Y
Y
, for all occuring in season
p
i
i
i
p
n
i p =

The final forecast for period i is then

Y adjusted = Y S , for any occuring in season
i i p
i p
Implementing the Model
The Plot
Applied To Our Quadratic Trend Model
Forecasts for time periods 21 through 24 at time period 20:
8 . 2747 % 7 . 105 9 . 2598 ) X X ( Y

1 2 2 1 1 0 21
21 21
= = + + = S b b b
6 . 2219 % 1 . 80 1 . 2771 ) X X ( Y

2 2 2 1 1 0 22
22 22
= = + + = S b b b
4 . 3041 % 1 . 103 5 . 2950 ) X X ( Y

3 2 2 1 1 0 23
23 23
= = + + = S b b b
1 . 3486 % 1 . 111 2 . 3137 ) X X ( Y

4 2 2 1 1 0 24
24 24
= = + + = S b b b
Summary of the Calculation and Use
of Seasonal Indices
1. Create a trend model and calculate the estimated value
for each observation in the sample.
2. For each observation, calculate the ratio of the actual
value to the predicted trend value:
(For additive effects, compute the difference:
3. For each season, compute the average of the ratios
calculated in step 2. These are the seasonal indices.
4. Multiply any forecast produced by the trend model by
the appropriate seasonal index calculated in step 3.
factor to the forecast.)

t
Y

. Y

/ Y
t t
). Y

Y
t t

Refining the Seasonal Indices
Note that Solver can be used to
simultaneously determine the optimal
values of the seasonal indices and the
parameters of the trend model being
used.
There is no guarantee that this will
produce a better forecast, but it should
produce a model that fits the data better
in terms of the MSE.

Seasonal Regression Models
Indicator variables may also be used in regression
models to represent seasonal effects.
If there are p seasons, we need p-1 indicator variables.
Our example problem involves quarterly data, so p=4
and we define the following 3 indicator variables:
X
if Y is an observation from quarter 2
otherwise
4
1
0
t
t
=

,
,
X
if Y is an observation from quarter 1
otherwise
3
1
0
t
t
=

,
,
X
if Y is an observation from quarter 3
otherwise
5
1
0
t
t
=

,
,
Implementing the Model
The regression function is:

Y X X X X X
t
b b b b b b
t t t t t
= + + + + +
0 1 1 2 2 3 3 4 4 5 5
where X and X
1 2
2
t t
t t = =
The Data
The Regression Results
The Plot
Forecasting With The
Seasonal Regression Model
Forecasts for time periods 21 through 24 at time period 20:
5 . 2638 ) 0 ( 453 . 123 ) 0 ( 736 . 424 ) 1 ( 805 . 86 ) 21 ( 485 . 3 ) 21 ( 319 . 17 471 . 824 Y

2
21
= + + =
7 . 2467 ) 0 ( 453 . 123 ) 1 ( 736 . 424 ) 0 ( 805 . 86 ) 22 ( 485 . 3 ) 22 ( 319 . 17 471 . 824 Y

2
22
= + + =
2 . 2943 ) 1 ( 453 . 123 ) 0 ( 736 . 424 ) 0 ( 805 . 86 ) 23 ( 485 . 3 ) 23 ( 319 . 17 471 . 824 Y

2
23
= + + =
8 . 3247 ) 0 ( 453 . 123 ) 0 ( 736 . 424 ) 0 ( 805 . 86 ) 24 ( 485 . 3 ) 24 ( 319 . 17 471 . 824 Y

2
24
= + + =
Combining Forecasts
It is also possible to combine forecasts to create a
composite forecast.
Suppose we used three different forecasting methods
on a given data set.
Denote the predicted value of time period t using
each method as follows:
F F F
t t t
1 2 3
, , and
We could create a composite forecast as follows:

Y F F F
t
b b b b
t t t
= + + +
0 1 1 2 2 3 3