clear all
close all

% set parameters
alpha      = 0.34;
beta       = 0.97;
sigma      =0.84;
eta        = 1.17;
zeta       = 1;
delta      = 0.059;
nu         = 3;
r_ss       = 1/beta-1;
z_ss       = 1;  
rho_z      = 0.139;
sigma_z    = 0.01;
varphi_ss  =4.6;
rho_varphi =0.9;
sigma_varphi=0.01;
w          = 1;
r_eps      =0;
chi        = 0.1;

% solve for steady state
r_ss = 1/beta - 1;
z = z_ss;
varphi=varphi_ss;
Lam = beta;
varthetas=0.0034;
kns = ((1- beta*(1-delta))/alpha*(beta+varthetas*varphi_ss))^(1/(alpha-1));
thetas=0.1;
bns=-varphi_ss*(kns^(alpha)-(1-thetas)*w)*(1+r_ss);
dns=kns^(alpha)-w-delta*kns-r_ss*bns/(1+r_ss);
cns = kns^(alpha) - delta*kns-(1-chi)*dns;
%thetas = ((1-alpha)*kns^(alpha)*(1+varthetas*varphi_ss)-w*beta*(1-beta^(nu-1))/(1-beta)*nu)/(w*(1+varthetas*varphi_ss) -beta*(1-beta^(nu-1))/nu*(1-beta));
nss =(w*cns^(-sigma)*(1-thetas+thetas*(beta+beta^2+beta^3)/nu)/zeta)^(1/(eta+sigma));
ks = kns*nss;
cs = cns*nss;
ds=dns*nss;
bs=bns*nss;
ys = ks^(alpha)*nss^(1-alpha);
is = delta*ks;
us2 = (1/(1-beta))*(cs^(1-sigma)/(1-sigma) + zeta*nss^(1+eta)/(1+eta));

save test2_1param alpha beta sigma eta zeta delta nu r_ss z_ss rho_z sigma_z varphi_ss rho_varphi sigma_varphi w r_eps thetas nss ks cs ys varthetas r_eps chi 

dynare test2_1 noclearall nolog

figunits = 'centimeters';
figsize = [16, 10] * 1.25;
figposition = [-1, -0.5, figsize(1)+2, figsize(2)+1];

% Default figure settings
set(groot, ...
    'DefaultAxesTickLabelInterpreter',     'latex',   ...
    'DefaultColorbarTickLabelInterpreter', 'latex',   ...
    'DefaultLegendInterpreter',            'latex',   ...
    'DefaultTextInterpreter',              'latex',   ...
    'DefaultTextboxshapeInterpreter',      'latex',   ...
    'DefaultFigurePaperUnits',             figunits, ...
    'DefaultFigurePaperPositionMode',      'manual'   ...
)

% Subplot grid layout
nrows = 3;
ncols = 2;

%IRFs = { i_e_z, oo_.irfs.nd_e_z, b_e_z, oo_.irfs.theta_e_z, z_e_z};
%varnames = { 'Investment', 'Labor Demand', 'Borrowing', 'Stock Compensation', 'Productivity'};

IRFs = { i_e_varphi, oo_.irfs.nd_e_varphi, b_e_varphi, oo_.irfs.theta_e_varphi, oo_.irfs.varphi_e_varphi};
varnames = { 'Investment', 'Labor Demand', 'Borrowing', 'Stock Compensation', 'Financial Shock'};

irf_fig = figure('Name', 'Model IRFs to productivity shocks', ...
                 'PaperSize', figsize, ...
                 'PaperPosition', figposition);
for i = 1 : nrows
  for j = 1 : ncols
    l = (i-1) * ncols + j;
    if l < 6
      subplot(nrows, ncols, l)
        plot(IRFs{l} * 100, 'Color', 'Black', 'LineWidth', 1)
        yline(0, 'Color', 'Black', 'LineStyle', '--');
        title(varnames{l})
        box off
        if i == nrows; xlabel('Years'); end
        if j == 1; ylabel('\% dev.'); end
    end
  end
end

print(irf_fig, '-dpdf', './rbc_irf.pdf')

