Professional Documents
Culture Documents
Moving Average
Moving Average
1.
1890 1891 1892 1893 1894 1895 1896 1897 1898 1899
82 80 76 73 76 73 72 73 77 74
MSE 4.5694
2.
1890 1891 1892 1893 1894 1895 1896 1897 1898 1899
82 80 76 73 76 73 72 73 77 74
MSE 9.98
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
Gamma=1.0
MSE 0.13
4.
PhD17105
Appendix:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%
% 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
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');