%This file calculates the staedy state of the DevLaneXuNoEntre model
function x = DLXNoEntre_steadystate(ststparams)
% Variables are ordered 
%  x=[W, P, C, H, M, PN, PM, KN, HN, RN, PX, KX, HX, RX, S, RKN, RKX, TM, CN, CM, IN,  IX, QN,QX,YN, YX, MCN, D, i, istar, GDP, PXstar]
x0 = [15 3  3  0  2  7   1   17  0.3 0.1 1   32  0.1 0.1 1  1    1    6   0.8 4   0.35 0.35 3 3  1   11  6   7.2 0.015 0.015 18 1];
options = optimset('MaxFunEvals',300000,'MaxIter',100000);
x = fsolve(@DLXNoEntre_function,x0,options);
%----------------------------------------------------------------%
function e = DLXNoEntre_function(x,ststparams)
global ststparams
% 

sigma = 2;%Inverse of elasticity of substitution in consumption;
epsilon =2; %Inverse of elasticity of substitution in real balance;
beta = 0.985;%Discount factor (quarterly);
eta = 1;%Coefficient of labor in utility;
psi = 1; %Inverse of elasticity of labor supply
chi =0.001; %Coefficient of real balance in utility;
rho = 0.9;%elasticity of substitution between non-tradable and tradable goods;
alpha = 0.3;%Share of capital in non-traded sector
gamma = 0.7;%Share of capital in export sector
%omega =0.95;%Share of household labor in the effective labor 
lambda = 11;%elasticity of substitution between non-tradable goods:
delta = 0.025; %Quarterly rate of capital depreciation;
a = 0.55;%Share of the non-tradable goods in production;
AN = 1; %Productivity in the non-traded sector;
AX = 1;%Productivity in the export sector;
%PXstar = 1;%ToT
%The monetary policy parameters;
Sbar = 1;
%bpin=1;
%bpi=1;
%bex=1;
%bid=1/betta-1;
%mupin=0.001;
%mupi=0.001;
%mus=999;
%Adjustment costs;
%psid=0.0007;
%psii=12;
%psipm=0;
%psipn=120;
%Entrepreneurs' parameters:
%sigmao=0.5; %Standard error of the technology shock of entrepreneurs, follow BGG;
%nu=0.94; %Aggregate saving rate of entrepreneurs;
%mu=0.2; %Parameters of the monintoring cost, follow BGG
%persistence of the term of trade and world interest rate shocks;
%rhowi=0.46;
%rhot=0.77;


% Steady state equations
% HH optimality conditions for labor, domestic and foreign bonds and real balances
e(1) = x(1)/x(2)-eta*(x(3)^sigma)*(x(4)^psi);
% Money equation
e(2) = x(5)/x(2)-(chi^(1/epsilon)*x(3)^(sigma/epsilon))/((1-beta)^(1/epsilon));
% Price index
e(3) = x(2)-(a*x(6)^(1-rho)+(1-a)*x(7)^(1-rho))^(1/(1-rho));
% CN and CM demand
e(4) = x(19)-a*(x(6)/x(2))^(-rho)*x(3);
e(5) = x(20)-(1-a)*(x(7)/x(2))^(-rho)*x(3);
% % Cost minimization and Production functions
e(6) = x(1)/x(6)-((lambda-1)/lambda)*(1-alpha)*(AN*(x(8)^alpha)*(x(9)^((1-alpha)-1)));
e(7) = x(10)/x(6)-((lambda-1)/lambda)*alpha*(AN*(x(8)^(alpha-1))*(x(9)^(1-alpha)));
e(8) = x(1)/x(11)-(1-gamma)*(AX*(x(12)^gamma)*(x(13)^((1-gamma)-1)));
e(9) = x(14)/x(11)-gamma*(AX*(x(12)^(gamma-1))*(x(13)^(1-gamma)));
%LOOP
e(10)= x(11)-x(15)*x(32);
% PM as a markup over PMf, which is normalised to 1
e(11)= x(7)-(lambda/(lambda-1))*x(15);
% Rate of return on capital
e(12)= x(16)-1/beta;
e(13)= x(16)-x(10)/x(2)-(1-delta);
e(14)= x(17)-1/beta;
e(15)= x(17)-x(14)/x(2)-(1-delta);
% Market Clearing of domestic goods market and demand for import goods:
e(16)= AN*(x(8)^alpha)*(x(9)^(1-alpha))-a*(x(6)/x(2))^(-rho)*(x(3)+delta*x(8)+delta*x(12));
e(17)= x(18)-(1-a)*(x(7)/x(2))^(-rho)*(x(3)+delta*x(8)+delta*x(12));
% labor supply conditions:
e(18)= x(13)+x(9)-x(4);
% aggregate Balance of Payments
e(19)= (1-a)*(x(7)/x(2))^(-rho)*(x(3)+delta*x(8)+delta*x(12))+0.4*(x(6)*AN*(x(8)^alpha)*(x(9)^(1-alpha))+x(11)*AX*(x(12)^gamma)*(x(13)^(1-gamma)))*(1/beta-1)-(x(11)/x(15))*AX*(x(12)^gamma)*(x(13)^(1-gamma));
%interest rate rule
e(20)= x(15)-Sbar;
% The steady state of other variables are:
e(21)= x(21)-delta*x(8); % IN
e(22)= x(22)-delta*x(12); %IX
e(23)= x(23)-x(2); %QN
e(24)= x(24)-x(2); %QX
e(25)= x(25)-(AN*(x(8)^alpha)*(x(9)^(1-alpha))); %YN
e(26)= x(26)-(AX*(x(12)^gamma)*(x(13)^(1-gamma))); %YX
e(27)= x(27)-((lambda-1)/lambda)*x(6); %MCN
e(28)= x(28)-0.4*(x(31)); %D
e(29)= x(29)-(1/beta-1); %i
e(30)= x(30)-(1/beta-1); %istar
e(31)= x(31)-(x(6)*x(25)+x(11)*x(26)); %GDP
e(32)= x(32)-1;
% RKNN=RN+(1-delta)*QN;
% RKXN=nrx+(1-delta)*QX;
% PN(-1)=PN;
% PM(-1)=PM;
% Dbar=D;
%TB=PXstar*YX-TM;
%RER=S/P;
%pi=P/P(-1)
%pi=1;
%pin=PN/PN(-1)
%pin=1;
%real interest rate
%r=i;
%import price inflation
%piim=1;