You are on page 1of 5

PhD17105

1.

1890 1891 1892 1893 1894 1895 1896 1897 1898 1899

82 80 76 73 76 73 72 73 77 74

Smoothed 0 0 79.333 76.333 75 74 73.666 72.666 74 74.666


series

error -3.333 -3.333 1 -1 -1.666 0.333 3 -0.666

MSE 4.5694

2.

1890 1891 1892 1893 1894 1895 1896 1897 1898 1899

82 80 76 73 76 73 72 73 77 74

Single 0 82 81 78.50 75.75 75.875 74.437 73.219 73.109 75.054


exponential
Smoothed
series,
alpha=0.5

error -2 -5 -5.5 0.25 -2.875 -2.437 -0.219 3.89 -1.055

MSE 9.98

alpha=0.9 0 82 80.2 76.42 73.34 75.734 73.273 72.127 72.913 76.591


2

error -2 -4.2 -3.42 2.658 -2.734 -1.273 0.873 4.087 -2.591

MSE 8.19
PhD17105

3.

1890 1891 1892 1893 1894 1895 1896 1897 1898 1899

82 80 76 73 76 73 72 73 77 74

Double 82 80 76.2 72.94 75.3 73.4 71.96 72.744 76.6 74.656


exponential 68 8 52
Smoothed
series,
alpha=0.9

Gamma=1.0

error 0 0 -0.2 0.06 0.63 -0.48 0.041 0.256 0.34 -0.656


2 7

MSE 0.13

4.
PhD17105

Appendix:

%%%%% mean price for a commodity during the period


1890-1899
data=[1890 1891 1892 1893 1894 1895 1896 1897 1898
1899;82 80 76 73 76 73 72 73 77 74];
price=data(2,:);
year=data(1,:);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%
% calculate moving averages with window

window=3;
n = length(price);
m = zeros(1,n-window);
for t=1:n-window+1
k=price(t:(t+window-1));
m(t+window-1) = mean(k);
end
error=price-m;
error1=error(window:n);
MSE=meansqr(error1);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% % Calculates single exponentially smoothed data
with weight parameter
% alpha. to find value of alpha which gives lowest
MSE is better.
% This is an iterative procedure beginning with a
range of ? between 0.1 and 0.9.
alpha1 = 0.5;
s1 = zeros(1,n);
s1(2) = price(1);
for i = 3:n
s1(i) = alpha1*price(i-1) + ((1-alpha1)*s1(i-1));
end
error_s1=price-s1;
error1_s1=error_s1(2:n);
MSE_s1=meansqr(error1_s1);

% Bootstrapping of forecasts
% We use the last data point and the last smoothed
point to calculate
PhD17105

% forecasts.

N = 5; % number of forecasts
yorigin = price(n);
f1 = zeros(1,N);
f1(1) = s1(n); % smoothed value at origin
for i = 1:N-1
f1(i+1) = alpha1*yorigin + ((1-alpha1)*f1(i));
end
forecastyear=[1900 1901 1902 1903 1904];
alpha2 = 0.9;
s2 = zeros(1,n);
s2(2) = price(1);
for i = 3:n
s2(i) = alpha2*price(i-1) + ((1-alpha2)*s2(i-1));
end
error_s2=price-s2;
error1_s2=error_s2(2:n);
MSE_s2=meansqr(error1_s2);

% Bootstrapping of forecasts
% We use the last data point and the last smoothed
point to calculate
% forecasts.

N = 5; % number of forecasts
yorigin = price(n);
f2 = zeros(1,N);
f2(1) = s2(n); % smoothed value at origin
for i = 1:N-1
f2(i+1) = alpha2*yorigin + ((1-alpha2)*f2(i));
end
%%%%%%%%%%%%%%%%%%
gamma=1.0;
alpha2 = 0.9;
% Calculates double exponentially smoothed data with
weight parameters
% alpha2 and gamma.
ds = zeros(1,n);
b = zeros(1,n);
ds(1) = price(1);
b(1) = price(2) - price(1); % out of three this
was choosen
for i = 2:n
PhD17105

ds(i) = alpha2*price(i) + ((1-alpha2)*(ds(i-


1)+b(i-1)));
b(i) = gamma*(ds(i)-ds(i-1)) + ((1-gamma)*b(i-
1));
end
error_ds=price-ds;
error1_ds=error_ds(1:n);
MSE_ds=meansqr(error1_ds);
% Forecasting with double exponential smoothing
N = 5; % number of forecasts
f = zeros(1,N);
st = ds(n);
bt = b(n);
for i = 1:N
f(i) = st + bt;
st1 = st;
st = alpha2*f(i) + ((1-alpha2)*(st+bt));
bt = gamma*(st-st1) + ((1-gamma)*bt);
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
figure;
plot(year, price, 'r-s','LineWidth', 1.5);
hold on;
plot(year, m, 'b-d','LineWidth', 1);
plot(year, s1, 'c-o','LineWidth', 1);
plot(forecastyear, f1, 'c:o','LineWidth', 1.5);
plot(year, s2, 'm-^','LineWidth', 1);
plot(forecastyear, f2, 'm:^', 'LineWidth', 1.5);
plot(year, ds, 'g-*','LineWidth', 1);
plot(forecastyear, f, 'g:*', 'LineWidth', 1.5);

legend('Original data',...
'Moving average of window 3',...
['alpha=0.5, mse=' num2str(MSE_s1)],...
'forecast: alpha=0.5 ',...
['alpha=0.9, mse=' num2str(MSE_s2)],...
'forecast: alpha=0.9 ',...
['alpha=0.9, gamma=1.0, mse='
num2str(MSE_ds)],...
'forecast: alpha=0.9, gamma=1.0',...
'Location', 'SouthWest');
title('Time Series Analysis');
xlabel(' Year ');
ylabel('mean price for a commodity');

You might also like