Download as pdf or txt
Download as pdf or txt
You are on page 1of 9

Exponential Smoothing: Holt's Method

You need to develop monthly forecasts (in pallets) for item #TESE2021

clear; clc

T=readtable('ForecastingHolts.xlsx');

Warning: Column headers from the file were modified to make them valid MATLAB identifiers before creating
variable names for the table. The original column headers are saved in the VariableDescriptions property.
Set 'VariableNamingRule' to 'preserve' to use the original column headers as table variable names.

T.Properties.VariableNames={'Month' 't' 'x_t'}

T = 10×3 table
Month t x_t

1 'January' 0 28
2 'February' 1 27
3 'March' 2 30
4 'April' 3 34
5 'May' 4 32
6 'June' 5 33
7 'July' 6 32
8 'August' 7 36
9 'September' 8 33
10 'October' 9 36

% Length of data
[n,~]=size(T)

n = 10

Let's make the plot of the data

plot(T.t,T.x_t,'--ob','Linewidth',2)
xlabel('Period - Month'), ylabel('Demand')
title('Demand of #TESE2021')
grid on, hold on

1
例:
By analyzing the data we can see that there is an upward trend. You determine that , and .
Your estimate level ( ) in January ( ) is 28 pallets/month and the estimate of trend ( ) is 1.35.

% Smoothing constants of level and trend


alpha=0.25; beta=0.1; tau=1;

% Updating procedure
a=zeros(n,1); b=a; Forecast=a;

% Error terms
error=a; error(1)=nan;

• Forecasting Model

• Updating Procedure

2
% From the information of the problem we have
a(1)=28; b(1)=1.35;
Forecast(1)=a(1)+tau*b(1);

for i=2:n
a(i)=alpha*T.x_t(i)+(1-alpha)*(a(i-1)+b(i-1));
b(i)=beta*(a(i)-a(i-1))+(1-beta)*b(i-1);
Forecast(i)=a(i)+tau*b(i);
error(i)=T.x_t(i)-Forecast(i-1);
end

T.Forecast=Forecast; T.a_hat=a; T.b_hat=b; T.Error=error

T = 10×7 table
Month t x_t Forecast a_hat b_hat Error

1 'January' 0 28 29.3500 28.0000 1.3500 NaN


2 'February' 1 27 30.0538 28.7625 1.2913 -2.3500
3 'March' 2 30 31.3302 30.0403 1.2899 -0.0538
4 'April' 3 34 33.3543 31.9977 1.3567 2.6698
5 'May' 4 32 34.3385 33.0157 1.3228 -1.3543
6 'June' 5 33 35.2932 34.0039 1.2893 -1.3385
7 'July' 6 32 35.6769 34.4699 1.2070 -3.2932
8 'August' 7 36 36.9728 35.7577 1.2151 0.3231
9 'September' 8 33 37.0953 35.9796 1.1158 -3.9728
10 'October' 9 36 37.9099 36.8215 1.0884 -1.0953

Let's add the plot of forecasts

plot(1:n,T.Forecast,'-dk','LineWidth',2)

3
%legend({'Actual Demand','Forecast'},'Location','best')

Now, adding the mean square error using an exponential smoothing method

% From the data given


MSE=zeros(n,1); MSE(1)=4.2;

% Smoothing factor
omega=0.05;

for i=2:n
MSE(i)=omega*(T.Error(i))^2+(1-omega)*MSE(i-1);
end

T.MSE=MSE

T = 10×8 table
Month t x_t Forecast a_hat b_hat Error MSE

1 'January' 0 28 29.3500 28.0000 1.3500 NaN 4.2000


2 'February' 1 27 30.0538 28.7625 1.2913 -2.3500 4.2661
3 'March' 2 30 31.3302 30.0403 1.2899 -0.0538 4.0530
4 'April' 3 34 33.3543 31.9977 1.3567 2.6698 4.2067

4
Month t x_t Forecast a_hat b_hat Error MSE

5 'May' 4 32 34.3385 33.0157 1.3228 -1.3543 4.0881


6 'June' 5 33 35.2932 34.0039 1.2893 -1.3385 3.9733
7 'July' 6 32 35.6769 34.4699 1.2070 -3.2932 4.3169
8 'August' 7 36 36.9728 35.7577 1.2151 0.3231 4.1062
9 'September' 8 33 37.0953 35.9796 1.1158 -3.9728 4.6901
10 'October' 9 36 37.9099 36.8215 1.0884 -1.0953 4.5156

Some Extra Info


The month of November is over, and by now we know that the actual demand for #TESE2021 during this period
was 35 units.

Assume that and . Use a level and trend exponential smoothing approach to forecast the
demand for December ( ).

% Deleting info
T(:,4:end)=[];

TNov={'Noviembre',10,35};
T=[T; TNov]

T = 11×3 table
Month t x_t

1 'January' 0 28
2 'February' 1 27
3 'March' 2 30
4 'April' 3 34
5 'May' 4 32
6 'June' 5 33
7 'July' 6 32
8 'August' 7 36
9 'September' 8 33
10 'October' 9 36
11 'Noviembre' 10 35

Forecast for December

% For the forecast


Fcast_New=HoltsMethod(T.x_t,alpha,beta,tau);

% Adding to table
T=[T Fcast_New]

5
T = 11×7 table
Month t x_t Forecast a_hat b_hat Error

1 'January' 0 28 29.3500 28.0000 1.3500 NaN


2 'February' 1 27 30.0538 28.7625 1.2913 -2.3500
3 'March' 2 30 31.3302 30.0403 1.2899 -0.0538
4 'April' 3 34 33.3543 31.9977 1.3567 2.6698
5 'May' 4 32 34.3385 33.0157 1.3228 -1.3543
6 'June' 5 33 35.2932 34.0039 1.2893 -1.3385
7 'July' 6 32 35.6769 34.4699 1.2070 -3.2932
8 'August' 7 36 36.9728 35.7577 1.2151 0.3231
9 'September' 8 33 37.0953 35.9796 1.1158 -3.9728
10 'October' 9 36 37.9099 36.8215 1.0884 -1.0953
11 'Noviembre' 10 35 38.1980 37.1824 1.0156 -2.9099

Damp Trends
Damped trend model

• Slight modification to exponential smoothing model


• Select damping parameter , where

Forecasting Model:

Updating Procedure:

If , this is just a linear trend

% Getting the data


T2=T(:,1:3)

T2 = 11×3 table
Month t x_t

1 'January' 0 28
2 'February' 1 27
3 'March' 2 30

6
Month t x_t

4 'April' 3 34
5 'May' 4 32
6 'June' 5 33
7 'July' 6 32
8 'August' 7 36
9 'September' 8 33
10 'October' 9 36
11 'Noviembre' 10 35

[n,~]=size(T2)

n = 11

Let's make a table for the prediction coefficients and the forecast for each month

% Smoothing constants
phi=0.9;

% Updating procedure
a=zeros(n,1); b=a; Forecast=a;

% Error terms
error=a; error(1)=nan;

% From the information of the problem we have


a(1)=28; b(1)=1.35; SumPhi=0;

for i=1:tau
SumPhi=SumPhi+phi^i;
end

Forecast(1)=a(1)+SumPhi*b(1);

for i=2:n
a(i)=alpha*T.x_t(i)+(1-alpha)*(a(i-1)+phi*b(i-1));
b(i)=beta*(a(i)-a(i-1))+(1-beta)*phi*b(i-1);
Forecast(i)=a(i)+SumPhi*b(i);
error(i)=T.x_t(i)-Forecast(i-1);
end

T2.Forecast=Forecast; T2.a_hat=a; T2.b_hat=b; T2.Error=error;

Now, adding the mean square error using an exponential smoothing method

% From the data given


MSE=zeros(n,1); MSE(1)=4.2;

7
% Smoothing factor
omega=0.05;

for i=2:n
MSE(i)=omega*(T2.Error(i))^2+(1-omega)*MSE(i-1);
end

T2.MSE=MSE

T2 = 11×8 table
Month t x_t Forecast a_hat b_hat Error MSE

1 'January' 0 28 29.2150 28.0000 1.3500 NaN 4.2000


2 'February' 1 27 29.7049 28.6612 1.1596 -2.2150 4.2353
3 'March' 2 30 30.7246 29.7787 1.0510 0.2951 4.0279
4 'April' 3 34 32.4685 31.5435 1.0278 3.2754 4.3629
5 'May' 4 32 33.1734 32.3514 0.9133 -0.4685 4.1557
6 'June' 5 33 33.8659 33.1300 0.8177 -0.1734 3.9495
7 'July' 6 32 34.0198 33.3994 0.6892 -1.8659 3.9261
8 'August' 7 36 35.1177 34.5148 0.6698 1.9802 3.9258
9 'September' 8 33 35.0832 34.5882 0.5499 -2.1177 3.9538
10 'October' 9 36 35.7784 35.3124 0.5178 0.9168 3.7981
11 'Noviembre' 10 35 35.9857 35.5838 0.4466 -0.7784 3.6385

Let's plot the forecast and the actual demand

plot(1:n,T2.Forecast,'--ks','LineWidth',2,'MarkerSize',4)
legend({'Actual Demand','Holts Method','Damp Trend'},'Location','best')

8
9

You might also like