clear all;
close all;
%addpath G:\dynare\4.4.1\matlab
beta = 0.995;
sigma=2;
alpha=0.5;
alphag=0.01;
theta=0.5;
deltap = 0.035;
deltag =0.035;
psi=1;
kai=1;
kaip=22;
epsp = 10;
phipi=0.75;
phiy=0.8;
phigama = 0;
rhom = 0.9;
rhoy=0.03;
rhopi=0.67;
rhoa =0.95;
rhog=0.9;
rhosigmap=0.97;
rhosigmag=0.97;
g=1.015;
as =1;
pis = 1.005; %zeros inflation steady state
Rs = pis*g/beta; %nominal interest rate
qs=1;
xs = epsp/(epsp-1);
xgs=xs;
gamas=0.15;
Rgs=(Rs-1)/(1-gamas)+1;
Rps=(Rs-1)/(1-gamas)+1;
hs=0.3333;
rks =g/beta-1+deltap;
Aps=1.03686;
Ags=1.0365;
kg_kp=0.31;
kps=(Aps*xs*rks/((1-alpha)*hs^alpha*kg_kp^alphag))^(1/(alphag-alpha));
invps=(1-(1-deltap)/g)*kps;
kgs=kps*kg_kp;
invgs=deltag*kgs;
ys =kps^(1-alpha)*hs^alpha*kgs^alphag;
ws=(ys/(Aps*xs))*alpha/hs;
omegags=0.14;
sp=Aps/Rps;%risk spread
sg=Ags/Rgs;%risk spread
mup=0.21;%monitor cost
Fomegabarp=0.005; %bankruptancy rate are set.
mug=0.21;%monitor cost
Fomegabarg=0.006; %bankruptancy rate are set.
lp=0;
lg=0.15;
%when given Fomega,mu and spread, solve omega, then sigma
[sigmaps,omegabarps,Gamma_p,Gam_muG,ixx] = get_omega_cond_Fomegabar(sp,Fomegabarp,mup,lp);

z_p        = (log(omegabarps) + sigmaps^2 / 2) / sigmaps; 
F_p         = normcdf(z_p);
G_p          = normcdf(z_p - sigmaps);
f_p         = 1-G_p-omegabarps*(1-F_p);
df_p        =-normpdf(z_p-sigmaps)/(sigmaps*omegabarps)-(1-F_p)+normpdf(z_p)/sigmaps;
g_p         =(1-F_p)*omegabarps+(1-(1-lp)*mup)*G_p; 
dg_p        =1-F_p-normpdf(z_p)/sigmaps+(1-(1-lp)*mup)*normpdf(z_p-sigmaps)/(sigmaps*omegabarps);

leverage_p=((Rps/(Aps*g_p))-1)*pis*g; %bank zero profit condition
bps=(ys/(Aps*xs))/(1+leverage_p/(pis*g));
bankruptps = F_p;
nps=bps*leverage_p;
gammap=nps/(Aps*(nps/(pis*g)+bps)*f_p);
%D_p         =  Aps*mup*(nps/(pis*g)+bps)*G_p;



[sigmags,omegabargs,Gamma_g,Gam_muG,ixx] = get_omega_cond_Fomegabar(sg,Fomegabarg,mug,lg);

z_g        = (log(omegabargs) + sigmags^2 / 2) / sigmags; 
F_g         = normcdf(z_g);
G_g          = normcdf(z_g - sigmags);
f_g         = 1-G_g-omegabargs*(1-F_g);
df_g        =-normpdf(z_g-sigmags)/(sigmags*omegabargs)-(1-F_g)+normpdf(z_g)/sigmags;
g_g         =(1-F_g)*omegabargs+(1-(1-lg)*mug)*G_g; 
dg_g        =1-F_g-normpdf(z_g)/sigmags+(1-(1-lg)*mug)*normpdf(z_g-sigmags)/(sigmags*omegabargs);

leverage_g=((Rgs/(Ags*g_g))-1)*pis*g; %bank zero profit condition
bgs=(invgs/(Ags*xgs))/(1+leverage_g/(pis*g));
bankruptgs = F_g;
ngs=bgs*leverage_g;
ygs=theta*(ngs/(pis*g)+bgs);
Ls=(invgs/(ygs^theta))^(1/(1-theta));
pls=(1-theta)*(ngs/(pis*g)+bgs)/Ls;
gammag=(ngs)/(Ags*(ngs/(pis*g)+bgs)*f_g);


Govs=omegags*ys;
Cs=ys-invps-ygs-Govs;
phi=ws/(hs^sigma*Cs);
ms=psi/((1/Cs)*(Rs-1)/Rs);
mpbar=1.18;
mps=pis*mpbar;
%save all the variables into mat file and then load in mod file
save mpa;
dynare mpa;

save irfresult;

IRF_periods=30;
t=(1:30)';
hh=1;
figure(hh) 
subplot(4,4,1)
hold on
plot(t,y_ea,'b-','LineWidth',2);
plot(zeros(IRF_periods,1),'k--','HandleVisibility','off'); xlim([1 IRF_periods]);set(gca,'XTick',[4:4:IRF_periods],'FontSize',12);
title('GDP','FontSize',10)
ylabel('Percent','FontSize',9)
legend('TFP shock')

subplot(4,4,2)
hold on
plot(t,C_ea,'b-','LineWidth',2)
plot(zeros(IRF_periods,1),'k--','HandleVisibility','off'); xlim([1 IRF_periods]);set(gca,'XTick',[4:4:IRF_periods],'FontSize',12);
title('Consumption','FontSize',10)
ylabel('Percent','FontSize',9)
  
subplot(4,4,3)
hold on
plot(t,pi_ea,'b-','LineWidth',2)
plot(zeros(IRF_periods,1),'k--','HandleVisibility','off'); xlim([1 IRF_periods]);set(gca,'XTick',[4:4:IRF_periods],'FontSize',12);
title('Inflation','FontSize',10)
ylabel('Percent','FontSize',9)
 
subplot(4,4,4)
hold on
plot(t,h_em,'b-','LineWidth',2)
plot(zeros(IRF_periods,1),'k--','HandleVisibility','off'); xlim([1 IRF_periods]);set(gca,'XTick',[4:4:IRF_periods],'FontSize',12);
title('Hours','FontSize',10)
ylabel('Percent','FontSize',9)

  
subplot(4,4,5)
hold on
plot(t,mp_ea,'b-','LineWidth',2)
plot(zeros(IRF_periods,1),'k--','HandleVisibility','off'); xlim([1 IRF_periods]);set(gca,'XTick',[4:4:IRF_periods],'FontSize',12);
title('M2 Growth','FontSize',10)
ylabel('Percent','FontSize',9)


  
subplot(4,4,6)
hold on
plot(t,gama_ea,'b-','LineWidth',2)
plot(zeros(IRF_periods,1),'k--','HandleVisibility','off'); xlim([1 IRF_periods]);set(gca,'XTick',[4:4:IRF_periods],'FontSize',12);
title('Reserve rate','FontSize',10)
ylabel('Percent','FontSize',9)

 
subplot(4,4,7)
hold on
plot(t,R_ea,'b-','LineWidth',2)
plot(zeros(IRF_periods,1),'k--','HandleVisibility','off'); xlim([1 IRF_periods]);set(gca,'XTick',[4:4:IRF_periods],'FontSize',12);
title('Interest Rate','FontSize',10)
ylabel('Percent','FontSize',9)

   
subplot(4,4,8)
hold on
plot(t,q_ea,'b-','LineWidth',2)
plot(zeros(IRF_periods,1),'k--','HandleVisibility','off'); xlim([1 IRF_periods]);set(gca,'XTick',[4:4:IRF_periods],'FontSize',12);
title('Asset price','FontSize',10)
ylabel('Percent','FontSize',9)

   
subplot(4,4,9)
hold on
plot(t,invp_ea,'b-','LineWidth',2)
plot(zeros(IRF_periods,1),'k--','HandleVisibility','off'); xlim([1 IRF_periods]);set(gca,'XTick',[4:4:IRF_periods],'FontSize',12);
title('Private Investment','FontSize',10)
ylabel('Percent','FontSize',9)

subplot(4,4,10)
hold on
plot(t,invg_ea,'b-','LineWidth',2)
plot(zeros(IRF_periods,1),'k--','HandleVisibility','off'); xlim([1 IRF_periods]);set(gca,'XTick',[4:4:IRF_periods],'FontSize',12);
title('Public Investment','FontSize',10)
ylabel('Percent','FontSize',9)

subplot(4,4,11)
hold on
plot(t,np_em,'b-','LineWidth',2)
plot(zeros(IRF_periods,1),'k--','HandleVisibility','off'); xlim([1 IRF_periods]);set(gca,'XTick',[4:4:IRF_periods],'FontSize',12);
title('Firm net worth','FontSize',10)
ylabel('Percent','FontSize',9)

subplot(4,4,12)
hold on
plot(t,ng_ea,'b-','LineWidth',2)
plot(zeros(IRF_periods,1),'k--','HandleVisibility','off'); xlim([1 IRF_periods]);set(gca,'XTick',[4:4:IRF_periods],'FontSize',12);
title('LGVC net worth','FontSize',10)
ylabel('Percent','FontSize',9)


   
subplot(4,4,13)
hold on
plot(t,bp_ea,'b-','LineWidth',2)
plot(zeros(IRF_periods,1),'k--','HandleVisibility','off'); xlim([1 IRF_periods]);set(gca,'XTick',[4:4:IRF_periods],'FontSize',12);
title('Firm Debt','FontSize',10)
ylabel('Percent','FontSize',9)

   
subplot(4,4,14)
hold on
plot(t,bg_ea,'b-','LineWidth',2)
plot(zeros(IRF_periods,1),'k--','HandleVisibility','off'); xlim([1 IRF_periods]);set(gca,'XTick',[4:4:IRF_periods],'FontSize',12);
title('LGFC Debt','FontSize',10)
ylabel('Percent','FontSize',9)



subplot(4,4,15)
hold on
plot(t,bankruptp_ea,'b-','LineWidth',2)
plot(zeros(IRF_periods,1),'k--','HandleVisibility','off'); xlim([1 IRF_periods]);set(gca,'XTick',[4:4:IRF_periods],'FontSize',12);
title('Firm Default rate','FontSize',10)
ylabel('Percent','FontSize',9)


subplot(4,4,16)
hold on
plot(t,bankruptg_em,'b-','LineWidth',2)
plot(zeros(IRF_periods,1),'k--','HandleVisibility','off'); xlim([1 IRF_periods]);set(gca,'XTick',[4:4:IRF_periods],'FontSize',12);
title('LGVC Default_rate','FontSize',10)
ylabel('Percent','FontSize',9)

hh=2;
figure(hh)
subplot(4,4,1)
hold on
plot(t,y_em,'b-','LineWidth',2);
plot(zeros(IRF_periods,1),'k--','HandleVisibility','off'); xlim([1 IRF_periods]);set(gca,'XTick',[4:4:IRF_periods],'FontSize',12);
title('GDP','FontSize',10)
ylabel('Percent','FontSize',9)
legend('Monetary policy shock')

   
subplot(4,4,2)
hold on
plot(t,C_em,'b-','LineWidth',2)
plot(zeros(IRF_periods,1),'k--','HandleVisibility','off'); xlim([1 IRF_periods]);set(gca,'XTick',[4:4:IRF_periods],'FontSize',12);
title('Consumption','FontSize',10)
ylabel('Percent','FontSize',9)

  
subplot(4,4,3)
hold on
plot(t,pi_em,'b-','LineWidth',2)
plot(zeros(IRF_periods,1),'k--','HandleVisibility','off'); xlim([1 IRF_periods]);set(gca,'XTick',[4:4:IRF_periods],'FontSize',12);
title('Inflation','FontSize',10)
ylabel('Percent','FontSize',9)

   
subplot(4,4,4)
hold on
plot(t,h_em,'b-','LineWidth',2)
plot(zeros(IRF_periods,1),'k--','HandleVisibility','off'); xlim([1 IRF_periods]);set(gca,'XTick',[4:4:IRF_periods],'FontSize',12);
title('Hours','FontSize',10)
ylabel('Percent','FontSize',9)

subplot(4,4,5)
hold on
plot(t,mp_em,'b-','LineWidth',2)
plot(zeros(IRF_periods,1),'k--','HandleVisibility','off'); xlim([1 IRF_periods]);set(gca,'XTick',[4:4:IRF_periods],'FontSize',12);
title('M2_Growth','FontSize',10)
ylabel('Percent','FontSize',9)

subplot(4,4,6)
hold on
plot(t,gama_em,'b-','LineWidth',2)
plot(zeros(IRF_periods,1),'k--','HandleVisibility','off'); xlim([1 IRF_periods]);set(gca,'XTick',[4:4:IRF_periods],'FontSize',12);
title('Reserve rate','FontSize',10)
ylabel('Percent','FontSize',9)

  
subplot(4,4,7)
hold on
plot(t,R_em,'b-','LineWidth',2)
plot(zeros(IRF_periods,1),'k--','HandleVisibility','off'); xlim([1 IRF_periods]);set(gca,'XTick',[4:4:IRF_periods],'FontSize',12);
title('Interest Rate','FontSize',10)
ylabel('Percent','FontSize',9)
  
subplot(4,4,8)
hold on
plot(t,q_em,'b-','LineWidth',2)
plot(zeros(IRF_periods,1),'k--','HandleVisibility','off'); xlim([1 IRF_periods]);set(gca,'XTick',[4:4:IRF_periods],'FontSize',12);
title('Asset price','FontSize',10)
ylabel('Percent','FontSize',9)

 
subplot(4,4,9)
hold on
plot(t,invp_em,'b-','LineWidth',2)
plot(zeros(IRF_periods,1),'k--','HandleVisibility','off'); xlim([1 IRF_periods]);set(gca,'XTick',[4:4:IRF_periods],'FontSize',12);
title('Private Investment','FontSize',10)
ylabel('Percent','FontSize',9)

subplot(4,4,10)
hold on
plot(t,invg_em,'b-','LineWidth',2)
plot(zeros(IRF_periods,1),'k--','HandleVisibility','off'); xlim([1 IRF_periods]);set(gca,'XTick',[4:4:IRF_periods],'FontSize',12);
title('Public Investment','FontSize',10)
ylabel('Percent','FontSize',9)

subplot(4,4,11)
hold on
plot(t,np_em,'b-','LineWidth',2)
plot(zeros(IRF_periods,1),'k--','HandleVisibility','off'); xlim([1 IRF_periods]);set(gca,'XTick',[4:4:IRF_periods],'FontSize',12);
title('Firm net worth','FontSize',10)
ylabel('Percent','FontSize',9)

subplot(4,4,12)
hold on
plot(t,ng_em,'b-','LineWidth',2)
plot(zeros(IRF_periods,1),'k--','HandleVisibility','off'); xlim([1 IRF_periods]);set(gca,'XTick',[4:4:IRF_periods],'FontSize',12);
title('LGVC net worth','FontSize',10)
ylabel('Percent','FontSize',9)


   
subplot(4,4,13)
hold on
plot(t,bp_em,'b-','LineWidth',2)
plot(zeros(IRF_periods,1),'k--','HandleVisibility','off'); xlim([1 IRF_periods]);set(gca,'XTick',[4:4:IRF_periods],'FontSize',12);
title('Firm Debt','FontSize',10)
ylabel('Percent','FontSize',9)

subplot(4,4,14)
hold on
plot(t,bg_em,'b-','LineWidth',2)
plot(zeros(IRF_periods,1),'k--','HandleVisibility','off'); xlim([1 IRF_periods]);set(gca,'XTick',[4:4:IRF_periods],'FontSize',12);
title('LGFC Debt','FontSize',10)
ylabel('Percent','FontSize',9)
  
subplot(4,4,15)
hold on
plot(t,bankruptp_em,'b-','LineWidth',2)
plot(zeros(IRF_periods,1),'k--','HandleVisibility','off'); xlim([1 IRF_periods]);set(gca,'XTick',[4:4:IRF_periods],'FontSize',12);
title('Firm Default rate','FontSize',10)
ylabel('Percent','FontSize',9)
  
subplot(4,4,16)
hold on
plot(t,bankruptg_em,'b-','LineWidth',2)
plot(zeros(IRF_periods,1),'k--','HandleVisibility','off'); xlim([1 IRF_periods]);set(gca,'XTick',[4:4:IRF_periods],'FontSize',12);
title('LGVC Default rate','FontSize',10)
ylabel('Percent','FontSize',9)

hh=3;
figure(hh)  
subplot(4,4,1)
hold on
plot(t,y_egama,'b-','LineWidth',2);
plot(zeros(IRF_periods,1),'k--','HandleVisibility','off'); xlim([1 IRF_periods]);set(gca,'XTick',[4:4:IRF_periods],'FontSize',12);
title('GDP','FontSize',10)
ylabel('Percent','FontSize',9)

 
subplot(4,4,2)
hold on
plot(t,C_egama,'b-','LineWidth',2)
plot(zeros(IRF_periods,1),'k--','HandleVisibility','off'); xlim([1 IRF_periods]);set(gca,'XTick',[4:4:IRF_periods],'FontSize',12);
title('Consumption','FontSize',10)
ylabel('Percent','FontSize',9)
   
subplot(4,4,3)
hold on
plot(t,pi_egama,'b-','LineWidth',2)
plot(zeros(IRF_periods,1),'k--','HandleVisibility','off'); xlim([1 IRF_periods]);set(gca,'XTick',[4:4:IRF_periods],'FontSize',12);
title('Inflation','FontSize',10)
ylabel('Percent','FontSize',9)

  
subplot(4,4,4)
hold on
plot(t,h_egama,'b-','LineWidth',2)
plot(zeros(IRF_periods,1),'k--','HandleVisibility','off'); xlim([1 IRF_periods]);set(gca,'XTick',[4:4:IRF_periods],'FontSize',12);
title('Hours','FontSize',10)
ylabel('Percent','FontSize',9)

   
subplot(4,4,5)
hold on
plot(t,mp_egama,'b-','LineWidth',2)
plot(zeros(IRF_periods,1),'k--','HandleVisibility','off'); xlim([1 IRF_periods]);set(gca,'XTick',[4:4:IRF_periods],'FontSize',12);
title('M2 Growth','FontSize',10)
ylabel('Percent','FontSize',9)

 
subplot(4,4,6)
hold on
plot(t,gama_egama,'b-','LineWidth',2)
plot(zeros(IRF_periods,1),'k--','HandleVisibility','off'); xlim([1 IRF_periods]);set(gca,'XTick',[4:4:IRF_periods],'FontSize',12);
title('Reserve rate','FontSize',10)
ylabel('Percent','FontSize',9)
  
subplot(4,4,7)
hold on
plot(t,R_egama,'b-','LineWidth',2)
plot(zeros(IRF_periods,1),'k--','HandleVisibility','off'); xlim([1 IRF_periods]);set(gca,'XTick',[4:4:IRF_periods],'FontSize',12);
title('Interest Rate','FontSize',10)
ylabel('Percent','FontSize',9)
 
subplot(4,4,8)
hold on
plot(t,q_egama,'b-','LineWidth',2)
plot(zeros(IRF_periods,1),'k--','HandleVisibility','off'); xlim([1 IRF_periods]);set(gca,'XTick',[4:4:IRF_periods],'FontSize',12);
title('Asset price','FontSize',10)
ylabel('Percent','FontSize',9)

 
subplot(4,4,9)
hold on
plot(t,invp_egama,'b-','LineWidth',2)
plot(zeros(IRF_periods,1),'k--','HandleVisibility','off'); xlim([1 IRF_periods]);set(gca,'XTick',[4:4:IRF_periods],'FontSize',12);
title('Private Investment','FontSize',10)
ylabel('Percent','FontSize',9)

subplot(4,4,10)
hold on
plot(t,invg_egama,'b-','LineWidth',2)
plot(zeros(IRF_periods,1),'k--','HandleVisibility','off'); xlim([1 IRF_periods]);set(gca,'XTick',[4:4:IRF_periods],'FontSize',12);
title('Public Investment','FontSize',10)
ylabel('Percent','FontSize',9)

subplot(4,4,11)
hold on
plot(t,np_egama,'b-','LineWidth',2)
plot(zeros(IRF_periods,1),'k--','HandleVisibility','off'); xlim([1 IRF_periods]);set(gca,'XTick',[4:4:IRF_periods],'FontSize',12);
title('Firm net worth','FontSize',10)
ylabel('Percent','FontSize',9)

subplot(4,4,12)
hold on
plot(t,ng_egama,'b-','LineWidth',2)
plot(zeros(IRF_periods,1),'k--','HandleVisibility','off'); xlim([1 IRF_periods]);set(gca,'XTick',[4:4:IRF_periods],'FontSize',12);
title('LGVC net worth','FontSize',10)
ylabel('Percent','FontSize',9)

 
subplot(4,4,13)
hold on
plot(t,bp_egama,'b-','LineWidth',2)
plot(zeros(IRF_periods,1),'k--','HandleVisibility','off'); xlim([1 IRF_periods]);set(gca,'XTick',[4:4:IRF_periods],'FontSize',12);
title('Firm Debt','FontSize',10)
ylabel('Percent','FontSize',9)
  
subplot(4,4,14)
hold on
plot(t,bg_egama,'b-','LineWidth',2)
plot(zeros(IRF_periods,1),'k--','HandleVisibility','off'); xlim([1 IRF_periods]);set(gca,'XTick',[4:4:IRF_periods],'FontSize',12);
title('LGFC Debt','FontSize',10)
ylabel('Percent','FontSize',9)
   
subplot(4,4,15)
hold on
plot(t,bankruptp_egama,'b-','LineWidth',2)
plot(zeros(IRF_periods,1),'k--','HandleVisibility','off'); xlim([1 IRF_periods]);set(gca,'XTick',[4:4:IRF_periods],'FontSize',12);
title('Firm Default rate','FontSize',10)
ylabel('Percent','FontSize',9)

figure(hh)   
subplot(4,4,16)
hold on
plot(t,bankruptg_egama,'b-','LineWidth',2)
plot(zeros(IRF_periods,1),'k--','HandleVisibility','off'); xlim([1 IRF_periods]);set(gca,'XTick',[4:4:IRF_periods],'FontSize',12);
title('LGVC Default rate','FontSize',10)
ylabel('Percent','FontSize',9)

hh=4;
figure(hh)
subplot(4,4,1)
hold on
plot(t,y_esigmap,'b-','LineWidth',2);
plot(zeros(IRF_periods,1),'k--','HandleVisibility','off'); xlim([1 IRF_periods]);set(gca,'XTick',[4:4:IRF_periods],'FontSize',12);
title('GDP','FontSize',10)
ylabel('Percent','FontSize',9)
legend('Firm Risk shock')

   
subplot(4,4,2)
hold on
plot(t,C_esigmap,'b-','LineWidth',2)
plot(zeros(IRF_periods,1),'k--','HandleVisibility','off'); xlim([1 IRF_periods]);set(gca,'XTick',[4:4:IRF_periods],'FontSize',12);
title('Consumption','FontSize',10)
ylabel('Percent','FontSize',9)

subplot(4,4,3)
hold on
plot(t,pi_esigmap,'b-','LineWidth',2)
plot(zeros(IRF_periods,1),'k--','HandleVisibility','off'); xlim([1 IRF_periods]);set(gca,'XTick',[4:4:IRF_periods],'FontSize',12);
title('Inflation','FontSize',10)
ylabel('Percent','FontSize',9)
 
subplot(4,4,4)
hold on
plot(t,h_esigmap,'b-','LineWidth',2)
plot(zeros(IRF_periods,1),'k--','HandleVisibility','off'); xlim([1 IRF_periods]);set(gca,'XTick',[4:4:IRF_periods],'FontSize',12);
title('Hours','FontSize',10)
ylabel('Percent','FontSize',9)

 
subplot(4,4,5)
hold on
plot(t,mp_esigmap,'b-','LineWidth',2)
plot(zeros(IRF_periods,1),'k--','HandleVisibility','off'); xlim([1 IRF_periods]);set(gca,'XTick',[4:4:IRF_periods],'FontSize',12);
title('M2 Growth','FontSize',10)
ylabel('Percent','FontSize',9)



subplot(4,4,6)
hold on
plot(t,gama_esigmap,'b-','LineWidth',2)
plot(zeros(IRF_periods,1),'k--','HandleVisibility','off'); xlim([1 IRF_periods]);set(gca,'XTick',[4:4:IRF_periods],'FontSize',12);
title('Reserve rate','FontSize',10)
ylabel('Percent','FontSize',9)

 
subplot(4,4,7)
hold on
plot(t,R_esigmap,'b-','LineWidth',2)
plot(zeros(IRF_periods,1),'k--','HandleVisibility','off'); xlim([1 IRF_periods]);set(gca,'XTick',[4:4:IRF_periods],'FontSize',12);
title('Interest Rate','FontSize',10)
ylabel('Percent','FontSize',9)

   
subplot(4,4,8)
hold on
plot(t,q_esigmap,'b-','LineWidth',2)
plot(zeros(IRF_periods,1),'k--','HandleVisibility','off'); xlim([1 IRF_periods]);set(gca,'XTick',[4:4:IRF_periods],'FontSize',12);
title('Asset price','FontSize',10)
ylabel('Percent','FontSize',9)

  
subplot(4,4,9)
hold on
plot(t,invp_esigmap,'b-','LineWidth',2)
plot(zeros(IRF_periods,1),'k--','HandleVisibility','off'); xlim([1 IRF_periods]);set(gca,'XTick',[4:4:IRF_periods],'FontSize',12);
title('Private Investment','FontSize',10)
ylabel('Percent','FontSize',9)

subplot(4,4,10)
hold on
plot(t,invg_esigmap,'b-','LineWidth',2)
plot(zeros(IRF_periods,1),'k--','HandleVisibility','off'); xlim([1 IRF_periods]);set(gca,'XTick',[4:4:IRF_periods],'FontSize',12);
title('Public Investment','FontSize',10)
ylabel('Percent','FontSize',9)

subplot(4,4,11)
hold on
plot(t,np_esigmap,'b-','LineWidth',2)
plot(zeros(IRF_periods,1),'k--','HandleVisibility','off'); xlim([1 IRF_periods]);set(gca,'XTick',[4:4:IRF_periods],'FontSize',12);
title('Firm net worth','FontSize',10)
ylabel('Percent','FontSize',9)

subplot(4,4,12)
hold on
plot(t,ng_esigmap,'b-','LineWidth',2)
plot(zeros(IRF_periods,1),'k--','HandleVisibility','off'); xlim([1 IRF_periods]);set(gca,'XTick',[4:4:IRF_periods],'FontSize',12);
title('LGVC net worth','FontSize',10)
ylabel('Percent','FontSize',9)

  
subplot(4,4,13)
hold on
plot(t,bp_esigmap,'b-','LineWidth',2)
plot(zeros(IRF_periods,1),'k--','HandleVisibility','off'); xlim([1 IRF_periods]);set(gca,'XTick',[4:4:IRF_periods],'FontSize',12);
title('Firm Debt','FontSize',10)
ylabel('Percent','FontSize',9)
   
subplot(4,4,14)
hold on
plot(t,bg_esigmap,'b-','LineWidth',2)
plot(zeros(IRF_periods,1),'k--','HandleVisibility','off'); xlim([1 IRF_periods]);set(gca,'XTick',[4:4:IRF_periods],'FontSize',12);
title('LGFC Debt','FontSize',10)
ylabel('Percent','FontSize',9)

   
subplot(4,4,15)
hold on
plot(t,bankruptp_esigmap,'b-','LineWidth',2)
plot(zeros(IRF_periods,1),'k--','HandleVisibility','off'); xlim([1 IRF_periods]);set(gca,'XTick',[4:4:IRF_periods],'FontSize',12);
title('Firm Default rate','FontSize',10)
ylabel('Percent','FontSize',9)
  
subplot(4,4,16)
hold on
plot(t,bankruptg_esigmap,'b-','LineWidth',2)
plot(zeros(IRF_periods,1),'k--','HandleVisibility','off'); xlim([1 IRF_periods]);set(gca,'XTick',[4:4:IRF_periods],'FontSize',12);
title('LGVC Default rate','FontSize',10)
ylabel('Percent','FontSize',9)

hh=5;
figure(hh) 
subplot(4,4,1)
hold on
plot(t,y_esigmag,'b-','LineWidth',2);
plot(zeros(IRF_periods,1),'k--','HandleVisibility','off'); xlim([1 IRF_periods]);set(gca,'XTick',[4:4:IRF_periods],'FontSize',12);
title('GDP','FontSize',10)
ylabel('Percent','FontSize',9)
legend('LGFC Risk shock')

  
subplot(4,4,2)
hold on
plot(t,C_esigmag,'b-','LineWidth',2)
plot(zeros(IRF_periods,1),'k--','HandleVisibility','off'); xlim([1 IRF_periods]);set(gca,'XTick',[4:4:IRF_periods],'FontSize',12);
title('Consumption','FontSize',10)
ylabel('Percent','FontSize',9)

   
subplot(4,4,3)
hold on
plot(t,pi_esigmag,'b-','LineWidth',2)
plot(zeros(IRF_periods,1),'k--','HandleVisibility','off'); xlim([1 IRF_periods]);set(gca,'XTick',[4:4:IRF_periods],'FontSize',12);
title('Inflation','FontSize',10)
ylabel('Percent','FontSize',9)


subplot(4,4,4)
hold on
plot(t,h_esigmag,'b-','LineWidth',2)
plot(zeros(IRF_periods,1),'k--','HandleVisibility','off'); xlim([1 IRF_periods]);set(gca,'XTick',[4:4:IRF_periods],'FontSize',12);
title('Hours','FontSize',10)
ylabel('Percent','FontSize',9)

subplot(4,4,5)
hold on
plot(t,mp_esigmag,'b-','LineWidth',2)
plot(zeros(IRF_periods,1),'k--','HandleVisibility','off'); xlim([1 IRF_periods]);set(gca,'XTick',[4:4:IRF_periods],'FontSize',12);
title('M2 Growth','FontSize',10)
ylabel('Percent','FontSize',9)

 
subplot(4,4,6)
hold on
plot(t,gama_esigmag,'b-','LineWidth',2)
plot(zeros(IRF_periods,1),'k--','HandleVisibility','off'); xlim([1 IRF_periods]);set(gca,'XTick',[4:4:IRF_periods],'FontSize',12);
title('Reserve rate','FontSize',10)
ylabel('Percent','FontSize',9)


subplot(4,4,7)
hold on
plot(t,R_esigmag,'b-','LineWidth',2)
plot(zeros(IRF_periods,1),'k--','HandleVisibility','off'); xlim([1 IRF_periods]);set(gca,'XTick',[4:4:IRF_periods],'FontSize',12);
title('Interest Rate','FontSize',10)
ylabel('Percent','FontSize',9)

  
subplot(4,4,8)
hold on
plot(t,q_esigmag,'b-','LineWidth',2)
plot(zeros(IRF_periods,1),'k--','HandleVisibility','off'); xlim([1 IRF_periods]);set(gca,'XTick',[4:4:IRF_periods],'FontSize',12);
title('Asset price','FontSize',10)
ylabel('Percent','FontSize',9)


subplot(4,4,9)
hold on
plot(t,invp_esigmag,'b-','LineWidth',2)
plot(zeros(IRF_periods,1),'k--','HandleVisibility','off'); xlim([1 IRF_periods]);set(gca,'XTick',[4:4:IRF_periods],'FontSize',12);
title('Private Investment','FontSize',10)
ylabel('Percent','FontSize',9)

subplot(4,4,10)
hold on
plot(t,invg_esigmag,'b-','LineWidth',2)
plot(zeros(IRF_periods,1),'k--','HandleVisibility','off'); xlim([1 IRF_periods]);set(gca,'XTick',[4:4:IRF_periods],'FontSize',12);
title('Public Investment','FontSize',10)
ylabel('Percent','FontSize',9)

subplot(4,4,11)
hold on
plot(t,np_esigmag,'b-','LineWidth',2)
plot(zeros(IRF_periods,1),'k--','HandleVisibility','off'); xlim([1 IRF_periods]);set(gca,'XTick',[4:4:IRF_periods],'FontSize',12);
title('Firm net worth','FontSize',10)
ylabel('Percent','FontSize',9)

subplot(4,4,12)
hold on
plot(t,ng_esigmag,'b-','LineWidth',2)
plot(zeros(IRF_periods,1),'k--','HandleVisibility','off'); xlim([1 IRF_periods]);set(gca,'XTick',[4:4:IRF_periods],'FontSize',12);
title('LGVC net worth','FontSize',10)
ylabel('Percent','FontSize',9)


subplot(4,4,13)
hold on
plot(t,bp_esigmag,'b-','LineWidth',2)
plot(zeros(IRF_periods,1),'k--','HandleVisibility','off'); xlim([1 IRF_periods]);set(gca,'XTick',[4:4:IRF_periods],'FontSize',12);
title('Firm Debt','FontSize',10)
ylabel('Percent','FontSize',9)

figure(hh)   
subplot(4,4,14)
hold on
plot(t,bg_esigmag,'b-','LineWidth',2)
plot(zeros(IRF_periods,1),'k--','HandleVisibility','off'); xlim([1 IRF_periods]);set(gca,'XTick',[4:4:IRF_periods],'FontSize',12);
title('LGFC Debt','FontSize',10)
ylabel('Percent','FontSize',9)



subplot(4,4,15)
hold on
plot(t,bankruptp_esigmag,'b-','LineWidth',2)
plot(zeros(IRF_periods,1),'k--','HandleVisibility','off'); xlim([1 IRF_periods]);set(gca,'XTick',[4:4:IRF_periods],'FontSize',12);
title('Firm Default rate','FontSize',10)
ylabel('Percent','FontSize',9)

   
subplot(4,4,16)
hold on
plot(t,bankruptg_esigmag,'b-','LineWidth',2)
plot(zeros(IRF_periods,1),'k--','HandleVisibility','off'); xlim([1 IRF_periods]);set(gca,'XTick',[4:4:IRF_periods],'FontSize',12);
title('LGVC Default rate','FontSize',10)
ylabel('Percent','FontSize',9)


hh=6;
figure(hh) 
subplot(4,4,1)
hold on
plot(t,y_eg,'b-','LineWidth',2);
plot(zeros(IRF_periods,1),'k--','HandleVisibility','off'); xlim([1 IRF_periods]);set(gca,'XTick',[4:4:IRF_periods],'FontSize',12);
title('GDP','FontSize',10)
ylabel('Percent','FontSize',9)
legend('Fiscal Policy shock')

  
subplot(4,4,2)
hold on
plot(t,C_eg,'b-','LineWidth',2)
plot(zeros(IRF_periods,1),'k--','HandleVisibility','off'); xlim([1 IRF_periods]);set(gca,'XTick',[4:4:IRF_periods],'FontSize',12);
title('Consumption','FontSize',10)
ylabel('Percent','FontSize',9)

  
subplot(4,4,3)
hold on
plot(t,pi_eg,'b-','LineWidth',2)
plot(zeros(IRF_periods,1),'k--','HandleVisibility','off'); xlim([1 IRF_periods]);set(gca,'XTick',[4:4:IRF_periods],'FontSize',12);
title('Inflation','FontSize',10)
ylabel('Percent','FontSize',9)

   
subplot(4,4,4)
hold on
plot(t,h_eg,'b-','LineWidth',2)
plot(zeros(IRF_periods,1),'k--','HandleVisibility','off'); xlim([1 IRF_periods]);set(gca,'XTick',[4:4:IRF_periods],'FontSize',12);
title('Hours','FontSize',10)
ylabel('Percent','FontSize',9)

  
subplot(4,4,5)
hold on
plot(t,mp_eg,'b-','LineWidth',2)
plot(zeros(IRF_periods,1),'k--','HandleVisibility','off'); xlim([1 IRF_periods]);set(gca,'XTick',[4:4:IRF_periods],'FontSize',12);
title('M2 Growth','FontSize',10)
ylabel('Percent','FontSize',9)



subplot(4,4,6)
hold on
plot(t,gama_eg,'b-','LineWidth',2)
plot(zeros(IRF_periods,1),'k--','HandleVisibility','off'); xlim([1 IRF_periods]);set(gca,'XTick',[4:4:IRF_periods],'FontSize',12);
title('Reserve rate','FontSize',10)
ylabel('Percent','FontSize',9)

 
subplot(4,4,7)
hold on
plot(t,R_eg,'b-','LineWidth',2)
plot(zeros(IRF_periods,1),'k--','HandleVisibility','off'); xlim([1 IRF_periods]);set(gca,'XTick',[4:4:IRF_periods],'FontSize',12);
title('Interest Rate','FontSize',10)
ylabel('Percent','FontSize',9)

  
subplot(4,4,8)
hold on
plot(t,q_eg,'b-','LineWidth',2)
plot(zeros(IRF_periods,1),'k--','HandleVisibility','off'); xlim([1 IRF_periods]);set(gca,'XTick',[4:4:IRF_periods],'FontSize',12);
title('Asset price','FontSize',10)
ylabel('Percent','FontSize',9)

 
subplot(4,4,9)
hold on
plot(t,invp_eg,'b-','LineWidth',2)
plot(zeros(IRF_periods,1),'k--','HandleVisibility','off'); xlim([1 IRF_periods]);set(gca,'XTick',[4:4:IRF_periods],'FontSize',12);
title('Private Investment','FontSize',10)
ylabel('Percent','FontSize',9)

subplot(4,4,10)
hold on
plot(t,invg_eg,'b-','LineWidth',2)
plot(zeros(IRF_periods,1),'k--','HandleVisibility','off'); xlim([1 IRF_periods]);set(gca,'XTick',[4:4:IRF_periods],'FontSize',12);
title('Public Investment','FontSize',10)
ylabel('Percent','FontSize',9)

subplot(4,4,11)
hold on
plot(t,np_eg,'b-','LineWidth',2)
plot(zeros(IRF_periods,1),'k--','HandleVisibility','off'); xlim([1 IRF_periods]);set(gca,'XTick',[4:4:IRF_periods],'FontSize',12);
title('Firm net worth','FontSize',10)
ylabel('Percent','FontSize',9)

subplot(4,4,12)
hold on
plot(t,ng_eg,'b-','LineWidth',2)
plot(zeros(IRF_periods,1),'k--','HandleVisibility','off'); xlim([1 IRF_periods]);set(gca,'XTick',[4:4:IRF_periods],'FontSize',12);
title('LGVC net worth','FontSize',10)
ylabel('Percent','FontSize',9)
 
subplot(4,4,13)
hold on
plot(t,bp_eg,'b-','LineWidth',2)
plot(zeros(IRF_periods,1),'k--','HandleVisibility','off'); xlim([1 IRF_periods]);set(gca,'XTick',[4:4:IRF_periods],'FontSize',12);
title('Firm Debt','FontSize',10)
ylabel('Percent','FontSize',9)
 
subplot(4,4,14)
hold on
plot(t,bg_eg,'b-','LineWidth',2)
plot(zeros(IRF_periods,1),'k--','HandleVisibility','off'); xlim([1 IRF_periods]);set(gca,'XTick',[4:4:IRF_periods],'FontSize',12);
title('LGFC Debt','FontSize',10)
ylabel('Percent','FontSize',9)
  
subplot(4,4,15)
hold on
plot(t,bankruptp_eg,'b-','LineWidth',2)
plot(zeros(IRF_periods,1),'k--','HandleVisibility','off'); xlim([1 IRF_periods]);set(gca,'XTick',[4:4:IRF_periods],'FontSize',12);
title('Firm Default rate','FontSize',10)
ylabel('Percent','FontSize',9)
 
subplot(4,4,16)
hold on
plot(t,bankruptg_eg,'b-','LineWidth',2)
plot(zeros(IRF_periods,1),'k--','HandleVisibility','off'); xlim([1 IRF_periods]);set(gca,'XTick',[4:4:IRF_periods],'FontSize',12);
title('LGVC Default rate','FontSize',10)
ylabel('Percent','FontSize',9)