function F=fun_ss(par);
%compute the steady state of the model in a small open economy
%par=[delta, eta, alpha, psi, A,z,r_star,tau_f_star,tau_star,tau,theta,phi,sigma,Psi]

delta=par(1);
eta=par(2);
alpha=par(3);
psi=par(4);
A=par(5);
z=par(6);
r_star=par(7);
tau_f_star=par(8);
tau_star=par(9);
tau=par(10);
theta=par(11);
phi=par(12);

sigma=par(13);
Psi=par(14);

%% steady-state when household foreign bond holding is positive

c=(1+(1-tau_star)*r_star)^(1/sigma)-1;%household consumption
beta=(1+c)^(-sigma);%subjective discount factor
r=(1-tau_star)*r_star/(1-tau);%domestic interest rate
% steady-state when international constriant is not binding
if (1-tau_star)/(1-tau)<1+tau_f_star
    %---interest rate and lagrange multipliers---
    xi=1-delta*beta*(1+r);%LM of domestic constraint
    xi_star=0;%LM of international constraint
    mu=theta*xi+theta*phi*xi_star+delta*beta;%LM of production constraint
    %---quantities---
    lambda=1/c;%household marginal utility
    x1=alpha/(alpha+psi*(1-alpha));%share of labor in final good production
    x2=1-x1;%share of labor in intermediate good production
    l=(A*z^(1-alpha)*alpha*lambda*mu*x1^(alpha-1)*x2^(psi*(1-alpha))/Psi)^(1/(eta+(1-alpha)*(1-psi)));%labor supply
    l1=x1*l;%labor used in final good production
    l2=x2*l;%labor used in intermediate good production
    m=z*l2^psi;% intermediate good
    y=A*l1^alpha*m^(1-alpha);%final good
    %----prices----
    w=Psi*l^eta/lambda;%wage
    q=(1-alpha)*mu*y/m;%price of intermediate good
    %---international positions--
    b=theta*y;%entrepreneurial borrowing from domestic investors
    b_star=0;%entrepreneurial borrowing from foreign investors
    c_e=y*(1-mu)-b*r-b_star*(1+tau_f_star)*r_star;%entrepreneurial consumption
    B_star=(c+c_e-y)/r_star+b_star;
% steady-state when international constriant is binding
else    
    %---interest rate and lagrange multipliers---
    xi=1-delta*beta*(1+r);%LM of domestic constraint
    xi_star=delta*beta*(r-(1+tau_f_star)*r_star);%LM of international constraint
    mu=theta*xi+theta*phi*xi_star+delta*beta;%LM of production constraint
    %---quantities---
    lambda=1/c;%household marginal utility
    x1=alpha/(alpha+psi*(1-alpha));%share of labor in final good production
    x2=1-x1;%share of labor in intermediate good production
    l=(A*z^(1-alpha)*alpha*lambda*mu*x1^(alpha-1)*x2^(psi*(1-alpha))/Psi)^(1/(eta+(1-alpha)*(1-psi)));%labor supply
    l1=x1*l;%labor used in final good production
    l2=x2*l;%labor used in intermediate good production
    m=z*l2^psi;% intermediate good
    y=A*l1^alpha*m^(1-alpha);%final good
    %----prices----
    w=Psi*l^eta/lambda;%wage
    q=(1-alpha)*mu*y/m;%price of intermediate good
    %---international positions--
    b=theta*(1-psi)*y;%entrepreneurial borrowing from domestic investors
    b_star=theta*psi*y;%entrepreneurial borrowing from foreign investors
    c_e=y*(1-mu)-b*r-b_star*(1+tau_f_star)*r_star;%entrepreneurial consumption
    B_star=(c+c_e-y)/r_star+b_star;
end


%% steady-state when household foreign bond holding is zero
if B_star<0
    B_star=0;
% steady-state when international constriant is not binding
b_star=0;%entrepreneurial borrowing from foreign investors
    s=fsolve(@(x) ss_aut(par,x(1),x(2),x(3),x(4),x(5)),[l y c r mu]);
    l=s(1);
    y=s(2);
    c=s(3);
    r=s(4);
    mu=s(5);
    beta=(1+c)^(-sigma);%subjective discount factor
    xi=1-delta*beta*(1+r);%LM of domestic constraint
    xi_star=0;%LM of international constraint
    b=theta*y;%entrepreneurial borrowing from domestic investors
% steady-state when international constriant is binding
if r>(1+tau_f_star)*r_star
    s=fsolve(@(x) ss_inf(par,x(1),x(2),x(3),x(4),x(5)),[l y c r mu]);
    l=s(1);
    y=s(2);
    c=s(3);
    r=s(4);
    mu=s(5);
    beta=(1+c)^(-sigma);%subjective discount factor
    xi=1-delta*beta*(1+r);%LM of domestic constraint
    xi_star=delta*beta*(r-(1+tau_f_star)*r_star);%LM of international constraint
    b=theta*(1-psi)*y;%entrepreneurial borrowing from domestic investors
    b_star=theta*psi*y;%entrepreneurial borrowing from foreign investors
end
lambda=1/c;
x1=alpha/(alpha+psi*(1-alpha));%share of labor in final good production
x2=1-x1;%share of labor in intermediate good production
l1=x1*l;%labor used in final good production
l2=x2*l;%labor used in intermediate good production
m=z*l2^psi;% intermediate good
w=Psi*l^eta/lambda;%wage
q=(1-alpha)*mu*y/m;%price of intermediate good
c_e=y*(1-mu)-b*r-b_star*(1+tau_f_star)*r_star;%entrepreneurial consumption
end
%% welfare
U_h=(log(c)-Psi*l^(1+eta)/(1+eta));%household utility flow
F=[r xi xi_star mu lambda c l l1 l2 m y w q b b_star c_e B_star U_h beta];
end



