% Dekle-Jeong-Kiyotaki Small Open Economy Steady State Calculation for new Shrunk Model (taking real exchange rate as exogenous and dropping foreign bond equations)
% July 12, 2012
% coded by Karrar Hussain


function [ss,check] = djk_shrunk_steadystate(ss,exe)
 
%Parameters of the model (Exogenous)

beta    =0.97;
delta   =2.9;
A       =0.0111;
B       =0.07524;
eta     =-6;
theta   =4.375;
epsilon =1.25;
k       =1/epsilon;

g       =0.11;
tau_ys  =0.03;
z_s     =1;
tau_cs =0.082;


A0 =(1+tau_cs);
A2 = eta/(1+eta);
A3 = theta/(1+eta);
A4 = (beta*theta)/(1+eta);
A5 = A3-A4;
A9 =delta/((1-tau_ys));
A10=A0-2*((A*B)^.5);
A11=2*A;
A12=B+1;

B1=A0-2*((A*B)^.5);
B2=(k*beta+1)/(1-beta);
B10=(k-(1/(beta)));
B3=-tau_ys*(1-(k*beta/(1-beta)));
B4=-tau_cs*(1-(k*beta/(1-beta)));
B5=-(1-(k*beta/(1-beta)));
B6=k*beta/(1-beta);


c1=A12/A;
c2=beta/A;




  check = 0;
  
%%% (6) Solving for steady state of N, after substituting the steady state values of C and
%%% (wx/N) in equation (32), from part (4) of the code file

x0 =2;
options=optimset('TolX',1e-12,'TolFun',1e-20) ;
options.MaxFunEvals=100000;
options.MaxIter = 100000;
JN = @(x)paramJN(x,g,theta,z_s,A,B,A2,A5,A9,A10,A11,B1,B3,B4,B5,beta,B6,tau_ys,tau_cs,k);
[x,fval,exitflag] = fsolve(JN,x0,options); 

pi = x;
f1=-B5*(x/(x-1));
f2=-B3*(x/(x-1));
f3=-B4*(x/(x-1));
f5=(A/(B+1-(beta/x)))^.5;
f6=A9*(B1+2*A/((A/(B+1-(beta/x)))^.5));
f7=g+(theta/2)*(x-1)^2;
f8=B1+(A/((A/(B+1-(beta/x)))^.5))+B*((A/(B+1-(beta/x)))^.5);
f9=z_s/(B1+(A/((A/(B+1-(beta/x)))^.5))+B*((A/(B+1-(beta/x)))^.5));
f10=(g+(theta/2)*(x-1)^2)/(B1+(A/((A/(B+1-(beta/x)))^.5))+B*((A/(B+1-(beta/x)))^.5));
f11=A5*x*(x-1);
f12=((A/(B+1-(beta/x)))^.5)*(1-(1/x));
f13=tau_cs+k*((A/(B+1-(beta/x)))^.5);
f14=tau_cs+(((A/(B+1-(beta/x)))^.5)*(1-(1/x)));

E=g*(-B5*(x/(x-1)))+((A5*x*(x-1))*(-B3*(x/(x-1))))/A2;


h=(g+(tau_ys*(A5*x*(x-1))/A2)+((g+(theta/2)*(x-1)^2)/(B1+(A/((A/(B+1-(beta/x)))^.5))+B*((A/(B+1-(beta/x)))^.5)))*(tau_cs+k*((A/(B+1-(beta/x)))^.5)))/((z_s/(B1+(A/((A/(B+1-(beta/x)))^.5))+B*((A/(B+1-(beta/x)))^.5)))*(tau_cs+k*((A/(B+1-(beta/x)))^.5))+(z_s*tau_ys/A2));

c=(z_s/(B1+(A/((A/(B+1-(beta/x)))^.5))+B*((A/(B+1-(beta/x)))^.5)))*((g+(tau_ys*(A5*x*(x-1))/A2)+((g+(theta/2)*(x-1)^2)/(B1+(A/((A/(B+1-(beta/x)))^.5))+B*((A/(B+1-(beta/x)))^.5)))*(tau_cs+k*((A/(B+1-(beta/x)))^.5)))/((z_s/(B1+(A/((A/(B+1-(beta/x)))^.5))+B*((A/(B+1-(beta/x)))^.5)))*(tau_cs+k*((A/(B+1-(beta/x)))^.5))+(z_s*tau_ys/A2)))-((g+(theta/2)*(x-1)^2)/(B1+(A/((A/(B+1-(beta/x)))^.5))+B*((A/(B+1-(beta/x)))^.5)));

w=(1/((g+(tau_ys*(A5*x*(x-1))/A2)+((g+(theta/2)*(x-1)^2)/(B1+(A/((A/(B+1-(beta/x)))^.5))+B*((A/(B+1-(beta/x)))^.5)))*(tau_cs+k*((A/(B+1-(beta/x)))^.5)))/((z_s/(B1+(A/((A/(B+1-(beta/x)))^.5))+B*((A/(B+1-(beta/x)))^.5)))*(tau_cs+k*((A/(B+1-(beta/x)))^.5))+(z_s*tau_ys/A2))))*((z_s*((g+(tau_ys*(A5*x*(x-1))/A2)+((g+(theta/2)*(x-1)^2)/(B1+(A/((A/(B+1-(beta/x)))^.5))+B*((A/(B+1-(beta/x)))^.5)))*(tau_cs+k*((A/(B+1-(beta/x)))^.5)))/((z_s/(B1+(A/((A/(B+1-(beta/x)))^.5))+B*((A/(B+1-(beta/x)))^.5)))*(tau_cs+k*((A/(B+1-(beta/x)))^.5))+(z_s*tau_ys/A2)))-(A5*x*(x-1)))/A2);

m=f5*c;

R=pi/beta;
lamda=A9/((1-h)*w);
b=(beta/(1-beta))*(tau_ys*w*h+f14*c-g);

Equation1=1-(beta*R/pi);
Equation2=(1/c)-lamda*(A0+(2*A*c/m)-2*(A*B)^.5);
Equation3=(delta/(1-h))-lamda*w*(1-tau_ys);
Equation4=m^2-(A*(c^2)/(B+1-(R^-1)));
Equation5=z_s*h*(1-A2*(w/z_s))-(A3-A4)*pi*(pi-1);
Equation6=m*(1-(pi^-1))+b-g-(R*b/pi)+tau_ys*w*h+tau_cs*c;
Equation7=g-tau_ys*w*h-tau_cs*c-k*m;
%Equation71=tau_ys*w*h+tau_cs*c-g_s-(R*b/pi)-k*b-9.0804e-004;
Equation8=B1*c+A*c^2/m+B*m+g+(theta/2)*(pi-1)^2-z_s*h;


ss =[pi
      m
      h
      w
      c
      R
      lamda
      b
      z_s
      g
      tau_ys
      tau_cs];
  
  