% Optimality conditions

function outc = calibration4(inc)
% Define global variables
global nu kappa deltan deltak deltaz eta phiy phil thetak thetaz xi phip epsilonp bbeta zeta q lfp v psi Asteady chi;

% Store the initial guesses into these variables
R = inc(1);
c = inc(2);
pit = inc(3);
w = inc(4);
rK = inc(5);
rZ = inc(6);
K = inc(7);
Ik = inc(8);
Z = inc(9);
Iz = inc(10);
mc = inc(11);
Y = inc(12);
L = inc(13);
m = inc(14); 
x1 = inc(15);
x2 = inc(16);
vartheta = inc(17);
pistar = inc(18);
s = inc(19);
n = inc(20);
f = inc(21);
gamma = inc(22);



%f=0.6;
%f = m/s;
%q = m/v;
%chi=0.6;
%Asteady = 1;

% System of equations to solve
outc(1) = -1/R + bbeta/(pit); % bond Euler
outc(2) = -c*nu*(lfp)^(kappa)+(1-f)*chi + f*(w+bbeta*((1-f)/f)*(nu*(lfp)^(kappa)-(chi/c))*c*(1-deltan)); % optimal lfp condition
outc(3) = -1+bbeta*(rK+(1-deltak)); % rK optimality
outc(4) = -1+bbeta*(rZ+(1-deltaz)); % rZ optimality
outc(5) = -Ik + deltak*K; % K law of motion
outc(6) = -Iz + deltaz*Z; % Z law of motion
outc(7) = -w+(1-eta)*chi+eta*(mc*Asteady^(phiy)*(1-thetak)*(Y/L)^(1/phiy)*(1-thetaz)*(L/n)^(phil)+bbeta*(gamma*f/q)); % wage equation
outc(8) = -m +deltan*n; % employment law of motion +m or +f*s
outc(9) = -(gamma/q)+mc*Asteady^(phiy)*(1-thetak)*(Y/L)^(1/phiy)*(1-thetaz)*(L/n)^(phil)-w+(1-deltan)*bbeta*(gamma/q);% job creation condition
outc(10) = -x1+(1/c)*mc*Y+phip*bbeta*x1*pit^(-zeta*epsilonp+epsilonp); % x1 auxiliary variable
outc(11) = -x2+(1/c)*Y+phip*bbeta*x2*pit^(zeta-zeta*epsilonp+epsilonp-1); % x2 auxiliary variable
outc(12) = -Y+(1/vartheta)*Asteady*(thetak*(K/L)^((phiy-1)/phiy)+(1-thetak))^(phiy/(phiy-1))*(thetaz*(Z/n)^((phil-1)/phil)+(1-thetaz))^(phil/(phil-1))*n; %production fnc
outc(13) = -vartheta+(1-phip)*(pistar)^(-epsilonp)*(pit)^(epsilonp)+(pit)^(epsilonp-zeta*epsilonp)*phip*vartheta; % price dispersion
outc(14) = -(pit)^(1-epsilonp)+(1-phip)*(pistar)^(1-epsilonp)+phip*(pit)^(zeta*(1-epsilonp)); %regular price equation
outc(15) = -(pistar)+(epsilonp/(epsilonp-1))*(x1/x2)*(pit); %reset price equation
outc(16) = -L+(thetaz*Z^((phil-1)/phil)+(1-thetaz)*n^((phil-1)/phil))^(phil/(phil-1)); %labor services fnc
outc(17) = -rK+mc*Asteady^(phiy)*thetak*(Y/K)^(1/phiy); %optimal labor complement capital
outc(18) = -rZ+mc*Asteady^(phiy)*(1-thetak)*(Y/L)^(1/phiy)*thetaz*(L/Z)^(1/phil); %optimal labor substitute capital
outc(19) = -m+psi*s^(xi)*v^(1-xi);
outc(20) = -f+m/s;
outc(21) = -Y+c+Ik+Iz+gamma*v; %resource constraint
outc(22) = -q+m/v;
%outc(19) = -lfp + n + (1-f)*s;
end