%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%High-Frequency Analysis and Moment-Matching Estimation%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%of the Baseline New-Keynesian Model%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%by Stephen Sacht (Doctoral Thesis/Chapters 2 & 3)%%%%%%%%%%%%%%
%%%%%%%%%%%%%%Matlab Source Code (c) by Stephen Sacht (2013)%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%Impulse Response Functions%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%(Stand-Alone Application)%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clear all;
close all;
clc;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
syms b1c
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
h=1/90; % Length of the period (relative to a quarter, where h=1)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
chi=0; % Habit formation parameter (must be set to zero)
alpha=0; % Price indexation parameter (must be set to zero)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
rho=0.0101; % Natural real rate of interest (households' preference rate)
sigma=1; % Intertemporal elasticity of substitution in consumption
eta=1; % Intertemporal elasticity of substitution of labour
theta=0.6667; % Calvo degree of price stickiness
phi_y=0.125; % Weight on the output gap in the Taylor rule
phi_pi=1.5; % Weight on the inflation rate in the Taylor rule
alpha1=1; % Monetary policy reaction with respect to the inflation rate
alpha2=0.05; % Monetary policy reaction with respect to the output gap
rf=90000; % Length of the impulse response functions (adjusted for w=90)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Shocks & Persistence in the shock process
epsi=0; % Impulse to the interest rate (in %)
epst=0; % Impulse to the demand (in %)
epsc=1; % Impulse to the inflation rate (in %)
avi=0; % Persistence in the interest rate shock
avt=0; % Persistence in the demand shock
avc=0.5; % Persistence in the inflation shock
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
rhovi=(1-h*(1-avi)); % Shock to be considered in the (hybrid) TR Case ONLY
rhovt=(1-h*(1-avt)); % Shock to be considered in the (hybrid) TR Case ONLY
rhovc=(1-h*(1-avc)); % ONLY Shock considered in the (non-hybrid) OMP Case
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Specification of composite parameters
thetah=1-h*(1-theta);
betah=1/(1+h*rho);
gamma_f=betah/(1+betah*alpha);
gamma_b=alpha/(1+betah*alpha);
kappah=(1/h)*((1-thetah)*(1-thetah*betah))/(thetah*(1+betah*alpha))*(sigma+eta);
delta_f=1/(1+chi);
delta_b=chi/(1+chi);
nu=(h*(1-chi))/(sigma*(1+chi));
nu2=(h*(1-chi)*(1+eta))/((1+chi)*(sigma+eta));
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% AR(1) Shock Process: E_0 v_t = rhov^t*eps_0
for t=1:rf
vi(t)=(rhovi^(t-1))*epsi; % Shock considered in the (hybrid) TR Case ONLY
vt(t)=(rhovt^(t-1))*epst; % Shock considered in the (hybrid) TR Case ONLY
vc(t)=(rhovc^(t-1))*epsc; % ONLY Shock considered in the (non-hybrid) OMP Case
end;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%A*x_t+B*x_{t+h}+C*x_{t-h}+D*v_t=0 with x_t=[y_t; pi_t];
%v_t=N*v_t-h+eps=0 with v_t=[v^(interest); v^{demand}_t; v^{cost}_t];
A=[1+nu*phi_y nu*phi_pi; -kappah 1]; % System
B=[-delta_f -nu; 0 -gamma_f]; % Matrices
C=[-delta_b 0; 0 -gamma_b]; % for the
N=[rhovi 0 0; 0 rhovt 0; 0 0 rhovc]; % hybrid
D=[nu -nu2*(rhovt-1) 0; 0 0 -1]; % NKM model
%CLAIM: x_t=Omega+x_{t-h}+Phi*v_t;
for i=2:rf; % i=Iterations
Omega{1}=0.8*eye(2,2);
Omega{i}=-inv(B*Omega{i-1}+A)*C;
end;
for ii=2:rf; % ii=Iterations
Phi{1}=0.8*ones(2,3);
Phi{ii}=-inv(A+B*Omega{10000})*(B*Phi{ii-1}*N+D);
end;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
d0=-alpha2/(h*kappah*alpha1); % Solution of the model
d1=kappah-d0; % under the monetary
d2=betah*d0; % policy regime
d3=-1/(d1+d2*rhovc); % 'Discretion'
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
c0=h*alpha1*kappah/alpha2; % Solution of
c1=1+h*alpha1*(kappah^2)/alpha2+betah^(2-h); % the model
c2=-betah^(1-h); % under the
c3=-betah; % monetary
b1c = solve(b1c^2 + (c1/c3)*b1c + (c2/c3),b1c); % policy regime
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
b1c1=double(b1c(1));
b1c2=double(b1c(2));
if abs(b1c1)<1 && abs(b1c2)>1
cbk=b1c1;
elseif abs(b1c1)>1 && abs(b1c2)<1
cbk=b1c2;
else
disp('Blancher-Kahn condition is not satisfied: Both Eigenvalues lie outside the unit circle!')
end;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
b2c = -c0/(c1+c3*(cbk+rhovc)); % 'Commitment'
cs=(b2c*(cbk-betah^(1-h)))/(cbk-rhovc); % (code lines 91-100 choose stable eigenvalue)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Dynamics in the state variables (TAYLOR RULE; hybrid NKM)
ytr(rf)=zeros;
pitr(rf)=zeros;
re(rf)=zeros;
ir(rf)=zeros;
pitrf(rf)=zeros;
pitrf(1:rf-1)=pitr(2:rf);
p(rf)=zeros;
p(1)=pitr(1);
for t=1:rf
ytr(t)=Phi{rf}(1,3)*rhovc^(t-1)*epsc; % Ouput Gap (TR)
pitr(t)=Phi{rf}(2,3)*rhovc^(t-1)*epsc; % Inflation Rate (TR)
ir(t)=phi_pi*pitr(t)+phi_y*ytr(t); % Interest Rate (TR)
re(t)=ir(t)-pitrf(t); % Real Interest Rate (TR)
end;
for t=2:rf
p(t)=pitr(t)+p(t-1); % Price Level (TR)
end;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Dynamics in the state variables (DISCRETION; forward-looking only)
yd(rf)=zeros;
pid(rf)=zeros;
ird(rf)=zeros;
red(rf)=zeros;
yfd(rf)=zeros;
yfd(1:rf-1)=yd(2:rf);
pifd(rf)=zeros;
pifd(1:rf-1)=pid(2:rf);
pd(rf)=zeros;
pd(1)=pid(1);
for t=1:rf
yd(t)=d3*rhovc^(t-1)*epsc; % Ouput Gap (D)
pid(t)=d0*d3*rhovc^(t-1)*epsc; % Inflation Rate (D)
ird(t)=((delta_f*yfd(t)-yd(t))/nu)+pifd(t); % Interest Rate (D)
red(t)=ird(t)-pifd(t); % Real Interest Rate (D)
end;
for t=2:rf
pd(t)=pid(t)+pd(t-1); % Price Level (D)
end;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Dynamics in the state variables (COMMITMENT; forward-looking only)
yc(rf)=zeros;
pic(rf)=zeros;
irc(rf)=zeros;
rec(rf)=zeros;
yfc(rf)=zeros;
yfc(1:rf-1)=yc(2:rf);
pifc(rf)=zeros;
pifc(1:rf-1)=pic(2:rf);
pc(rf)=zeros;
pc(1)=pic(1);
for t=1:rf
yc(t)=(b2c*(cbk^(t)-rhovc^(t)))/(cbk-rhovc)*epsc; % Output Gap (COM)
pic(t)=-1/c0*(cs*cbk^(t-1)-(cs-b2c)*rhovc^(t-1))*epsc; % Inflation Rate (COM)
irc(t)=((delta_f*yfc(t)-yc(t))/nu)+pifc(t); % Interest Rate (COM)
rec(t)=irc(t)-pifc(t); % Real Interest Rate (COM)
end;
for t=2:rf
pc(t)=pic(t)+pc(t-1); % Price Level (COM)
end;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
aa(rf)=zeros; % Adjustment of the x-axis for h<1
for k=1:rf;
aa(k)=(k-1)*h;
end;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
H90=zeros(rf,19);
H90(:,:)=[ytr',pitr',ir',re',p',vi',vt',vc',aa',yd',pid',ird',red',pd',yc',pic',irc',rec',pc'];
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
figure('Name','Daily h-economy','NumberTitle','off');
subplot(3,2,1);
plot(H90(:,9),H90(:,1),'r--',H90(:,9),H90(:,10),'k-',H90(:,9),H90(:,15),'b:','LineWidth',1.5);
xlim([-0.5 20]);
legend('Regime TR','Regime D','Regime C','Location','SouthEast');
title('Output Gap','FontSize',14)
subplot(3,2,2);
plot(H90(:,9),H90(:,2),'r--',H90(:,9),H90(:,11),'k-',H90(:,9),H90(:,16),'b:','LineWidth',1.5);
xlim([-0.5 20]);
title('Inflation Rate','FontSize',14)
subplot(3,2,3);
plot(H90(:,9),H90(:,3),'r--',H90(:,9),H90(:,12),'k-',H90(:,9),H90(:,17),'b:','LineWidth',1.5);
xlim([-0.5 20]);
title('Nominal Interest Rate','FontSize',14)
subplot(3,2,4);
plot(H90(:,9),H90(:,4),'r--',H90(:,9),H90(:,13),'k-',H90(:,9),H90(:,18),'b:','LineWidth',1.5);
xlim([-0.5 20]);
title('Real Interest Rate','FontSize',14)
subplot(3,2,5);
plot(H90(:,9),H90(:,5),'r--',H90(:,9),H90(:,14),'k-',H90(:,9),H90(:,19),'b:','LineWidth',1.5);
xlim([-0.5 20]);
title('Price Level','FontSize',14)
subplot(3,2,6);
plot(H90(:,9),H90(:,6),'k-',H90(:,9),H90(:,7),'k-',H90(:,9),H90(:,8),'k-','LineWidth',1.5);
xlim([0 20]);
title('Shock Process','FontSize',14)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%