Professional Documents
Culture Documents
Ex2 HoltsMethod
Ex2 HoltsMethod
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 = 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
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.
% 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 = 10×7 table
Month t x_t Forecast a_hat b_hat Error
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
% 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
4
Month t x_t Forecast a_hat b_hat Error MSE
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
% Adding to table
T=[T Fcast_New]
5
T = 11×7 table
Month t x_t Forecast a_hat b_hat Error
Damp Trends
Damped trend model
Forecasting Model:
Updating Procedure:
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;
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
Now, adding the mean square error using an exponential smoothing method
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
plot(1:n,T2.Forecast,'--ks','LineWidth',2,'MarkerSize',4)
legend({'Actual Demand','Holts Method','Damp Trend'},'Location','best')
8
9