%Labor is calibrated
% keyboard
L=1/3;

Rk=1.0126;
alphap=(0.0126+delta)/alpha*Xss;
K=(alphap)^(-1/(1-alpha))*L;
I=delta*K;
Y=alphap*K;
Yss=Y;
C=(1-GYss)*Y-I;
w=Y/L*(1-alpha)/Xss;
Rdc=1;
Lambda=beta;
G=GYss*Y;
taok=0;
RkmR=1.0126-1/beta;

%CBDC parameters

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%CASH, CBDC AND LAGRANGIAN MULTIPLIERS BLOCK
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%*****************************HOME COUNTRY*********************************
F = @(x) [((C)^(rho_dc))*midc*x(5)*x(2)^(-rho_dc) - chi_dc*((2*x(1)*(Gamma - x(3)))/(x(1)+x(2))^2)-x(4)+beta*x(4)*Rdc;
          ((C)^(rho_dc))*mi*x(5)*x(1)^(-rho_dc) - chi_dc*(2*(Gamma - x(3))*(x(3)/(x(1)+x(2)) - 1/(x(1)+x(2)))) - x(4) + beta*x(4);
          x(3) - x(1)/(x(1)+x(2));
          ((C - h*C)^(-1)) - beta*h*((C - h*C)^(-1))-x(4)-x(5);
          C-(mi*x(1)^(1-rho_dc)+midc*x(2)^(1-rho_dc))^(1/(1-rho_dc))];  
%initial value for x(2) guessed at 0.5
options = optimoptions('fsolve','Display','none','FunctionTolerance',1e-8,'OptimalityTolerance',1e-8); 
[x,fval,exitflag,output,jacobian] = fsolve(F,[1 1 0.5 1 1],options); 
trs=x(3);
M=x(1);
DC=x(2);
lambda1=x(4);
gam=x(5);


%F = @(x) [1/delta*((1-GYss)*x(1)*L/(1-alpha)-C)-(x(1)/(1-alpha))^(1/alpha)*L ];
%options = optimoptions%('fsolve','Display','none','FunctionTolerance',1e-8,'OptimalityTolerance',1e-8);
%[x,fval,exitflag,output,jacobian] = fsolve(F,[1],options); 
%w=x(1);
chi=w*lambda1/(L)^phi;
S=K;
Q=1;
Qss=Q;
Sss=K;
R=1/beta;
%Gamma=trs;

%bank
MM=beta*((1-taok)*Rk-R);
aa=MM;
bb=-(1-sigma)*(theta+MM);
cc=(1-sigma)*theta;
V=(-bb-(bb^2-4*aa*cc)^(1/2))/(2*aa);
miu=MM*V;
phit=V/(theta-miu);
ksi=(1+sigma*R*(phit-1))/phit/1.0126-sigma;
N=(sigma+ksi)*Rk*S/(1+sigma*R*(phit-1));
D=(phit-1)*N;
Omega=1-sigma+sigma*(phit*miu+V);

U = (log(C - h*C)) - ((chi/(1+phi))*L^(1+phi));

%utility function
%U1 = (log(C1 - h1*C1)) - ((chi1/(1+phi1))*L1^(1+phi1)) - chi_dc1*(Gamma1-trs1)^2 ;
%U2 = (log(C2 - h2*C2)) - ((chi2/(1+phi2))*L2^(1+phi2)) - chi_dc2*(Gamma2-trs2)^2 ;


%welfare
%WEL1=U1/(1-beta1);
%WEL2=U2/(1-beta2)；

A=1;
pai=1;
X=1.05;
