
clc
clear all

beta=0.98;%discount factor
vsigma=0.5;%Intertemporal Substitution in Consumption
gama=6;%Elascticity of Labour Supply
eta=0.333;%Relative Preference for Leisure
lamda=6;%Elasticity of demand for intermediate goods
lamdaw=8;%Elasticity of demand for intermediate goods
a=0.8;%productivity paramater

eps_max=1.36;%idiosyncratic shock maximum value
eps_min=1;%idiosyncratic shock minimum value
eps_avg=0.5*(eps_max+eps_min);


omega=0.75;%proportion of firms keeping prices fixed
omegaw=0.65;%proportion of households keeping wages fixed
k=(1-omega)*(1-omega*beta)/omega;
kw=((1-omegaw)*(1-beta*omegaw))/(omegaw*(1+gama*lamdaw));
chi=0.97;%fraction of collateral seized in case of default
rho_d=0.08;%Capital adequacy ratio
mkp=lamda/(lamda-1);
mkpw=lamdaw/(lamdaw-1);


mc=1/mkp;

epsV_min=0;
epsV_max=0;

miu_V=1;

eps_thresh_ss=((1/mkp)*eps_avg)/(chi);

PHI=(eps_thresh_ss-eps_min)/(eps_max-eps_min);                                        %prob default ss
MULTIP=(eps_thresh_ss/(eps_thresh_ss-eps_min));

iD=1/beta-1;                                                                      %deposit rate ss

z=a*eps_avg;

coeff_LLP=0;

bcc=1;

y_eff_ss=z^((1+gama)/((1/vsigma)+gama));

c_v=0;

c_0=0.25;

weight_inf=lamda/k;
weight_output=(1/vsigma)+gama;
weight_wages=lamdaw/kw;

rel_weight=weight_output/weight_inf;

kappa_cc=1;

%INITIAL GUESS VALUES

x0=[1;
    1;
    0.95;
    0.05;
    1;
    0.5;
    0.05;
    0.05;
    0.50;
    0.05;
    0.50;
    1.50;
    0.05;]

x = fsolve(@(x) TZ_FSOLVE_2014_NEW(x,beta,vsigma,gama,eta,lamda,lamdaw,a,eps_max,eps_min,eps_avg, omega,omegaw,k,kw,chi,rho_d,mkp,mkpw,mc,epsV_min,epsV_max,miu_V,eps_thresh_ss, PHI,MULTIP,iD,z,coeff_LLP,bcc,y_eff_ss,c_0,c_v,weight_inf,weight_output,weight_wages,rel_weight,kappa_cc),x0, optimset('TolFun',1e-10,'MaxIter',1000000,'MaxFunEvals',100000));
                        
%DEFINING THE SYSTEM

yss=x(1);                       
nss=x(2);
wss=x(3);
iLss=x(4);
Lss=x(5);
vss=x(6);
iVss=x(7);


Cost_Def_V_ss=x(8);
eps_thresh_V_ss=x(9);
LLP_ss=x(10);
PHI_V_ss=x(11);

Eps_thresh_new_ss=x(12);
PD_new_ss=x(13);

MULTIP_new=(x(12)/(x(12)-eps_min));               

pdss=PHI;                                                                                                                                                         %risk weight ss
zss=a*eps_avg;                                   

L_V_ss=Lss/vss;

V_L_ss=vss/Lss;

L_Y_ss=Lss/yss;

spreadss=(1+iLss)/(1+iD);


y_gap_ss=yss/y_eff_ss;

y_natural_ss=(z^((1+gama)/(vsigma+gama)))/((mkp*(1+iLss))^(1/(vsigma+gama)));

y_gap_natural=yss/y_natural_ss;



%EXPERIMENT WITH THRESHOLD BANK CAPITAL DEFAULT

%EPS_V_THRESHOLD=((1+iVss)*vss+(1+iD)*(Lss-vss))/((1+iLss)*Lss);

%PHI_V_NEW=(EPS_V_THRESHOLD-epsV_min)/(epsV_max-epsV_min);

%SAVING THE RESULTS FOR TZ_LLP_OPT and TZ_LLP_SIM DYNARE FILES



X=[beta
   vsigma
   gama
   eta
   lamda
   lamdaw
   a
   eps_max
   eps_min
   eps_avg
   omega
   omegaw
   k
   kw
   chi
   rho_d
   mkp
   mkpw
   eps_thresh_ss
   mc
   epsV_min
   epsV_max
   miu_V
   PHI
   MULTIP
   iD
   z
   coeff_LLP
   yss
   nss
   wss
   iLss
   Lss
   vss
   iVss
   Cost_Def_V_ss
   miu_V
   LLP_ss
   PHI_V_ss
   pdss
   zss
   L_V_ss
   V_L_ss
   L_Y_ss
   bcc
   y_eff_ss
   y_gap_ss
   spreadss
   c_v
   c_0
   kappa_cc
   Eps_thresh_new_ss
   PD_new_ss
   MULTIP_new
   y_gap_natural
   y_natural_ss];

save X X

