%Vivaldo Mendes (ISCTE--IUL), December 2014

%This routine requires the following routine to be previosusly run
%"Baseline_NK_Model_V2". The latter generates the "resp.mat" file, upon
%which we the current routine produces all the graphical and numerical
%output.

%  This routine calculates the foolowing:
% 1. The autocorrelation sample 
% 2. The cross-correlation sample
% 3. The standard deviation
%using the IRFs (Impuilse Response Functions) that come out from NKM, and
%saved in the "resp.mat" file.


%The names of the variables are as follows:
   
    Technology_Shock=resp(:,1);
    Monetray_Shock=resp(:,2);
    Inflation_rate=resp(:,3);
    Hours=resp(:,4);
    Output=resp(:,5);
    Output_gap=resp(:,6);
    Output_Natural_Rate=resp(:,7);
    Interest_Natural_Rate=resp(:,8);
    Interest_Rate=resp(:,9);
    Real_Interest=resp(:,10);
   
    
    
    % Producing the time series of the simulated Impulse response functions
    
    t=0:1:29;
    
    figure   
    subplot(221);plot(t,Technology_Shock,'o-g'),grid on;title('Tecnology shock')
    subplot(222);plot(t,Monetray_Shock,'*-r'), grid on;title('Monetary shock')
    subplot(223);plot(t,Hours,'+-b'),grid on; title('Hours')  
    subplot(224);plot(t,Output,'p-k'),grid on;title('Output')
  
   figure   
    subplot(221);plot(t,Output_gap,'o-g'),grid on;title('Output gap')
    subplot(222);plot(t,Inflation_rate,'*-r'),grid on;title('Inflation')
    subplot(223);plot(t,Interest_Rate,'+-b'),grid on;title('Interest rate(nominal)')
    subplot(224);plot(t,Real_Interest,'p-k'),grid on;title('Real interest rate')
    
    %Now let us calculate the sample autocorrelation function for four important
    %variables
    %fi
    lag=0:10;
        figure
    subplot(221);plot(lag,autocorr(Output_gap,10),'o-b'),
    grid on; title('Autocorrelation: Output gap')
    subplot(222);plot(lag,autocorr(Inflation_rate,10),'*-g'),
    grid on; title('Autocorrelation: Inflation')
    subplot(223);plot(lag,autocorr(Interest_Rate,10),'+-r'),
    grid on; title('Autocorrelation: Interest rate')
    subplot(224);plot(lag,autocorr(Real_Interest,10),'p-k'),
    grid on; title('Autocorrelation: Real interest rate')
    
   
    
    %Now let's go for the crosscorrelation between each relevant variable
    %and Output Gap
    
    lags=-20:20;
    
     figure
     
    subplot(221);plot(lags,crosscorr(Inflation_rate,Output_gap,20),'o-b'),
    grid on; title('Cross-correlation: Inflation')
    subplot(222);plot(lags,crosscorr(Interest_Rate,Output_gap,20),'*-g'),
    grid on; title('Cross-correlation: Interest rate')
    subplot(223);plot(lags,crosscorr(Real_Interest,Output_gap,20),'+-r'),
    grid on; title('Cross-correlation: Real interest rate')
    subplot(224);plot(lags,crosscorr(Hours,Output_gap,20),'p-k'),
    grid on; title('Cross-correlation: Hours')
  
    
    
    
    %Now, let's finish with calculating the Standard DEviation of each
    %variable.
    sigmaY=std(Output_gap)
    sigmai=std(Interest_Rate)
    sigmaPi=std(Inflation_rate)
    sigmaL=std(Inflation_rate)
    
       
    figure
    y_y=[sigmaY sigmai sigmaPi sigmaL];
    names={'Output gap';'Interest';'Inflation';'Hours'}
    bar(y_y)
    set(gca,'xticklabel',names)
    title('Standard Deviation')
    grid on
   
    
