clc; clear all; close all

beta_p=0.99;
sigma=1; 
phi=0.2; 
delta_k=0.025; 
kappaI=2.48; 
rho_TG=0.9;




epsilon=6;

beta_e=0.99;
piss=1;
beta=0.99;
calvo=0.75;
seita=(epsilon-1)*calvo/(piss^2*(1-calvo)*(1-beta*calvo));
beta_0=0.3;
beta_1=0.3;
eita=0.3;


gss=0.2;

alpha=0.3;
delta_d=0.025;
vita=0.3;
lans=0.7;
w_d=1;

rho_g=0.9;
rho_xy=0.9;
rho_xc=0.9;
rho_rd=0.9;
rho_r=0.8;
qx_pi=2;
qx_y=2;



rd=0.04;
xy=0.8;
xc=0.8;


fe=0.4;


y=1;
L=1/3;
L_p=fe*L;
L_pf=L_p;
L_e=(1-fe)*L;
g=gss;


r_b = 1/beta_p;
q_p=1;



d_p=fe*1;
d_e=(1-fe)*1;


q_e=1;
r_k=1/beta_e-(1-delta_k);





mc=(epsilon-1)/epsilon;
k=beta_0*(1-eita)*mc*y/r_k;
k_p=fe*k;
k_e=(1-fe)*k;
i_e=delta_k*k_e;

i_p=delta_k*k_p;
w_p=(1-beta_0)*(1-eita)*mc*y/L_pf;

ivs=delta_k*k;


d_v=xy*y;

%L_ed=(1+rd)*(y*(1-(1-beta_1*eita)*mc)-((1-beta_1)*eita*mc*y/(L_e-L_ed))*L_ed)/((1-beta_1)*eita*mc*y/(L_e-L_ed))^(1/alpha)*(w_d*(1-alpha)^2*y*(1-(1-beta_1*eita)*mc)/D*((xc*(y-ivs-g-(1+rd)*(y*(1-(1-beta_1*eita)*mc)-((1-beta_1)*eita*mc*y/(L_e-L_ed))*L_ed)))/(w_d*((1+rd)*(y*(1-(1-beta_1*eita)*mc)-((1-beta_1)*eita*mc*y/(L_e-L_ed))*L_ed))^alpha*(L_ed)^(1-alpha)/delta_d))^vita)^(1/alpha);
%L_ed=4.567515531553694e-06;
L_ed=0.5*L_e;
L_ef=0.5*L_e;
%L_ef=L_e-L_ed;
w_e=(1-beta_1)*eita*mc*y/L_ef;


s=y*(1-(1-beta_1*eita)*mc)-w_e*L_ed;
s_rd=s;
c=y-ivs-g-(1+rd)*s;
d_g=xc*c;
N_d=w_d*((1+rd)*s)^alpha*(L_ed)^(1-alpha)/delta_d;
b=d_g^eita*(N_d)^(1-eita);
D=lans*d_v+(1-lans)*b;

c_p=fe*c;
c_e=(1-fe)*c;
lanta_e=(c_e)^(-sigma);
lanta_p=(c_p)^(-sigma);
%TG=fe*c+fe*k+fe*1-r_k*fe*k+r_b*fe*1-r_b*fe*1-(1-tax_w)*w_p*L_p;
TG=solve_TG(fe, c, k, r_k, r_b, gss, rd, s_rd, w_p, L_p, w_e, L_e);
%tax_w=(gss+(r_b-1)+rd*s_rd+TG)/(w_p*L_p+w_e*L_e);
tax_w=0.2;
tmp_p=lanta_p*(1-tax_w)*w_p/(L_p)^phi;
tmp_e=lanta_e*(1-tax_w)*w_e/(L_e)^phi;



save par beta_p sigma phi tax_w delta_k kappaI rho_TG TG epsilon beta_e ...
     calvo seita beta_0 beta_1 eita piss gss alpha delta_d vita lans w_d... 
     rho_g rho_xy rho_xc rho_rd rho_r qx_pi qx_y y rd xy xc fe tmp_e tmp_p
