%%% Compute SSE for alpha


function [sse, r, error_mean,error_std]=SSE(data, alpha)


%%% Change alpha to w

   w=1-alpha;

   z=data;
   
%%% Compute mean of data as initial value of S0
   
   s0=mean(z);

%%% Compute sample size of data

   n=length(z);
   
%%% Updating S from S(1) to S(n). S(i) will be regarded as the one step forecast value z_i(1)  

   S=zeros(n,1);
   
   for i=1:n
       
       if i>1           
           S(i)=(1-w)*z(i)+w*S(i-1);
       else
           S(i)=(1-w)*z(i)+w*s0;
       end
     
   end
   
   forecast_error=zeros(n,1);
   
  %%% Compute forecast error 
  
   forecast_error(2:n)=z(2:n)-S(1:n-1);
   
   forecast_error(1)=z(1)-s0;;
   
  %%% Compute SSE
  
   sse=sum((S(1:n-1)-z(2:n)).^2)+(s0-z(1))^2;
  
  %%% Compute mean of forecast error
  
   error_mean=mean(forecast_error);
   
  %%% Compute standard deviation of the estimate of mean of forecast error
  
   error_std=std(forecast_error)/sqrt(n);
   
  %%% Compute auto-correlation of the forecast error from lag=1 to lag=6
   
   r=zeros(1,6);
   
   for i=1:6 
   
        r(i)=auto_corr(forecast_error,i);
        
   end 
       
   
   