clear all
close all

addpath c:\dynare\4.6.4\matlab

% set parameters
beta1 = 0.99;
beta2 = 0.97;
j = 0.1;
m = 0.8;
kappa = 1-40^(-1);
deltah = 0.01;
spF = 0.03;
spB = 0.01;
epsip = 11;
alpha = 1/3;
delta0 = 0.025;
g = 0.2;
bb = 0.8; 
bcs = 0.2; % central bank balance sheet / Y
bcbGs = 0.9; % percentage of balance sheet holding government bonds
by = 0.5; % steady state government debt / GDP
levs = 5;
sigma = 0.95;
nu = 0.5;

% solve for steady state
Rds = beta1^(-1);
RFs = (1+spF)^(1/4)*Rds;
RBs = (1+spB)^(1/4)*Rds;
Rres = Rds;
Qs = (RFs - kappa)^(-1);
QBs = (RBs - kappa)^(-1);
pms = (epsip-1)/epsip;
Ks = (alpha*pms/(1/beta1 - (1-delta0)))^(1/(1-alpha));
Ys = Ks^(alpha);
Is = delta0*Ks;
w1s = (1-alpha)*nu*pms*Ks^(alpha);
w2s = (1-alpha)*(1-nu)*pms*Ks^(alpha);
delta1 = alpha*pms*Ks^(alpha-1);
varsigma1 = j*(1-bb)/((1-beta1*(1-deltah))*(1-beta1*bb));
varsigma2 = j*(1-bb)/((1-beta2*(1-deltah))*(1 - m*((1-beta2*RFs)/(RFs*(1-beta2*kappa))))*(1-beta2*bb));
varsigma3 = bcs*(RFs*(1-bcbGs) + RBs*bcbGs - beta1^(-1));
varsigma4 = (g + by*QBs^(-1)*(1 - QBs*(1-kappa)) - varsigma3)/2;
varsigma5 = ((1-alpha)*(1-nu)*pms - varsigma4)/(1 + deltah*varsigma2 - m*deltah*varsigma2*(Qs*(1-kappa) - 1)/(Qs*(1-kappa)*RFs));
varsigma6 = (1 - g - delta0*Ks^(1-alpha) - (1 + deltah*varsigma2)*varsigma5)/(1 + deltah*varsigma1);
C2s = varsigma5*Ys;
fs = m*deltah*C2s*varsigma2/(Qs*(1-kappa)*RFs);
C1s = varsigma6*Ys;
mu1s = (1-beta1*bb)/(C1s*(1-bb));
mu2s = (1-beta2*bb)/(C2s*(1-bb));
mu3s = - mu2s*(1-beta2*RFs)/(RFs*(1-beta2*kappa));
H1s = varsigma1*varsigma6*Ys;
H2s = varsigma2*varsigma5*Ys;
IHs = deltah*(H1s + H2s);
chi1 = mu1s*w1s;
chi2 = mu2s*w2s;
res = bcs*Ys;
bcbs = bcbGs*res/QBs;
fcbs = (res - QBs*bcbs)/Qs;
fprs = fs - fcbs;
bGs = by*Ys/QBs;
bs = bGs - bcbs;
ns = (Qs*fprs + QBs*bs + res)/levs;
ds = Qs*fprs + QBs*bs + res - ns;
Delta = (RBs - Rds)/(RFs - Rds);
phis = (Qs*fprs + Delta*QBs*bs)/ns;
thetas = (1 - sigma + phis*beta1*(1-sigma)*(RFs - Rds))/((1-sigma)*phis - beta1*sigma*phis^2*(RFs - Rds));
X = ns - sigma*( (RFs-Rds)*Qs*fprs + (RBs - Rds)*QBs*bs + Rds*ns);
Omegas = 1 - sigma + sigma*phis*thetas;
lams = (thetas/(beta1*(RFs - Rds)*(1-sigma + sigma*phis*thetas)) - 1)^(-1);

% parameters unrelated to steady state
phip = 0.75;
psik = 2; % capital adjustment cost
psih = 2; % housing adjustment cost
delta2 = 0.01; % squared term capital adjustment cost
eta = 1; % Frisch elasticity

% Taylor rule
rhor = 0.8;
phipi = 1.5;
phiy = 0.15;
sr = 0.0025;

% Shock processes
rhof = 0.97;
rhob = 0.97;
sf = 0.01;
sb = 0.01;
rhoA = 0.9;
sA = 0.01;
rhot = 0.95;
st = 0.01;
rhoG = 0.9;
sG = 0.01;



save param_lrh beta1 beta2 j m kappa deltah spF spB epsip alpha delta0 g bb bcs bcbGs by levs sigma nu Rds RFs RBs Rres Qs QBs pms Ks Ys Is w1s w2s delta1 varsigma1 varsigma2 varsigma3 varsigma4 varsigma5 varsigma6 C1s C2s H1s H2s IHs mu1s mu2s mu3s chi1 chi2 fprs res bcbs fcbs fs bGs bs ns ds Delta phis thetas X Omegas lams phip psik psih delta2 eta rhor phipi phiy sr rhof rhob sf sb rhoA sA rhot st rhoG sG


dynare lrh_2023 noclearall nolog


figure
subplot(3,3,1)
plot(fcb_ef,'-k','Linewidth',1.5)
title('f_{cb}')

subplot(3,3,2)
plot(Y_ef,'-k','Linewidth',1.5)
title('Y')

subplot(3,3,3)
plot(C1_ef,'-k','Linewidth',1.5)
title('C_{1}')

subplot(3,3,4)
plot(mu3_ef,'-k','Linewidth',1.5)
title('\mu_3')

subplot(3,3,5)
plot(C2_ef,'-k','Linewidth',1.5)
title('C_{2}')

subplot(3,3,6)
plot(Pi_ef,'-k','Linewidth',1.5)
title('\pi')

subplot(3,3,7)
plot(Rd_ef,'-k','Linewidth',1.5)
title('r^{d}')

subplot(3,3,8)
plot(q_ef,'-k','Linewidth',1.5)
title('q')

subplot(3,3,9)
plot(H2_ef,'-k','Linewidth',1.5)
title('H_{2}')
legend('Private QE')

figure
subplot(3,3,1)
plot(bcb_eb,'-k','Linewidth',1.5)
title('b_{cb}')

subplot(3,3,2)
plot(Y_eb,'-k','Linewidth',1.5)
title('Y')

subplot(3,3,3)
plot(C1_eb,'-k','Linewidth',1.5)
title('C_{1}')

subplot(3,3,4)
plot(I_eb,'-k','Linewidth',1.5)
title('I')

subplot(3,3,5)
plot(H1_eb,'-k','Linewidth',1.5)
title('H_{1}')

subplot(3,3,6)
plot(Pi_eb,'-k','Linewidth',1.5)
title('\pi')

subplot(3,3,7)
plot(Rd_eb,'-k','Linewidth',1.5)
title('r^{d}')

subplot(3,3,8)
plot(Q_eb,'-k','Linewidth',1.5)
title('Q')

subplot(3,3,9)
plot(H2_eb,'-k','Linewidth',1.5)
title('H_{2}')
legend('Public QE')


figure
subplot(3,3,1)
plot(theta_et,'-k','Linewidth',1.5)
title('\theta')

subplot(3,3,2)
plot(Y_et,'-k','Linewidth',1.5)
title('Y')

subplot(3,3,3)
plot(C1_et,'-k','Linewidth',1.5)
title('C_{1}')

subplot(3,3,4)
plot(I_et,'-k','Linewidth',1.5)
title('I')

subplot(3,3,5)
plot(H1_et,'-k','Linewidth',1.5)
title('H_{1}')

subplot(3,3,6)
plot(Pi_et,'-k','Linewidth',1.5)
title('\pi')

subplot(3,3,7)
plot(Rd_et,'-k','Linewidth',1.5)
title('r^{d}')

subplot(3,3,8)
plot(Q_et,'-k','Linewidth',1.5)
title('Q')

subplot(3,3,9)
plot(H2_et,'-k','Linewidth',1.5)
title('H_{2}')
legend('Credit Shock')


figure
subplot(3,3,1)
plot(G_eG,'-k','Linewidth',1.5)
title('G')

subplot(3,3,2)
plot(Y_eG,'-k','Linewidth',1.5)
title('Y')

subplot(3,3,3)
plot(C1_eG,'-k','Linewidth',1.5)
title('C_{1}')

subplot(3,3,4)
plot(I_eG,'-k','Linewidth',1.5)
title('I')

subplot(3,3,5)
plot(H1_eG,'-k','Linewidth',1.5)
title('H_{1}')

subplot(3,3,6)
plot(Pi_eG,'-k','Linewidth',1.5)
title('\pi')

subplot(3,3,7)
plot(Rd_eG,'-k','Linewidth',1.5)
title('r^{d}')

subplot(3,3,8)
plot(Q_eG,'-k','Linewidth',1.5)
title('Q')

subplot(3,3,9)
plot(H2_eG,'-k','Linewidth',1.5)
title('H_{2}')
legend('Gov. Spending Shock')

figure
subplot(3,3,1)
plot(A_eA,'-k','Linewidth',1.5)
title('A')

subplot(3,3,2)
plot(Y_eA,'-k','Linewidth',1.5)
title('Y')

subplot(3,3,3)
plot(C1_eA,'-k','Linewidth',1.5)
title('C_{1}')

subplot(3,3,4)
plot(I_eA,'-k','Linewidth',1.5)
title('I')

subplot(3,3,5)
plot(H1_eA,'-k','Linewidth',1.5)
title('H_{1}')

subplot(3,3,6)
plot(Pi_eA,'-k','Linewidth',1.5)
title('\pi')

subplot(3,3,7)
plot(Rd_eA,'-k','Linewidth',1.5)
title('r^{d}')

subplot(3,3,8)
plot(Q_eA,'-k','Linewidth',1.5)
title('Q')

subplot(3,3,9)
plot(H2_eA,'-k','Linewidth',1.5)
title('H_{2}')
legend('Productivity Shock')


figure
subplot(3,3,1)
plot(Rd_er,'-k','Linewidth',1.5)
title('r^{d}')

subplot(3,3,2)
plot(Y_er,'-k','Linewidth',1.5)
title('Y')

subplot(3,3,3)
plot(C1_er,'-k','Linewidth',1.5)
title('C_{1}')

subplot(3,3,4)
plot(I_er,'-k','Linewidth',1.5)
title('I')

subplot(3,3,5)
plot(H1_er,'-k','Linewidth',1.5)
title('H_{1}')

subplot(3,3,6)
plot(Pi_er,'-k','Linewidth',1.5)
title('\pi')

subplot(3,3,7)
plot(Q_er,'-k','Linewidth',1.5)
title('Q')

subplot(3,3,8)
plot(H2_er,'-k','Linewidth',1.5)
title('H_{2}')
legend('Monetary Shock')