clear all
close all

x = load('us.txt');
lgdp = log(x(:,2));
lcpi = log(x(:,4));
ir = x(:,5)/100;

pie = 4*(lcpi - lag(lcpi,1));

[lgdp_trend, lgdp_gap] = hp(lgdp, 1600);
[pie_trend, pie_gap] = hp(pie, 1600);
[ir_trend, ir_gap] = hp(ir, 1600);

rir_gap = lag(ir_gap,1) - pie_gap;


X1 = [lag(lgdp_gap,1) rir_gap ];
X2 = [lag(pie_gap,1), lgdp_gap];
X3 = [lag(ir_gap,1), pie_gap, lgdp_gap];

a = ols(lgdp_gap,X1);
b = ols(pie_gap, X2);
c = ols(ir_gap, X3);

alpha = a(1,1);
beta = a(2,1);
gamma = b(1,1);
delta = b(2,1);
omega = c(1,1);
kappa = c(2,1);
lambda = c(3,1);

A = [1  beta  0
    -delta 1  0
    -lambda -kappa 1];

B = [alpha 0  beta
    0   gamma  0
    0     0   omega];


C = inv(A)*B;
D = inv(A);


eigenvalues = abs(eig(C));

x = zeros([3,20]);
epsilon = [1;0;0];

x(:,1) = D*epsilon;

for k = 2:20
    x(:,k) = C * x(:,k-1);
end

figure
plot(x')
legend('mezera y','mezera \pi','mezera i')
title('Impulsni odezvy')
ylabel('odchylka od s.s.')
grid












































    





