clear
clc
rmpath(genpath('/Users/francescosimeone/Desktop/applied macroeconomics/project/VAR-Toolbox-main/v3dot0/'))
returns = readmatrix('database_mpshocks_infoshocks.xlsx', 'Range', 'B:H', 'NumHeaderLines', 1);
Y= returns(:, [1, 3]);
Mdl = varm(2,3);
Mdl.SeriesNames = {'Transformed real GDP','Transformed real 3-mo T-bill rate'};
EstMdl = estimate(Mdl,Y);
[YIRF,h] = armairf(EstMdl.AR,{},'InnovCov',EstMdl.Covariance);
defGDPImp = ret2price(YIRF(:,2,1));
figure;
numobs = size(defGDPImp,1);
plot(0:numobs - 1,defGDPImp);
title('Impact of Shock to Interest Rate on Deflated GDP')
ylabel('Deflated GDP');
xlabel('Time');
rng(1); % For reproducibility
%[Response,Lower,Upper] = irf(EstMdl);
[Response, Lower, Upper] = irf(EstMdl, 'Confidence', 0.68);
irfshock2resp3 = Response(:,1,2);
IRFCIShock2Resp3 = [Lower(:,1,2) Upper(:,1,2)];
figure;
h1 = plot(0:19,irfshock2resp3);
hold on
h2 = plot(0:19,IRFCIShock2Resp3,"r--");
legend([h1 h2(1)],["IRF" "68% Confidence Interval"])
xlabel("Time Index");
ylabel("Response");
title("IRF of IB When Y Is Shocked");
grid on
hold off