clear all
close all

addpath c:\dynare\5.0\matlab

% set parameters
beta = 0.995;
kappa = 1-40^(-1);
spF = 0.03;
spB = 0.01;
psi = 0.81;
epsip = 11;
epsiw = 11;
alpha = 1/3;
delta0 = 0.025;
g = 0.2;
bb = 0.8; 
bcs = 0.1; % 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;

% solve for steady state
Rds = beta^(-1);
RFs = (1+spF)^(1/4)*Rds;
RBs = (1+spB)^(1/4)*Rds;
Qs = (RFs - kappa)^(-1);
QBs = (RBs - kappa)^(-1);
M1s = beta/(Qs*(1-beta*kappa));
M2s = 1 + (M1s-1)*psi;
pws = (epsip-1)/epsip;
Ks = (alpha*pws/(M2s*(1/beta - (1-delta0))))^(1/(1-alpha));
Ys = Ks^(alpha);
Is = delta0*Ks;
ws = (1-alpha)*pws*Ks^(alpha);
delta1 = (alpha*pws*Ks^(alpha-1)/M2s);
Cs = (1-g)*Ys - Is;
mus = (1/Cs)*(1-beta*bb)/(1-bb);
mrss = ((epsiw-1)/epsiw)*ws;
chi = mus*mrss;
fws = psi*Is/(Qs*(1-kappa));
res = bcs*Ys;
bcbs = bcbGs*res/QBs;
fcbs = (res - QBs*bcbs)/Qs;
fs = fws - fcbs;
bGs = by*Ys/QBs;
bs = bGs - bcbs;
ns = (Qs*fs + QBs*bs + res)/levs;
ds = Qs*fs + QBs*bs + res - ns;
Delta = (RBs - Rds)/(RFs - Rds);
phis = (Qs*fs + Delta*QBs*bs)/ns;
thetas = (1 - sigma + phis*beta*(1-sigma)*(RFs - Rds))/((1-sigma)*phis - beta*sigma*phis^2*(RFs - Rds));
X = ns - sigma*( (RFs-Rds)*Qs*fs + (RBs - Rds)*QBs*bs + Rds*ns);
Omegas = 1 - sigma + sigma*phis*thetas;
lams = (thetas/(beta*(RFs - Rds)*(1-sigma + sigma*phis*thetas)) - 1)^(-1);

% parameters unrelated to steady state
phip = 0.75;
phiw = 0.75;
psik = 2; % capital 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;
rhoB = 0.9;
sB = 0.9;



save param_sw beta kappa spF spB psi epsip epsiw alpha delta0 g bb bcs bcbGs by levs sigma Rds RFs RBs Qs QBs M1s M2s pws Ks Ys Is ws delta1 Cs mus mrss chi fws res bcbs fcbs fs bGs bs ns ds Delta phis thetas X Omegas lams phip phiw psik delta2 eta rhor phipi phiy sr rhof rhob sf sb rhoA sA rhot st rhoG sG rhoB sB


dynare sw_2020 noclearall nolog


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

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

subplot(3,3,3)
plot(logC_ef,'-k','Linewidth',1.5)
title('C')

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

subplot(3,3,5)
plot(logLd_ef,'-k','Linewidth',1.5)
title('L_{d}')

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

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

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

subplot(3,3,9)
plot(exr_ef,'-k','Linewidth',1.5)
title('E_{t}r_{t+1}^{F} - r_{t}^{d}')
legend('Private QE')

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

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

subplot(3,3,3)
plot(logC_eb,'-k','Linewidth',1.5)
title('C')

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

subplot(3,3,5)
plot(logLd_eb,'-k','Linewidth',1.5)
title('L_{d}')

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

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

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

subplot(3,3,9)
plot(exr_eb,'-k','Linewidth',1.5)
title('E_{t}r_{t+1}^{F} - r_{t}^{d}')
legend('Public QE')


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

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

subplot(3,3,3)
plot(logC_et,'-k','Linewidth',1.5)
title('C')

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

subplot(3,3,5)
plot(logLd_et,'-k','Linewidth',1.5)
title('L_{d}')

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

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

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

subplot(3,3,9)
plot(exr_et,'-k','Linewidth',1.5)
title('E_{t}r_{t+1}^{F} - r_{t}^{d}')
legend('Credit Shock')

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

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

subplot(3,3,3)
plot(logC_eB,'-k','Linewidth',1.5)
title('C')

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

subplot(3,3,5)
plot(logLd_eB,'-k','Linewidth',1.5)
title('L_{d}')

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

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

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

subplot(3,3,9)
plot(exr_eB,'-k','Linewidth',1.5)
title('E_{t}r_{t+1}^{F} - r_{t}^{d}')
legend('Gov. Debt Shock')

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

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

subplot(3,3,3)
plot(logC_eG,'-k','Linewidth',1.5)
title('C')

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

subplot(3,3,5)
plot(logLd_eG,'-k','Linewidth',1.5)
title('L_{d}')

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

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

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

subplot(3,3,9)
plot(exr_eG,'-k','Linewidth',1.5)
title('E_{t}r_{t+1}^{F} - r_{t}^{d}')
legend('Gov. Spending Shock')

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

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

subplot(3,3,3)
plot(logC_eA,'-k','Linewidth',1.5)
title('C')

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

subplot(3,3,5)
plot(logLd_eA,'-k','Linewidth',1.5)
title('L_{d}')

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

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

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

subplot(3,3,9)
plot(exr_eA,'-k','Linewidth',1.5)
title('E_{t}r_{t+1}^{F} - r_{t}^{d}')
legend('Productivity Shock')


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

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

subplot(3,3,3)
plot(logC_er,'-k','Linewidth',1.5)
title('C')

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

subplot(3,3,5)
plot(logLd_er,'-k','Linewidth',1.5)
title('L_{d}')

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

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

subplot(3,3,8)
plot(exr_er,'-k','Linewidth',1.5)
title('E_{t}r_{t+1}^{F} - r_{t}^{d}')
legend('Monetary Shock')