clear all
close all

x=load('us.txt');
time = x(:,1);
gdp = x(:,2);
cpi = x(:,4);

lgdp = log(gdp);
lcpi = log(cpi);

figure(1)
subplot(2,1,1)
plot(time,cpi)
title('CPI')
subplot(2,1,2)
plot(time,gdp)
title('GDP')

lgdp_trend = hp(lgdp,1600); % gdp trend (extracted by HP filter)
lgdp_gap = lgdp - lgdp_trend;  % calculation of gap

%[lgdp_trend, lgdp_gap] = hp(lgdp,1600); % alternative way

figure
plot(time,[lgdp, lgdp_trend])
legend('log of gdp', 'gdp trend')

figure
plot(time,lgdp_gap*100)
legend('gdp gap')
grid

pie4 = lcpi(5:end) - lcpi(1:end-4); % y/y inflation rate
pie4 = [nan(4,1);pie4];

figure
plot(time,lgdp_gap, time, pie4,'r')
legend('gdp gap','\pi')
grid

corr1 = corrfn(cpi,gdp,0);          % correlation - non stationary data
corr2 = corrfn(pie4, lgdp_gap, 0);  %             - stationary data

% positive corr coef = demand shocks prevailed
% negative corr coef = supply shocks


% alternative way of stationarization
lgdp_gr = lgdp(2:end) - lgdp(1:end-1);   % growth rate of gdp
lgdp_gr = [nan;lgdp_gr];

figure
plot(time,lgdp_gr,'m',time,pie4,'r')
legend('growth rate gdp','\pi_t')
grid

