/*  fs2000 as a deterministic model
           
       trying to get ride of var z in line 27     */

var m P c ER W Rf k d n l y z;
varexo er;   


parameters alp bet gam mst rho psi del e g h etta;  

alp = 0.33;
bet = 0.99;
gam = 0.003;
mst = 1.011;
rho = 0.7;
psi = 0.787;
del = 0.02;
e = 1;
g = .0001;
h = .3;
etta = .99;  % eta is fixed at .01

model;
log(m) = (1-rho)*log(mst) + rho*log(m(-1));      %  + e_m;
-P/(c(+1)*P(+1)*m)+bet*P(+1)*(alp*k^(alp-1)*n(+1)^(1-alp)+(1-del))/(c(+2)*P(+2)*m(+1))=0;

W = (l/n)+z;    % Want to get rid of the z variable in this equation!!!

-(psi/(1-psi))*(c*P/(1-n))+l/n = 0;
Rf = P*(1-alp)*k(-1)^alp*n^(-alp)/(W*etta);   % denominator is (W(1-eta))
1/(c*P)-bet*P*(1-alp)*k(-1)^alp*n^(1-alp)/(m*l*c(+1)*P(+1)) = 0;
c+k = k(-1)^alp*n^(1-alp)+(1-del)*k(-1);
P*c + ER = m;
%P*c = m;
d = l + ER;               % bank's balance sheet
ER = g + h*er;            % demand for ERs by banks;
% l = 5 - h*Rf; 
Rf*etta = er;           %  wedge between loan rate and ior rate is etta
y = k(-1)^alp*n^(1-alp);

end;

initval;
er = 1.0098;
k = 6;  %changed from 6
m = mst;
P = 2.25;
c = 0.45;
ER = .01;
W = 4.5;
Rf = 1.02;
d = 0.85;
n = .19;
l = 0.86;
y = 0.6;
% z = .00001;
end;

steady;

check;


% permanant shock
endval;
er = 1.3;  % er increases
% k = 6;
m = mst;
% ER = .02;  % ER increases
% P = 2.25;
% c = 0.45;
% W = 4;
% Rf = 1.02;
% d = 0.85;
% n = 0.19;
%l = 0.86;
% y = 0.6;
% gy_obs = exp(gam);
% gp_obs = exp(-gam);
% dA = exp(gam);
end;

steady;

% delay shock
shocks;
var er;
periods 1:50;
values 1.0089;

end;

check;

simul(periods=2000);

// Figures

 tt=0:2001;

    figure('Name','ior, R and Rf');
    subplot(1,1,1);
    plot([0:49], oo_.exo_simul(1:50,1),'k','LineWidth',1.5);
    hold on;
    plot([51:1999], oo_.exo_simul(52:2000,1),'--k','LineWidth',1.5);
    hold on; plot([0:49], oo_.endo_simul(6,1:50),':r');  // both interest rates together
    hold on; plot([51:1999], oo_.endo_simul(6,52:2000),'-.b');//both interest rates together   
    title('IOR, deposit, and loan interet rates');
    axis([0 1000 .9 1.4]);
    xlabel('time')
    ylabel('percent %,\xi')
    legend('ior & R before change', 'ior & R after change','Rf before change','Rf after change','Location','southeast')

    figure('Name','M P C ER');
    subplot(2,2,1); 
    plot(tt, oo_.endo_simul(1,:),'--b');
    title('Money Supply','Fontsize', 12);
    axis([0 2000 .5 2]);
    xlabel('1')
    ylabel('M(m*,m(-1),\rho)')

    subplot(2,2,2);
    plot(tt, oo_.endo_simul(2,:),'c');
    title('Price Level');
    axis([0 500 1 1.75]);
    xlabel('2')
    ylabel('P(k,m,c,\delta)')

    subplot(2,2,3);
    plot(tt, oo_.endo_simul(3,:),'g');
    title('Consumption');
    xlabel('3')
    ylabel('C')
    axis([0 200 0.45 .55]);

    subplot(2,2,4);
    plot(tt, oo_.endo_simul(4,:));
    title('ER');
    xlabel('4')
    ylabel('ER(ior)')
    axis([0 500 0.2 .5]);
   
    
    figure('Name','W Rf k d');
    subplot(2,2,1);
    plot(tt, oo_.endo_simul(5,:));
    title('Wages');
    xlabel('1');
    ylabel('W(loans,n \zeta)');
    axis([0 500 2 4]);

    subplot(2,2,2);
    plot(tt, oo_.endo_simul(6,:));
    title('interest rate for loan to firms');
    xlabel('2');
    ylabel('Rf');
    axis([0 1000 1 1.4]);

    subplot(2,2,3);
    plot(tt, oo_.endo_simul(7,:));
    title('capital');
    xlabel('3');
    ylabel('K');
    axis([0 200 6.55 6.7]);

    subplot(2,2,4);
    plot(tt, oo_.endo_simul(8,:));
    title('deposits');
    ylabel('d');
    xlabel('4');
    axis([0 300 .87 .95]);

    figure('Name','labor loans output \zeta');
    subplot(2,2,1); 
    plot(tt, oo_.endo_simul(9,:));
    title('labor');
    xlabel('1');
    ylabel('L');
    axis([0 500 -.5 2]);

    subplot(2,2,2);
    plot(tt, oo_.endo_simul(10,:));
    title('loans to firms');
    xlabel('2');
    ylabel('Rf');
    axis([0 500 0.25 1]);

    subplot(2,2,3);
    plot(tt, oo_.endo_simul(11,:));
    title('output');
    xlabel('3');
    ylabel('Y');
    axis([0 500 .6 .61]);

    subplot(2,2,4);
    plot(tt, oo_.endo_simul(12,:));
    title('want to get rid of z');
    xlabel('4');
    ylabel('z is \zeta');
    %axis([0 200 -.1 .3]);