% RBC model with EZ
% find parameters and calculate steady state 

% steady state
rk  = 1/bbeta;
Erk = 1/bbeta;
i = 1/bbeta;
pi = 1;
q = 1;

z = 0;
sig_z = mu_sig/(1-rho_sig);

m = 0;

l = l_target;

pm = 1-1/ces;

k = ( (rk - (1-ddelta))/aalpha * l^(aalpha-1) / pm )^(1/(aalpha-1));

x = ddelta*k;

y = exp(z)* k^aalpha * l^(1-aalpha);
w = (1-aalpha)*y*pm/l;

c = y - x;

% choose oomega to reach labor target level
oomega = (1 + w / c * (1-l))^(-1);

V = c^oomega * (1-l)^(1-oomega);
CE = V^(1-ggamma);


save( 'steady_state', 'V', 'c', 'y', 'l', 'CE', 'rk', 'w', 'k', 'x', 'z', 'Erk','q','sig_z', 'pi', 'i','pm','m');


% store completed parameter set 

params.bbeta     = bbeta;
params.ggamma    = ggamma;
params.ies       = ies;
params.aalpha    = aalpha;
params.ddelta    = ddelta;
params.oomega    = oomega;
params.rho_z     = rho_z;
params.rho_sig   = rho_sig;
params.v_z       = v_z;
params.cchi      = cchi;
params.sig_m     = sig_m;
params.rho       = rho;
params.phi       = phi;
params.cphi      = cphi;
params.it        = it;
params.ces       = ces;
save('ParamFile','-struct','params');