%% generate the impluse response to a positive structural monetary policy shock

clear;

% set the type of shocks
sig_tau=1;  % =1 or -1 implies that the economy faces a 1% positive or negative structural monetary policy shock, =0 implies that the economy doesn't experience a structural monetary policy shock
sig_a=0;    % =1 or -1 implies that the economy faces a 1% positive or negative productivity shock, =0 implies that the economy doesn't experience this shock
sig_m=0;    % =1 or -1 implies that the economy faces a 1% positive or negative traditional monetary policy shock, =0 implies that the economy doesn't experience this shock
sig_g=0;    % =1 or -1 implies that the economy faces a 1% positive or negative capital regulatory policy shock, =0 implies that the economy doesn't experience this shock
save shock_type sig_tau sig_a sig_m sig_g

%% define oo_bench_sm and oo_nosb_sm
% oo_bench_sm:oo_ of the benchmark case
% oo_nosb_sm: oo_ file of the case without shadow banks
dynare   bench_trans.mod 
oo_bench_sm=oo_;
save SM_BENCH oo_bench_sm

dynare bench_nosb.mod
oo_nosb_sm=oo_;
save SM_NOSB oo_nosb_sm

%% generate figure 1

clear; 

load SM_BENCH
load SM_NOSB
figure;
subplot(3,4,1)
plot(100*oo_bench_sm.irfs.gdp_exp_tau./oo_bench_sm.steady_state(48),'k-','LineWidth',1.5);
hold all
plot(100*oo_nosb_sm.irfs.gdp_exp_tau./oo_nosb_sm.steady_state(37),'k--','LineWidth',1.5);
hold all
title('GDP','FontSize',18,'interpreter','latex')
box off

subplot(3,4,2)
plot(100*oo_bench_sm.irfs.yys_exp_tau./oo_bench_sm.steady_state(45),'k-','LineWidth',1.5);
hold all
plot(100*oo_nosb_sm.irfs.yys_exp_tau./oo_nosb_sm.steady_state(34),'k--','LineWidth',1.5);
hold all
title('产业结构','FontSize',18,'interpreter','latex')
box off

subplot(3,4,3)
plot(100*oo_bench_sm.irfs.lls_exp_tau./oo_bench_sm.steady_state(44),'k-','LineWidth',1.5);
hold all
plot(100*oo_nosb_sm.irfs.lls_exp_tau./oo_nosb_sm.steady_state(33),'k--','LineWidth',1.5);
hold all
title('商业银行信贷结构','FontSize',18,'interpreter','latex')
box off

subplot(3,4,4)
plot(100*(oo_bench_sm.irfs.ls_exp_tau+oo_bench_sm.irfs.lp_exp_tau)./(oo_bench_sm.steady_state(10)+oo_bench_sm.steady_state(21)),'k-','LineWidth',1.5);
hold all
plot(100*(oo_nosb_sm.irfs.ls_exp_tau+oo_nosb_sm.irfs.lp_exp_tau)./(oo_nosb_sm.steady_state(10)+oo_nosb_sm.steady_state(20)),'k--','LineWidth',1.5);
hold all
title('商业银行贷款规模','FontSize',18,'interpreter','latex')
box off

subplot(3,4,5)
plot(100*oo_bench_sm.irfs.lp_exp_tau./oo_bench_sm.steady_state(10),'k-','LineWidth',1.5);
hold all
plot(100*oo_nosb_sm.irfs.lp_exp_tau./oo_nosb_sm.steady_state(10),'k--','LineWidth',1.5);
hold all
title('商业银行非国企贷款量','FontSize',18,'interpreter','latex')
box off

subplot(3,4,6)
plot(100*oo_bench_sm.irfs.ls_exp_tau./oo_bench_sm.steady_state(21),'k-','LineWidth',1.5);
hold all
plot(100*oo_nosb_sm.irfs.ls_exp_tau./oo_nosb_sm.steady_state(20),'k--','LineWidth',1.5);
hold all
title('商业银行国企贷款量','FontSize',18,'interpreter','latex')
box off


subplot(3,4,8)
plot(100*oo_bench_sm.irfs.Rs_exp_tau./oo_bench_sm.steady_state(27),'k-','LineWidth',1.5);
hold all
plot(100*oo_nosb_sm.irfs.Rs_exp_tau./oo_nosb_sm.steady_state(26),'k--','LineWidth',1.5);
hold all
title('商业银行国企贷款利率','FontSize',18,'interpreter','latex')
box off

subplot(3,4,7)
plot(100*oo_bench_sm.irfs.Rp_exp_tau./oo_bench_sm.steady_state(28),'k-','LineWidth',1.5);
hold all
plot(100*oo_nosb_sm.irfs.Rp_exp_tau./oo_nosb_sm.steady_state(27),'k--','LineWidth',1.5);
hold all
title('商业银行非国企贷款利率','FontSize',18,'interpreter','latex')
box off

subplot(3,4,9)
plot(100*oo_bench_sm.irfs.lp_bar_exp_tau./oo_bench_sm.steady_state(20),'k-','LineWidth',1.5);
hold all
plot(zeros([1,10])','k--','LineWidth',1.5);
hold all
title('影子银行贷款规模','FontSize',18,'interpreter','latex')
box off
subplot(3,4,10)
plot(100*oo_bench_sm.irfs.rb_exp_tau./oo_bench_sm.steady_state(29),'k-','LineWidth',1.5);
hold all
plot(zeros([1,10])','k--','LineWidth',1.5);
hold all
title('影子银行借款利率','FontSize',18,'interpreter','latex')
box off

subplot(3,4,11)
plot(100*oo_bench_sm.irfs.pr_exp_tau./oo_bench_sm.steady_state(38),'k-','LineWidth',1.5);
hold all
plot(zeros([1,10])','k--','LineWidth',1.5);
hold all
title('影子银行违约率','FontSize',18,'interpreter','latex')
box off
legend('有影子银行','没有影子银行','FontSize',18,'interpreter','latex')
legend('boxoff') 

%% generate the impluse response to a positive traditional monetary policy shock

clear;

% set the type of shocks
sig_tau=0; sig_a=0;  
sig_m=1;   sig_g=0;   
save shock_type sig_tau sig_a sig_m sig_g

% define oo_bench_sm and oo_nosb_sm
% oo_bench_sm:oo_ of the benchmark case
% oo_nosb_sm: oo_ file of the case without shadow banks

dynare   bench_trans.mod 
oo_bench_sm=oo_;
save SMm_BENCH oo_bench_sm

dynare bench_nosb.mod
oo_nosb_sm=oo_;
save SMm_NOSB oo_nosb_sm
%% generate figure 2

clear; 

load SMm_BENCH
load SMm_NOSB
figure;
subplot(3,4,1)
plot(100*oo_bench_sm.irfs.gdp_exp_m./oo_bench_sm.steady_state(48),'k-','LineWidth',1.5);
hold all
plot(100*oo_nosb_sm.irfs.gdp_exp_m./oo_nosb_sm.steady_state(37),'k--','LineWidth',1.5);
hold all
title('GDP','FontSize',18,'interpreter','latex')
box off

subplot(3,4,2)
plot(100*oo_bench_sm.irfs.yys_exp_m./oo_bench_sm.steady_state(45),'k-','LineWidth',1.5);
hold all
plot(100*oo_nosb_sm.irfs.yys_exp_m./oo_nosb_sm.steady_state(34),'k--','LineWidth',1.5);
hold all
title('产业结构','FontSize',18,'interpreter','latex')
box off

subplot(3,4,3)
plot(100*oo_bench_sm.irfs.lls_exp_m./oo_bench_sm.steady_state(44),'k-','LineWidth',1.5);
hold all
plot(100*oo_nosb_sm.irfs.lls_exp_m./oo_nosb_sm.steady_state(33),'k--','LineWidth',1.5);
hold all
title('商业银行信贷结构','FontSize',18,'interpreter','latex')
box off

subplot(3,4,4)
plot(100*(oo_bench_sm.irfs.ls_exp_m+oo_bench_sm.irfs.lp_exp_m)./(oo_bench_sm.steady_state(10)+oo_bench_sm.steady_state(21)),'k-','LineWidth',1.5);
hold all
plot(100*(oo_nosb_sm.irfs.ls_exp_m+oo_nosb_sm.irfs.lp_exp_m)./(oo_nosb_sm.steady_state(10)+oo_nosb_sm.steady_state(20)),'k--','LineWidth',1.5);
hold all
title('商业银行贷款规模','FontSize',18,'interpreter','latex')
box off

subplot(3,4,5)
plot(100*oo_bench_sm.irfs.lp_exp_m./oo_bench_sm.steady_state(10),'k-','LineWidth',1.5);
hold all
plot(100*oo_nosb_sm.irfs.lp_exp_m./oo_nosb_sm.steady_state(10),'k--','LineWidth',1.5);
hold all
title('商业银行非国企贷款量','FontSize',18,'interpreter','latex')
box off

subplot(3,4,6)
plot(100*oo_bench_sm.irfs.ls_exp_m./oo_bench_sm.steady_state(21),'k-','LineWidth',1.5);
hold all
plot(100*oo_nosb_sm.irfs.ls_exp_m./oo_nosb_sm.steady_state(20),'k--','LineWidth',1.5);
hold all
title('商业银行国企贷款量','FontSize',18,'interpreter','latex')
box off


subplot(3,4,8)
plot(100*oo_bench_sm.irfs.Rs_exp_m./oo_bench_sm.steady_state(27),'k-','LineWidth',1.5);
hold all
plot(100*oo_nosb_sm.irfs.Rs_exp_m./oo_nosb_sm.steady_state(26),'k--','LineWidth',1.5);
hold all
title('商业银行国企贷款利率','FontSize',18,'interpreter','latex')
box off

subplot(3,4,7)
plot(100*oo_bench_sm.irfs.Rp_exp_m./oo_bench_sm.steady_state(28),'k-','LineWidth',1.5);
hold all
plot(100*oo_nosb_sm.irfs.Rp_exp_m./oo_nosb_sm.steady_state(27),'k--','LineWidth',1.5);
hold all
title('商业银行非国企贷款利率','FontSize',18,'interpreter','latex')
box off

subplot(3,4,9)
plot(100*oo_bench_sm.irfs.lp_bar_exp_m./oo_bench_sm.steady_state(20),'k-','LineWidth',1.5);
hold all
plot(zeros([1,10])','k--','LineWidth',1.5);
hold all
title('影子银行贷款规模','FontSize',18,'interpreter','latex')
box off
subplot(3,4,10)
plot(100*oo_bench_sm.irfs.rb_exp_m./oo_bench_sm.steady_state(29),'k-','LineWidth',1.5);
hold all
plot(zeros([1,10])','k--','LineWidth',1.5);
hold all
title('影子银行借款利率','FontSize',18,'interpreter','latex')
box off

subplot(3,4,11)
plot(100*oo_bench_sm.irfs.pr_exp_m./oo_bench_sm.steady_state(38),'k-','LineWidth',1.5);
hold all
plot(zeros([1,10])','k--','LineWidth',1.5);
hold all
title('影子银行违约率','FontSize',18,'interpreter','latex')
box off
legend('有影子银行','没有影子银行','FontSize',18,'interpreter','latex')
legend('boxoff') 

%% generate the impluse response to a positive capital regulatory policy shock

clear;

% set the type of shocks
sig_tau=0; sig_a=0;  
sig_m=0;   sig_g=1;   
save shock_type sig_tau sig_a sig_m sig_g

dynare   bench_trans.mod 
oo_bench_sm=oo_;             % define oo_bench_sm: oo_ of the benchmark case 
save GAMMA_BENCH oo_bench_sm

%% generate figure 3
clear
load GAMMA_BENCH

figure;
fig_width = 4 * 400;  
fig_height = 400;
set(gcf, 'Position', [100 100 fig_width fig_height]);

subplot(1,4,1)
plot(100*oo_bench_sm.irfs.lp_bar_exp_g./oo_bench_sm.steady_state(20),'k-','LineWidth',1.5);
hold all
title('影子银行贷款规模','FontSize',18,'interpreter','latex')
box off
subplot(1,4,2)
plot(100*oo_bench_sm.irfs.lls_exp_g./oo_bench_sm.steady_state(44),'k-','LineWidth',1.5);
hold all
title('商业银行信贷结构','FontSize',18,'interpreter','latex')
box off
subplot(1,4,3)
plot(100*oo_bench_sm.irfs.rb_exp_g./oo_bench_sm.steady_state(29),'k-','LineWidth',1.5);
hold all
title('影子银行借款利率','FontSize',18,'interpreter','latex')
box off
subplot(1,4,4)
plot(100*oo_bench_sm.irfs.pr_exp_g./oo_bench_sm.steady_state(38),'k-','LineWidth',1.5);
hold all
title('影子银行违约率','FontSize',18,'interpreter','latex')
box off
   


