function [fval] = sfile(z)
global M_ 
%%
NumberOfParameters = M_.param_nbr;                            % Number of deep parameters.
for i = 1:NumberOfParameters                                  % Loop...
  paramname = deblank(M_.param_names(i,:));                   %    Get the name of parameter i. 
  eval([ paramname ' = M_.params(' int2str(i) ');']);         %    Get the value of parameter i.
end   
%%
%%
Y_H =z(1);
Y_U =z(2);
P_sc_H=z(3);
P_sc_U=z(4);
% Bs_H = z(6);
% Bs_U = z(7);
%%
%% Exchange rates
%%
rer_H      =   1;
rer_U      =   1/rer_H;
%%
%% Home
%%
%%
P_sd_H = 1;

P_sm_H      =	rer_H*P_sc_H/P_sc_U;

fval(3) = P_sc_H - (   (1-dlt_mc_H)*P_sd_H^(r_c/(r_c-1))   +   dlt_mc_H*P_sm_H^(r_c/(r_c-1))  )^((r_c-1)/r_c);
P_si_H =  P_sc_H;%(   (1-dlt_i_H)*P_sd_H^(r_c / (r_c-1))  +   dlt_i_H*P_sm_H^(r_c /(r_c-1))  )^((r_c-1)/r_c);

r_k_H = P_si_H*(1/betta_H - (1-dlt));

% lmbd_sv_H = ((0.5^(r_o/(r_o-1)) -   dlt_oy_H*P_so_H^(r_o/(r_o-1)))/(1-dlt_oy_H))^((r_o-1)/r_o);
w_H       = (   (.5^(r_v/(r_v-1))    -   (1-dlt_l_H)*r_k_H^(r_v/(r_v-1)))/dlt_l_H  )^((r_v-1)/r_v);

%lmbd_sv_H =  (   (1-dlt_l_H)*r_k_H^(r_v/(r_v-1))    +   dlt_l_H*w_H^(r_v/(r_v-1))  )^((r_v-1)/r_v);
% mc_H      =  ((1-dlt_oy_H)*lmbd_sv_H^(r_o/(r_o-1))   +   dlt_oy_H*P_so_H^(r_o/(r_o-1))  )^((r_o-1)/r_o);
mc_H =  (   (1-dlt_l_H)*r_k_H^(r_v/(r_v-1))    +   dlt_l_H*w_H^(r_v/(r_v-1))  )^((r_v-1)/r_v);

% VA_H =   (1-dlt_oy_H)*(mc_H /lmbd_sv_H)^(1/(1-r_o))*Y_H;
K_H  =   (1-dlt_l_H)*(mc_H/r_k_H)^(1/(1-r_v))*Y_H;
L_H  =  dlt_l_H*(mc_H/ w_H)^(1/(1-r_v))*Y_H;

theta_w_H=1;
psi_w_H	=	(1+theta_w_H)/theta_w_H;
w_f_H = w_H*(psi_w_H-1)/psi_w_H; 
C_H = (chi0*(P_sc_H /w_f_H)*(1-L_H)^(-chi))^(-1 /sig)*(1 /(1-kappa));
% C_no_H =   (1-dlt_oc_H)*(P_sc_H /P_sno_H)^(1/(1-r_o))*C_H;
C_d_H =   (1-dlt_mc_H)*(P_sc_H)^(1/(1-r_c))*C_H;

I_H=dlt*K_H; 
I_d_H =  (1-dlt_i_H)*(P_si_H)^(1/(1-r_c))*I_H;

M_c_H   = dlt_mc_H*(P_sc_H/P_sm_H)^(1/(1-r_c))*C_H;
M_i_H   = dlt_i_H*(P_si_H/P_sm_H)^(1/(1-r_c))*I_H;
M_H = P_sm_H*(M_i_H + M_c_H);

G_d_H = g_H*Y_H;


%%
%%
P_sd_U = 1;
P_sm_U		=	rer_U*P_sc_U/P_sc_H;

% P_si_U =  (   (1-dlt_i_U)*P_sd_U^(r_c / (r_c-1))  +   dlt_i_U*P_sm_U^(r_c /(r_c-1))  )^((r_c-1)/r_c);


fval(4) = P_sc_U -  (   (1-dlt_mc_U)*P_sd_U^(r_c/(r_c-1))   +   dlt_mc_U*P_sm_U^(r_c/(r_c-1))  )^((r_c-1)/r_c);
P_si_U =P_sc_U;
r_k_U = P_si_U*(1/betta_U - (1-dlt));

w_U       = (   (.5^(r_v/(r_v-1))    -   (1-dlt_l_U)*r_k_U^(r_v/(r_v-1)))/dlt_l_U  )^((r_v-1)/r_v);

%lmbd_sv_U =  (   (1-dlt_l_U)*r_k_U^(r_v/(r_v-1))    +   dlt_l_U*w_U^(r_v/(r_v-1))  )^((r_v-1)/r_v);
% mc_U      =  ((1-dlt_oy_U)*lmbd_sv_U^(r_o/(r_o-1))   +   dlt_oy_U*P_so_U^(r_o/(r_o-1))  )^((r_o-1)/r_o);
mc_U =  (   (1-dlt_l_U)*r_k_U^(r_v/(r_v-1))    +   dlt_l_U*w_U^(r_v/(r_v-1))  )^((r_v-1)/r_v);


K_U  =   (1-dlt_l_U)*(mc_U/r_k_U)^(1/(1-r_v))*Y_U;
L_U  =  dlt_l_U*(mc_U/ w_U)^(1/(1-r_v))*Y_U;

theta_w_U=1;
psi_w_U	=	(1+theta_w_U)/theta_w_U;
w_f_U = w_U*(psi_w_U-1)/psi_w_U;
C_U = (chi0*(P_sc_U /w_f_U)*(1-L_U)^(-chi))^(-1 /sig)*(1 /(1-kappa));
C_d_U =   (1-dlt_mc_U)*(P_sc_U)^(1/(1-r_c))*C_U;

I_U=dlt*K_U;
I_d_U =  (1-dlt_i_U)*(P_si_U)^(1/(1-r_c))*I_U;

M_c_U   = dlt_mc_U*(P_sc_U/P_sm_U)^(1/(1-r_c))*C_U;
M_i_U   = dlt_i_U*(P_si_U/P_sm_U)^(1/(1-r_c))*I_U;
M_U = P_sm_U*(M_i_U + M_c_U);

G_d_U = g_U*Y_U;

%%
%%
X_H = M_U;
X_U = M_H;
% 
% NTs_H	=	(X_H	-	M_H)	+	P_so_H*O_U;
% NTs_U	=	(X_U	-	M_U )	-	P_so_U*O_U;
% 
% P_b_H = betta_H;     P_b_U = betta_U;     
% phi_b_H = exp(-phi_b*Bs_H);
% phi_b_U = exp(-phi_b*Bs_U);
% 
% fval(6) = Bs_H - NTs_H/(P_b_U/phi_b_H - 1);
% fval(7) = Bs_U - NTs_U/(P_b_H/phi_b_U - 1);
%%
%%

fval(1) = Y_H - C_d_H - I_d_H - G_d_H - (X_H );

fval(2) =  Y_U - C_d_U - I_d_U - G_d_U - (X_U );



