% Description Compute the return of return
% rate of reutrn=ln(S(i)/S(i-1))
clear all;
[numericalData, textData]=xlsread('OMXS30.xls')
Stocks=numericalData;
SdOfAbb=zeros(189,1);
VarianceOfAbb=zeros(189,1);
VarianceOfAbb2=zeros(189,1);
SdOfAbb2=zeros(189,1);

for i=1:1:189   
   for k=2:1:(i+63)        
    RateOfReturn(k)=log(Stocks(k)/Stocks(k-1));      
   end

   VarianceOfAbb(i)=var(RateOfReturn);
    SdOfAbb(i)=sqrt(VarianceOfAbb(i))/sqrt(1/252);
  
end
SdOfAbb

for i=1:1:189    
   for k=(i+1):1:(i+63)        
    RateOfReturn2(k-i)=log(Stocks(k)/Stocks(k-1));      
   end

   VarianceOfAbb2(i)=var(RateOfReturn2);
    SdOfAbb2(i)=sqrt(VarianceOfAbb2(i))/sqrt(1/252);
   
end
SdOfAbb2

plot([1:1:189],SdOfAbb,'--ro',[1:1:189],SdOfAbb2,'-b*')
title('Historical Volatility and Folating Volatility');
xlabel('date');
ylabel('Volatility')
legend('Historical Volatility','Folating Volatility','location','northwest');
grid on
