%% Parameters to load

clear all
close all
clc

%Following GALI 2015
betta   = 0.99;
siggma  = 1;
varphi  = 5;
alppha  = 1/4;
epsilon = 9;
theta   = 3/4;
upsilon = 0.4;
rho_nu  = 0.5;
rho_a   = 0.9;
rho_y_star  = 0;
phi_pi  = 1.5;
phi_y   = 0.5/4;
eta     = 1;
rho_z   =0.5;

%Composite parameters
Omega    =(1-alppha)/(1-alppha+alppha*epsilon);        %p. 233
lambda   =(1-theta)*(1-betta*theta)/theta*Omega;       %p. 233
omega    = siggma*eta + (1-upsilon)*(siggma*eta-1);    %p. 235
Phi = 1 / (1+upsilon*(omega-1));                       %p. 235
siggma_upsilon = siggma*Phi;                           %p. 235
Gamma_a  = (1+varphi)/(siggma_upsilon*(1-alppha)+varphi+alppha);                                          %p. 238
Gamma_star  = - upsilon*(omega-1)*siggma_upsilon*(1-alppha)/(siggma_upsilon*(1-alppha)+varphi+alppha);    %p. 238
Gamma_z  = - upsilon*omega*Phi*(1-alppha)/(siggma_upsilon*(1-alppha)+varphi+alppha);                      %p. 238   
kappa_upsilon  = lambda*(siggma_upsilon+(varphi+alppha)/(1-alppha));                                      %p. 238 bottom
Phi_star=siggma_upsilon*(upsilon*(omega-1)+Gamma_star);                                                %p. 239
Phi_z=(1-upsilon)*Phi-siggma_upsilon*Gamma_z;                                                          %p. 239 


save paranews betta siggma varphi alppha epsilon theta upsilon rho_nu rho_a rho_y_star phi_pi phi_y eta rho_z Omega lambda omega Phi siggma_upsilon Gamma_a Gamma_star Gamma_z kappa_upsilon Phi_star Phi_z

dynare news13 noclearall nolog


IRF_outputgap=[];
IRF_employment=[];
IRF_domesticinflation=[];
IRF_CPIinflation=[];
IRF_domesticpricelevel=[];
IRF_consumerpricelevel=[];
IRF_tot=[];
IRF_nominalexchangerate=[];
IRF_nominalrate=[];
IRF_realrate=[];

IRF_outputgap=[IRF_outputgap, y_gap_eps_nu_news1];
IRF_employment=[IRF_employment, n_eps_nu_news1];
IRF_domesticinflation=[IRF_domesticinflation, pi_h_ann_eps_nu_news1];
IRF_CPIinflation=[IRF_CPIinflation, pi_ann_eps_nu_news1];
IRF_domesticpricelevel=[IRF_domesticpricelevel, p_h_eps_nu_news1];
IRF_consumerpricelevel=[IRF_consumerpricelevel, p_eps_nu_news1];
IRF_tot=[IRF_tot, s_eps_nu_news1];
IRF_nominalexchangerate=[IRF_nominalexchangerate, er_eps_nu_news1];
IRF_nominalrate=[IRF_nominalrate, i_ann_eps_nu_news1];
IRF_realrate=[IRF_realrate, r_real_ann_eps_nu_news1];

%%  news for 2 periods ahead

save paranews betta siggma varphi alppha epsilon theta upsilon rho_nu rho_a rho_y_star phi_pi phi_y eta rho_z Omega lambda omega Phi siggma_upsilon Gamma_a Gamma_star Gamma_z kappa_upsilon Phi_star Phi_z

dynare news13 noclearall nolog


IRF_outputgap=[IRF_outputgap, y_gap_eps_nu_news2];
IRF_employment=[IRF_employment, n_eps_nu_news2];
IRF_domesticinflation=[IRF_domesticinflation, pi_h_ann_eps_nu_news2];
IRF_CPIinflation=[IRF_CPIinflation, pi_ann_eps_nu_news2];
IRF_domesticpricelevel=[IRF_domesticpricelevel, p_h_eps_nu_news2];
IRF_consumerpricelevel=[IRF_consumerpricelevel, p_eps_nu_news2];
IRF_tot=[IRF_tot, s_eps_nu_news2];
IRF_nominalexchangerate=[IRF_nominalexchangerate, er_eps_nu_news2];
IRF_nominalrate=[IRF_nominalrate, i_ann_eps_nu_news2];
IRF_realrate=[IRF_realrate, r_real_ann_eps_nu_news2];

%%  news for 4 periods ahead

save paranews betta siggma varphi alppha epsilon theta upsilon rho_nu rho_a rho_y_star phi_pi phi_y eta rho_z Omega lambda omega Phi siggma_upsilon Gamma_a Gamma_star Gamma_z kappa_upsilon Phi_star Phi_z

dynare news13 noclearall nolog


IRF_outputgap=[IRF_outputgap, y_gap_eps_nu_news4];
IRF_employment=[IRF_employment, n_eps_nu_news4];
IRF_domesticinflation=[IRF_domesticinflation, pi_h_ann_eps_nu_news4];
IRF_CPIinflation=[IRF_CPIinflation, pi_ann_eps_nu_news4];
IRF_domesticpricelevel=[IRF_domesticpricelevel, p_h_eps_nu_news4];
IRF_consumerpricelevel=[IRF_consumerpricelevel, p_eps_nu_news4];
IRF_tot=[IRF_tot, s_eps_nu_news4];
IRF_nominalexchangerate=[IRF_nominalexchangerate, er_eps_nu_news4];
IRF_nominalrate=[IRF_nominalrate, i_ann_eps_nu_news4];
IRF_realrate=[IRF_realrate, r_real_ann_eps_nu_news4];

%% IRF (run section by section)

%figure1
%
plot (IRF_outputgap(:,1))
hold on
plot (IRF_outputgap(:,2))
hold on
plot (IRF_outputgap(:,3))
title('y_gap')
legend( 'news1', 'news2' , 'news4')

%% figure2
%
hold off
plot (IRF_employment(:,1))
hold on
plot (IRF_employment(:,2))
hold on
plot (IRF_employment(:,3))
title('n')
legend( 'news1', 'news2' , 'news4')

%% figure3
%
hold off
plot (IRF_domesticinflation(:,1))
hold on
plot (IRF_domesticinflation(:,2))
hold on
plot (IRF_domesticinflation(:,3))
title('domestic inflation')
legend( 'news1', 'news2' , 'news4')

%% figure4
%
plot (IRF_CPIinflation(:,1))
hold on
plot (IRF_CPIinflation(:,2))
hold on
plot (IRF_CPIinflation(:,3))
title('CPI inflation')
legend( 'news1', 'news2' , 'news4')

%% figure5

hold off
plot (IRF_domesticpricelevel(:,1))
hold on
plot (IRF_domesticpricelevel(:,2))
hold on
plot (IRF_domesticpricelevel(:,3))
title('domestic price level')
legend( 'news1', 'news2' , 'news4')

%% figure6
%
hold off
plot (IRF_consumerpricelevel(:,1))
hold on
plot (IRF_consumerpricelevel(:,2))
hold on
plot (IRF_consumerpricelevel(:,3))
title('consumer price level')
legend( 'news1', 'news2' , 'news4')

%% figure7
%
hold off
plot (IRF_tot(:,1))
hold on
plot (IRF_tot(:,2))
hold on
plot (IRF_tot(:,3))
title('tot')
legend( 'news1', 'news2' , 'news4')

%% figure8
%
hold off
plot (IRF_nominalexchangerate(:,1))
hold on
plot (IRF_nominalexchangerate(:,2))
hold on
plot (IRF_nominalexchangerate(:,3))
title('nominal exchange rate')
legend( 'news1', 'news2' , 'news4')

%% figure9
%
hold off
plot (IRF_nominalrate(:,1))
hold on
plot (IRF_nominalrate(:,2))
hold on
plot (IRF_nominalrate(:,3))
title('R')
legend( 'news1', 'news2' , 'news4')

%% figure10
%
hold off
plot (IRF_realrate(:,1))
hold on
plot (IRF_realrate(:,2))
hold on
plot (IRF_realrate(:,3))
title('real rate')
legend( 'news1', 'news2' , 'news4')

%%

subplot (1,1,1)
subplot (2,1,2)

