%% cd_figures.m
% generates figures for CD model
if strcmp(model,'CD')
    %% %%%%%%%%%%%%%%%%%  Figures  %%%%%%%%%%%%%%%
%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
t = 0:T-1; t = t';
zt = 0*t;
plot_color= { 'o-k' 's-.c'  'd--b' '*--r' }; % 'd-b' 'd--b'};
markersize = 4;

figure(11)
subplot(2,2,1)
plot(t,IRF_CD_0_15_85(:,2),'o-k',t,IRF_CD_1_15_85(:,2),'s-.c',t,IRF_CD_2_15_85(:,2),'d--b',t,IRF_CD_3_15_85(:,2),'*-r',t,IRF_CD_4_15_85(:,2),'d-b',t,IRF_CD_5_15_85(:,2),'o--k',t,zt,'k','LineWidth',1.5,'MarkerSize',markersize)
legend('k=0','k=1','k=2','k=3','k=4','k=5','Location',['northeast'])
title('Nominal rate')
subplot(2,2,2)
plot(t,IRF_CD_0_15_85(:,3),'o-k',t,IRF_CD_1_15_85(:,3),'s-.c',t,IRF_CD_2_15_85(:,3),'d--b',t,IRF_CD_3_15_85(:,3),'*-r',t,IRF_CD_4_15_85(:,3),'d-b',t,IRF_CD_5_15_85(:,3),'o--k',t,zt,'k','LineWidth',1.5,'MarkerSize',markersize)
title('Real rate')
%legend('Real rate','Location','Northeast')
subplot(2,2,3)
plot(t,IRF_CD_0_15_85(:,5),'o-k',t,IRF_CD_1_15_85(:,5),'s-.c',t,IRF_CD_2_15_85(:,5),'d--b',t,IRF_CD_3_15_85(:,5),'*-r',t,IRF_CD_4_15_85(:,5),'d-b',t,IRF_CD_5_15_85(:,5),'o--k',t,zt,'k','LineWidth',1.5,'MarkerSize',markersize)
title('Output gap')
%legend('output gap','Location','SouthEast')
subplot(2,2,4)
plot(t,IRF_CD_0_15_85(:,4),'o-k',t,IRF_CD_1_15_85(:,4),'s-.c',t,IRF_CD_2_15_85(:,4),'d--b',t,IRF_CD_3_15_85(:,4),'*-r',t,IRF_CD_4_15_85(:,4),'d-b',t,IRF_CD_5_15_85(:,4),'o--k',t,zt,'k','LineWidth',1.5,'MarkerSize',markersize)
title('Inflation rate')
%legend('inflation','Location','NorthEast')
MM = 10;
v  = 5;
[IRF_RE_0_15_85(1:MM,v) IRF_CD_0_15_85(1:MM,v) IRF_RE_5_15_85(1:MM,v) IRF_CD_5_15_85(1:MM,v)]

if strcmp(savefigs,'yes')
    cd(cdfigures)
    print -dpng 'IRF_CD';
    savefig('IRF_CD'); 
    cd(cdoutput)
end
%%
figure(12)
subplot(2,2,1)
plot(t,IRF_CD_0_15_85(:,2),'o-k',t,IRF_CD_0_30_85(:,2),'o--k',t,IRF_CD_4_15_85(:,2),'d-b',t,IRF_CD_4_30_85(:,2),'b--d',t,zt,'k','LineWidth',1.5,'MarkerSize',markersize)
%legend('k=0, \phi_{\pi}=1.5','k=0, \phi_{\pi}=3.0','k=4, \phi_{\pi}=1.5','k=4, \phi_{\pi}=3.0','Location','NorthEast')
title('Nominal rate')
subplot(2,2,2)
plot(t,IRF_CD_0_15_85(:,3),'o-k',t,IRF_CD_0_30_85(:,3),'o--k',t,IRF_CD_4_15_85(:,3),'d-b',t,IRF_CD_4_30_85(:,3),'b--d',t,zt,'k','LineWidth',1.5,'MarkerSize',markersize)
legend('k=0, \phi_{\pi}=1.5','k=0, \phi_{\pi}=3.0','k=4, \phi_{\pi}=1.5','k=4, \phi_{\pi}=3.0','Location','SouthEast')
title('Real rate')
%legend('Real rate','Location','Northeast')
subplot(2,2,3)
plot(t,IRF_CD_0_15_85(:,5),'o-k',t,IRF_CD_0_30_85(:,5),'o--k',t,IRF_CD_4_15_85(:,5),'d-b',t,IRF_CD_4_30_85(:,5),'b--d',t,zt,'k','LineWidth',1.5,'MarkerSize',markersize)
title('Output gap')
%legend('output gap','Location','SouthEast')
subplot(2,2,4)
plot(t,IRF_CD_0_15_85(:,4),'o-k',t,IRF_CD_0_30_85(:,4),'o--k',t,IRF_CD_4_15_85(:,4),'d-b',t,IRF_CD_4_30_85(:,4),'b--d',t,zt,'k','LineWidth',1.5,'MarkerSize',markersize)
title('Inflation rate')
%legend('inflation','Location','NorthEast')

if strcmp(savefigs,'yes')
    cd(cdfigures)
    print -dpng 'IRF_CD_doublephi';
    savefig('IRF_CD_doublephi'); 
    cd(cdoutput)
end
%%
figure(13)
subplot(2,2,1)
plot(t,IRF_CD_0_15_85(:,2),'o-k',t,IRF_CD_0_15_5(:,2),'o--k',t,IRF_CD_4_15_85(:,2),'d-b',t,IRF_CD_4_15_5(:,2),'b--d',t,zt,'k','LineWidth',1.5,'MarkerSize',markersize)
title('Nominal rate')
subplot(2,2,2)
plot(t,IRF_CD_0_15_85(:,3),'o-k',t,IRF_CD_0_15_5(:,3),'o--k',t,IRF_CD_4_15_85(:,3),'d-b',t,IRF_CD_4_15_5(:,3),'b--d',t,zt,'k','LineWidth',1.5,'MarkerSize',markersize)
title('Real rate')
%legend('Real rate','Location','Northeast')
subplot(2,2,3)
plot(t,IRF_CD_0_15_85(:,5),'o-k',t,IRF_CD_0_15_5(:,5),'o--k',t,IRF_CD_4_15_85(:,5),'d-b',t,IRF_CD_4_15_5(:,5),'b--d',t,zt,'k','LineWidth',1.5,'MarkerSize',markersize)
title('Output gap')
%legend('output gap','Location','SouthEast')
subplot(2,2,4)
plot(t,IRF_CD_0_15_85(:,4),'o-k',t,IRF_CD_0_15_5(:,4),'o--k',t,IRF_CD_4_15_85(:,4),'d-b',t,IRF_CD_4_15_5(:,4),'b--d',t,zt,'k','LineWidth',1.5,'MarkerSize',markersize)
legend('k=0, \phi_{\pi}=1.5,\rho_i=0.85','k=0, \phi_{\pi}=1.5,\rho_i=0.5','k=4, \phi_{\pi}=1.5,\rho_i=0.85','k=4, \phi_{\pi}=1.5, \rho_i=0.5','Location','NorthEast')
title('Inflation rate')
%legend('inflation','Location','NorthEast')

if strcmp(savefigs,'yes')
    cd(cdfigures)
    print -dpng 'IRF_CD_small_rhoi';
    savefig('irf_CD_small_rhoi'); 
    cd(cdoutput)
end
%%
figure(14)
subplot(2,2,1)
plot(t,IRF_CD_0_30_85(:,2),'o-k',t,IRF_CD_0_30_5(:,2),'o--k',t,IRF_CD_4_30_85(:,2),'d-b',t,IRF_CD_4_30_5(:,2),'b--d',t,zt,'k','LineWidth',1.5,'MarkerSize',markersize)
%legend('k=0, \phi_{\pi}=3.0,\rho_i=0.85','k=0, \phi_{\pi}=3.0,\rho_i=0.5','k=4, \phi_{\pi}=3.0,\rho_i=0.85','k=4, \phi_{\pi}=3.0, \rho_i=0.5','Location','NorthEast')
title('Nominal rate')
subplot(2,2,2)
plot(t,IRF_CD_0_30_85(:,3),'o-k',t,IRF_CD_0_30_5(:,3),'o--k',t,IRF_CD_4_30_85(:,3),'d-b',t,IRF_CD_4_30_5(:,3),'b--d',t,zt,'k','LineWidth',1.5,'MarkerSize',markersize)
title('Real rate')
%legend('Real rate','Location','Northeast')
subplot(2,2,3)
plot(t,IRF_CD_0_30_85(:,5),'o-k',t,IRF_CD_0_30_5(:,5),'o--k',t,IRF_CD_4_30_85(:,5),'d-b',t,IRF_CD_4_30_5(:,5),'b--d',t,zt,'k','LineWidth',1.5,'MarkerSize',markersize)
title('Output gap')
%legend('output gap','Location','SouthEast')
subplot(2,2,4)
plot(t,IRF_CD_0_30_85(:,4),'o-k',t,IRF_CD_0_30_5(:,4),'o--k',t,IRF_CD_4_30_85(:,4),'d-b',t,IRF_CD_4_30_5(:,4),'b--d',t,zt,'k','LineWidth',1.5,'MarkerSize',markersize)
legend('k=0, \phi_{\pi}=3.0,\rho_i=0.85','k=0, \phi_{\pi}=3.0,\rho_i=0.5','k=4, \phi_{\pi}=3.0,\rho_i=0.85','k=4, \phi_{\pi}=3.0, \rho_i=0.5','Location','NorthEast')
title('Inflation rate')
%legend('inflation','Location','NorthEast')

if strcmp(savefigs,'yes')
    cd(cdfigures)
    print -dpng 'IRF_CD_large_phi_small_rhoi';
    savefig('IRF_CD_large_phi_small_rhoi'); 
    cd(cdoutput)
end


%%
figure(15)
subplot(2,2,1)
plot(t,IRF_CD_4_15_85(:,2),'b-d',t,IRF_CD_6_15_85(:,2),'r--o',t,zt,'k','LineWidth',1.5,'MarkerSize',markersize)
title('Nominal rate')
subplot(2,2,2)
plot(t,IRF_CD_4_15_85(:,3),'b-d',t,IRF_CD_6_15_85(:,3),'r--o',t,zt,'k','LineWidth',1.5,'MarkerSize',markersize)
title('Real rate')
legend('k=4, \phi_{\pi}=1.5, \rho_i=0.85','k=6, \phi_{\pi}=1.5, \rho_i=0.85','Location','SouthEast')
%legend('Real rate','Location','Northeast')
subplot(2,2,3)
plot(t,IRF_CD_4_15_85(:,5),'b-d',t,IRF_CD_6_15_85(:,5),'r--o',t,zt,'k','LineWidth',1.5,'MarkerSize',markersize)
title('Output gap')
%legend('output gap','Location','SouthEast')
subplot(2,2,4)
plot(t,IRF_CD_4_15_85(:,4),'b-d',t,IRF_CD_6_15_85(:,4),'r--o',t,zt,'k','LineWidth',1.5,'MarkerSize',markersize)
title('Inflation rate')
%legend('inflation','Location','NorthEast')

if strcmp(savefigs,'yes')
    cd(cdfigures)
    print -dpng 'IRF_CD_large_k';
    savefig('IRF_CD_large_k'); 
    cd(cdoutput)
end
%% volatility figures
%plotcolors = {'o-k' 's:c'  'd-b' '*--r'};
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% old figures 6 and 7

if strcmp(TK,'yes')
figure(16)
subplot(2,2,1)
plot(t,V_CD_0_15_85(:,5),'o-k',t,V_CD_1_15_85(:,5),'s-.c',t,V_CD_2_15_85(:,5),'d--b',t,V_CD_3_15_85(:,5),'*-r',t,V_CD_4_15_85(:,5),'d-b',t,V_CD_5_15_85(:,5),'o--k',t,zt,'k','LineWidth',1.5,'MarkerSize',markersize)
title(' \phi_{\pi}=1.5, \rho_i=0.85')
legend('k=0','k=1','k=2','k=3','k=4','k=5','Location','NorthEast')
subplot(2,2,2)
plot(t,V_CD_0_30_85(:,5),'o-k',t,V_CD_1_30_85(:,5),'s-.c',t,V_CD_2_30_85(:,5),'d--b',t,V_CD_3_30_85(:,5),'*-r',t,V_CD_4_30_85(:,5),'d-b',t,V_CD_5_30_85(:,5),'o--k',t,zt,'k','LineWidth',1.5,'MarkerSize',markersize)
title(' \phi_{\pi}=3.0, \rho_i=0.85')
%legend('Real rate','Location','Northeast')
subplot(2,2,3)
plot(t,V_CD_0_15_5(:,5),'o-k',t,V_CD_1_15_5(:,5),'s-.c',t,V_CD_2_15_5(:,5),'d--b',t,V_CD_3_15_5(:,5),'*-r',t,V_CD_4_15_5(:,5),'d-b',t,V_CD_5_15_5(:,5),'o--k',t,zt,'k','LineWidth',1.5,'MarkerSize',markersize)
title(' \phi_{\pi}=1.5, \rho_i=0.5')
%legend('output gap','Location','SouthEast')
subplot(2,2,4)
plot(t,V_CD_0_30_5(:,5),'o-k',t,V_CD_1_30_5(:,5),'s-.c',t,V_CD_2_30_5(:,5),'d--b',t,V_CD_3_30_5(:,5),'*-r',t,V_CD_4_30_5(:,5),'d-b',t,V_CD_5_30_5(:,5),'o--k',t,zt,'k','LineWidth',1.5,'MarkerSize',markersize)
title(' \phi_{\pi}=3.0, \rho_i=0.5')

if strcmp(savefigs,'yes')
    cd(cdfigures)
    print -dpng 'loss1_CD';
    savefig('loss1_CD'); 
    cd(cdoutput)
end
%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
figure(17)
subplot(2,2,1)
plot(t,VL_CD_0_15_85(:,6),'o-k',t,VL_CD_1_15_85(:,6),'s-.c',t,VL_CD_2_15_85(:,6),'d--b',t,VL_CD_3_15_85(:,6),'*-r',t,VL_CD_4_15_85(:,6),'d-b',t,VL_CD_5_15_85(:,6),'o--k',t,zt,'k','LineWidth',1.5,'MarkerSize',markersize)
legend('k=0', 'k=1', 'k=3', 'k=4', 'k=5','Location','NorthEast')
title(' \phi_{\pi}=1.5, \rho_i=0.85')
subplot(2,2,2)
plot(t,VL_CD_0_30_85(:,6),'o-k',t,VL_CD_1_30_85(:,6),'s-.c',t,VL_CD_2_30_85(:,6),'d--b',t,VL_CD_3_30_85(:,6),'*-r',t,VL_CD_4_30_85(:,6),'d-b',t,VL_CD_5_30_85(:,6),'o--k',t,zt,'k','LineWidth',1.5,'MarkerSize',markersize)
title(' \phi_{\pi}=3.0, \rho_i=0.85')
%legend('Real rate','Location','Northeast')
subplot(2,2,3)
plot(t,VL_CD_0_15_5(:,6),'o-k',t,VL_CD_1_15_5(:,6),'s-.c',t,VL_CD_2_15_5(:,6),'d--b',t,VL_CD_3_15_5(:,6),'*-r',t,VL_CD_4_15_5(:,6),'d-b',t,VL_CD_5_15_5(:,6),'o--k',t,zt,'k','LineWidth',1.5,'MarkerSize',markersize)
title(' \phi_{\pi}=1.5, \rho_i=0.5')
%legend('output gap','Location','SouthEast')
subplot(2,2,4)
plot(t,VL_CD_0_30_5(:,6),'o-k',t,VL_CD_1_30_5(:,6),'s-.c',t,VL_CD_2_30_5(:,6),'d--b',t,VL_CD_3_30_5(:,6),'*-r',t,VL_CD_4_30_5(:,6),'d-b',t,VL_CD_5_30_5(:,6),'o--k',t,zt,'k','LineWidth',1.5,'MarkerSize',markersize)
title(' \phi_{\pi}=3.0, \rho_i=0.5')
%legend('k=0, \phi_{\pi}=3.0,\rho_i=0.85','k=0, \phi_{\pi}=3.0,\rho_i=0.5','k=4, \phi_{\pi}=3.0,\rho_i=0.85','k=4, \phi_{\pi}=3.0, \rho_i=0.5','Location','NorthEast')
if strcmp(savefigs,'yes')
    cd(cdfigures)
    print -dpng 'loss2_CD';
    savefig('loss2_CD'); 
    cd(cdoutput)
end
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% New figures 6, 7, and 8
if strcmp(TK,'no')
if strcmp(model,'RE')
    V1_loss11 = [V_CD_0_15_85; V_CD_1_15_85; V_CD_2_15_85; V_CD_3_15_85; V_CD_4_15_85; V_CD_5_15_85];
    V2_loss11 = [VL_CD_0_15_85; VL_CD_1_15_85; VL_CD_2_15_85; VL_CD_3_15_85; VL_CD_4_15_85; VL_CD_5_15_85];

    V1_loss22 = [V_CD_0_30_5; V_CD_1_30_5; V_CD_2_30_5; V_CD_3_30_5; V_CD_4_30_5; V_CD_5_30_5];
    V2_loss22 = [VL_CD_0_30_5; VL_CD_1_30_5; VL_CD_2_30_5; VL_CD_3_30_5; VL_CD_4_30_5; VL_CD_5_30_5];
else
    V1_loss = [V_CD_0_15_85; V_CD_1_15_85; V_CD_2_15_85; V_CD_3_15_85; V_CD_4_15_85; V_CD_5_15_85];
    V2_loss = [VL_CD_0_15_85; VL_CD_1_15_85; VL_CD_2_15_85; VL_CD_3_15_85; VL_CD_4_15_85; VL_CD_5_15_85];
end

kk  = [0 1 2 3 4 5]';
zkk = zeros(length(kk),1);
%%
figure(16)
plot(kk,V1_loss22(:,1),'k-o',kk,V1_loss22(:,2),'r--d',kk,V1_loss22(:,3),'b-.s','LineWidth',1.5,'MarkerSize',markersize+1)
legend('Total loss', 'Contribution of inflation','Contribution of output','Location','NorthWest')
titleV1 = ['Loss as measured by (21): \lambda = ',num2str(lambda)];
title(titleV1)
xlabel('k')
ylabel('L^1')

if strcmp(savefigs,'yes')
    cd(cdfigures)
    print -dpng 'loss_CD_V1_fixedT';
    savefig('loss_CD_V1_fixedT'); 
    cd(cdoutput)
end
%%
figure(17)
plot(kk,V2_loss22(:,1),'k-o',kk,V2_loss22(:,2),'r--d',kk,V2_loss22(:,3),'b-.s',kk,zkk,'k:','LineWidth',1.5,'MarkerSize',markersize+1)
legend('Total loss', 'Contribution of inflation','Contribution of output gap','Location','NorthWest')
titleV2 = ['Loss as measured by (22): \lambda = ',num2str(lambda)];
xlabel('k')
ylabel('L^2')
title(titleV2)

if strcmp(savefigs,'yes')
    cd(cdfigures)
    print -dpng 'loss_CD_V2_fixedT';
    savefig('loss_CD_V2_fixedT'); 
    cd(cdoutput)
end
%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
figure(22)
plot(t,V_CD_0_15_85(:,6),'o-k',t,V_CD_0_30_5(:,6),'o--k',t,V_CD_3_15_85(:,6),'d-b',t,V_CD_3_30_5(:,6),'d--b',t,zt,'k','LineWidth',1.5,'MarkerSize',markersize)
legend('k=0', 'k=0', 'k=3', 'k=3','Location','NorthEast')
title('Eq. (21): Delay and aggression')

if strcmp(savefigs,'yes')
    cd(cdfigures)
    print -dpng 'loss_CD_V1_comp';
    savefig('loss_RE_V1_comp'); 
    cd(cdoutput)
end
%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
figure(23)
plot(t,VL_CD_0_15_85(:,6),'o-k',t,VL_CD_0_30_5(:,6),'o--k',t,VL_CD_2_15_85(:,6),'d-b',t,VL_CD_2_30_5(:,6),'d--b',t,zt,'k','LineWidth',1.5,'MarkerSize',markersize)
legend('k=0', 'k=0', 'k=3', 'k=3','Location','NorthEast')
title('Eq (22): Delay and aggression')

if strcmp(savefigs,'yes')
    cd(cdfigures)
    print -dpng 'loss_CD_V2_comp';
    savefig('loss_CD_V2_comp'); 
    cd(cdoutput)
end
%% 
    V1_loss11 = [V_CD_0_15_85; V_CD_1_15_85; V_CD_2_15_85; V_CD_3_15_85; V_CD_4_15_85; V_CD_5_15_85];
    V2_loss11 = [VL_CD_0_15_85; VL_CD_1_15_85; VL_CD_2_15_85; VL_CD_3_15_85; VL_CD_4_15_85; VL_CD_5_15_85];
    V1_loss22 = [V_CD_0_30_5; V_CD_1_30_5; V_CD_2_30_5; V_CD_3_30_5; V_CD_4_30_5; V_CD_5_30_5];
    V2_loss22 = [VL_CD_0_30_5; VL_CD_1_30_5; VL_CD_2_30_5; VL_CD_3_30_5; VL_CD_4_30_5; VL_CD_5_30_5];
figure(20)
subplot(2,1,1)
plot(kk,V1_loss22(:,1),'k-o',kk,V1_loss22(:,2),'r--d',kk,V1_loss22(:,3),'b-.s','LineWidth',1.5,'MarkerSize',markersize+1)
legend('Total loss', 'Contribution of inflation','Contribution of output','Location','NorthWest')
xlabel('k')
ylabel('L^1')
titleV1 = ['Loss as measured by (21): \lambda = ',num2str(lambda)];
title(titleV1)
subplot(2,1,2)
plot(kk,V2_loss22(:,1),'k-o',kk,V2_loss22(:,2),'r--d',kk,V2_loss22(:,3),'b-.s',kk,zkk,'k','LineWidth',1.5,'MarkerSize',markersize+1)
legend('Total loss', 'Contribution of inflation','Contribution of output gap','Location','NorthWest')
xlabel('k')
ylabel('L^2')
axis([0 5 -1 Inf])
titleV2 = ['Loss as measured by (22): \lambda = ',num2str(lambda)];
title(titleV2)


if strcmp(savefigs,'yes')
    cd(cdfigures)
    print -dpng 'loss_CD_V1_fixedT';
    savefig('loss_CD_V1_fixedT'); 
    cd(cdoutput)
end
end

end
cd(cdprograms)