
function [Ct,lambdat,Ht,wt,mht,pit,Rt,Rkt,Zt,omega1t,omega2t,Lambdat,...
    nt,bt,sigmat,pwt,Yt,Kt,At,wet,rkt,qt,It,dt,mt,...
    gmt,gyt,GDPt] = steady_state2(A_ss,beta,eta,Psi,Psi_m,epsilon,alpha,theta,pi_ss,delta,xi,m1,m2,taut,sigma)

options = optimset('MaxFunEvals',100000,'MaxIter',10000,'TolFun',1e-16);

initial =[log(0.5),log(0.1)]; 

ss = fsolve(@(x)solve_ss1(epsilon,pi_ss,beta,taut,sigma,m1,delta,alpha,xi,theta,exp(x(1)),exp(x(2))),initial,options);
omega1 = exp(ss(1));
omega2 = exp(ss(2));

%% 
q_ss = 1; % eq.17
pw_ss = (epsilon-1)/epsilon; % eq.9
R_ss = pi_ss/beta; % eq.4
F_omega1 = normcdf((log(omega1)+sigma^2/2)/ sigma); 
F_omega2 = normcdf((log(omega2)+sigma^2/2)/ sigma); 
g_omega1 = 1-normcdf((log(omega1)-sigma^2/2)/sigma)-(1-F_omega1)*omega1;
f_omega1 = 1/(omega1*sigma*sqrt(2*3.1416))*exp(-(log(omega1)+sigma^2/2)^2/(2*sigma^2));
int_omega1 = normcdf((log(omega1)-sigma^2/2)/sigma);
int_omega2 = normcdf((log(omega2)-sigma^2/2)/sigma);

Lambda_ss=(1-F_omega1)/(1-F_omega1-m1*omega1*f_omega1); % eq.6
Rk_ss = -Lambda_ss*(R_ss*taut*F_omega2-R_ss)/(g_omega1+Lambda_ss*omega1*(1-F_omega1)+Lambda_ss*(1-m1)*(int_omega1-int_omega2));
rk_ss=Rk_ss +delta-1; % eq.14
K_Y=(pw_ss*(1-alpha))/rk_ss; % eq.13
nb_Y = K_Y; %eq.15
n_Y = xi * Rk_ss*nb_Y*g_omega1+pw_ss*(1-theta)*alpha; % eq.18
b_Y = nb_Y - n_Y;
I_K = delta; %eq.16
I_Y = I_K*K_Y;
C_Y = 1-I_Y-Rk_ss*(nb_Y)*m1*(int_omega1-int_omega2)-Rk_ss*(nb_Y)*m2*int_omega2; %eq.19

H_ss = (pw_ss*theta*alpha/C_Y/Psi)^(1/(1+eta)); %eq.11 and 2 
Y_ss = (A_ss*K_Y^(1-alpha)*H_ss^(theta*alpha))^(1/alpha); %eq.10
K_ss = Y_ss*K_Y;
C_ss = Y_ss*C_Y;
I_ss = Y_ss*I_Y;
n_ss = Y_ss*n_Y;
b_ss = Y_ss*b_Y;
w_ss = pw_ss*theta*alpha*Y_ss/H_ss; % eq.11
we_ss = pw_ss*(1-theta)*alpha*Y_ss; % eq.12
Z_ss = omega1*Rk_ss*(n_ss+b_ss)/b_ss;
%Premium_ss = Z_ss/R_ss ; %credit premium

lambda_ss = 1/C_ss; % eq.1
d_ss = (1-taut)*b_ss; %eq.21
mh_ss = Psi_m*C_ss/(1-beta/pi_ss); %eq.3
%m_ss = d_ss/0.95; % deposit stands for 95% of M2
m_ss = mh_ss+d_ss; % eq.22  currency stands for 5% of M2
GDP_ss = C_ss+I_ss; %eq.26
brc_ss = Y_ss-C_ss-I_ss; %eq.19 bankruptcy cost

Ct = C_ss;
lambdat = lambda_ss;
Ht  = H_ss;
wt  = w_ss;
mht =  mh_ss;
pit =  pi_ss; 
Rt  =  R_ss;
Rkt  =  Rk_ss;
Zt =  Z_ss;
%Premiumt =  Premium_ss);
omega1t  =  omega1;
omega2t  =  omega2;
Lambdat  =  Lambda_ss;
nt  =  n_ss;
bt  =  b_ss;

sigmat =  sigma; 
pwt  =  pw_ss;
Yt  =  Y_ss;
Kt  =  K_ss;
At  = 1;
wet  =  we_ss;
rkt  =  rk_ss;
qt  = 1;
It  =  I_ss;
dt  =  d_ss;
mt  =  m_ss;
gmt  =  log(pi_ss);
gyt  = 0;
GDPt = GDP_ss;

end
%%











