%general commands
clear all
close all

%parameter values
beta = 0.97;
k = 0.2;
sigma = 1;
int = 1;            %interest rate value
t=-5:10;

%for plotting the interest rate
int1=[0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1];

%specifying lambda1 and lambda2
l1 = ((1+beta+k*sigma) + (((1+beta+k*sigma)^2)-4*beta)^0.5)/2 ;
l2 = ((1+beta+k*sigma) - (((1+beta+k*sigma)^2)-4*beta)^0.5)/2 ;

if t<0
    int=0;
else int=1;

%INFLATION AND OUTPUT: EXPECTED
    for t= -5:10
    
    %iterations for j for output function
    A=((1-l1^min(-t,-0)))/(1-l1^-1);  
    B=(l2)^max((-t+1),1)/(1-l2); 
    
    %output gap equation
    output_exp(t+6) = ((sigma)/(l1-l2))*( (1-beta*l1^-1)*(A) + (1-beta*l2^-1)*(B));
     
    
    %iterations for j for inflation function
    C = ((l1^-1)-(l1^min(-(t),-0)))/(1-l1^-1);
    D = ((l2)^max(-(t-1),1)/(1-l2));
    
    %inflation equation
    inflation_exp(t+6)=((k*sigma)/(l1-l2))*(int+C+D);
    
end;

%INFLATION AND OUTPUT: UNEXPECTED
for t= -5:10
    
                
   %for output
  if t>=0
      E=(1-l1^min(-(t)))/(1-l1^-1);    %this only holds for t=>0
      F=(l2)^1/(1-l2);            %this only holds for t=>0
      
    %output gap equation
    output_unexp(t+6) = ((sigma)/(l1-l2))*( (1-beta*l1^-1)*(E) + (1-beta*l2^-1)*(F));
    
 
    %for inflation
    H = ((l1^-1)-(l1^min(-(t),-0)))/(1-l1^-1);    %this only holds for t=>1!!
 
 if t<0
     G=0;
 else G = ((l2)^1/(1-l2));   %but this only holds for t=>0!
    
    %inflation equation
    inflation_unexp(t+6)=((k*sigma)/(l1-l2))*(int+H+G);
    
 end;
     
  end;
end;


end;
   
%plotting basic model with interest rate change, EXPECTED & UNEXPECTED

figure
plot (output_exp,'-b')
hold on
plot (inflation_exp, '-g')
hold on
plot (output_unexp, '--b')
hold on
plot (inflation_unexp, '--g')
plot (int1, 'r')
hold on
axis ([1 30 -1 1.1]);
xlabel ('Time');
ylabel ('Percentage change');

%Design of graph done manually, saved as createfigure1.m

