clear all
close all
%addpath G:\dynare\4.4.1\matlab

alpha = 1/3;
beta = 0.985;
delta = 0.025;
eta =1;
nu =3; 
chi_N = 1;
chi_M =0.008;
theta = 0.75;
phi = 2;
F_ss = 0.01;
Sigma_ss = 0.28;
Zeta_ss = 0.06;
Rzeta_ss = 1.0092;
epsilon = 11;
gamma =1;
gammae = 0.21;
taue = 0.97;
We = 0.0783;
rho_a = 0.9;
rho_sigma = 0.9;
rho_zeta = 0.9;
rho_rzeta = 0.9;
sigma_a = 1;% 1 percent (0.01)
sigma_sigma = 1;% 1 percent (0.01)
sigma_zeta = 1;
sigma_rzeta = 1;


As = 1;
Qs = 1;
Sigmas = Sigma_ss;
Zetas =Zeta_ss;
Rzetas = Rzeta_ss;

Ksibars = exp(norminv(F_ss)*Sigmas-Sigmas^2/2);
G_ss = normcdf((log(Ksibars) + Sigmas^2/2) / Sigmas - Sigmas);
GAMMA_ss = Ksibars*(1-F_ss) + G_ss;
dF_ss = 1/(Ksibars*Sigmas)*normpdf((log(Ksibars) + Sigmas^2/2) / Sigmas);

pis = 1;
Rds = 1/beta;
Rcbs = (Rds-Rzetas*Zetas)/(1-Zetas);
lames = (1-F_ss)/(1-F_ss-gammae*Ksibars*dF_ss);
Rs = lames*Rcbs/((1-GAMMA_ss)+lames*(GAMMA_ss-gammae*G_ss));
Leverages = 1+lames*(GAMMA_ss-gammae*G_ss)/(1-GAMMA_ss);
RLs = Ksibars*Rs*Leverages/(Leverages-1);
RCBs = RLs*((GAMMA_ss-gammae*G_ss)/(Ksibars));
rs = Rs - (1-delta);

pistars = 1;
mcs = (epsilon-1)/epsilon;
ws = (1-alpha)*(alpha^alpha*mcs/(rs^alpha))^(1/(1-alpha));
K_Ns=(ws/rs)*(alpha/(1-alpha));
dps = 1;
Y_Ns = (K_Ns)^alpha;
inv_Ns = delta*(K_Ns);
C_Ns = Y_Ns-inv_Ns;
Ns = (ws/chi_N*1/((K_Ns)^alpha-delta*(K_Ns)))^(eta/(phi+eta));
Ks = K_Ns*Ns;
invs = inv_Ns*Ns;
Cs = C_Ns*Ns;
Ys = Y_Ns*Ns;
lamfs = Cs^(-eta);
x1s = lamfs*mcs*Ys/(1-theta*beta);
x2s = lamfs*Ys/(1-theta*beta);
ms = (chi_M/(Cs^(-eta)*(1-beta)))^(1/gamma);

ns = taue*(1-GAMMA_ss)*Rs*Ks +We;
Ls = (Leverages-1)*ns;


ln_lamf = log(lamfs);
ln_lame = log(lames);
ln_Y = log(Ys);
ln_C = log(Cs);
n_N = log(Ns);
ln_Rd = log(Rds);
ln_m = log(ms);
ln_R = log(Rs);
ln_Leverage = log(Leverages);
ln_RL = log(RLs);
ln_Ksibar = log(Ksibars);
ln_Sigma = log(Sigmas);
ln_pi = log(pis);
ln_pistar = log(pistars);
ln_mc = log(mcs);
ln_w = log(ws);
ln_r = log(rs);
ln_dp = log(dps);
ln_x1 = log(x1s);
ln_x2 = log(x2s);
ln_K = log(Ks);
ln_inv = log(invs);
ln_Q = log(Qs);
ln_n = log(ns);
ln_Rcb = log(Rcbs);
ln_A = log(As);
ln_Zeta = log(Zetas);
ln_Rzeta= log(Rzetas);



%save all the variables into mat file and then load in mod file
save myselfmodelindex;
