close all
clear all

x = load('us2.txt');
t = x(:,1);
cpi = x(:,3);
ir = x(:,7);

n = length(t);
lcpi = log(cpi);

pie4 = (lcpi - lag(lcpi,4))*100;
%pie4 = lcpi(5:end) - lcpi(1:end-4);
%pie4 = [nan(4,1); pie4]*100;

%pie4 = (cpi ./ lag(cpi,4) - 1 )*100;

rir = ir(1:end-4) - pie4(5:end);
rir = [rir;nan(4,1)];

X = [ones(n,1) lag(rir,1)];
b = ols(rir, X);

rir_eq = b(1,1)/(1-b(2,1));
rir_eq_plot = ones(n,1)*rir_eq;

figure
plot([rir rir_eq_plot])
legend('realna ur. mira','rovnovazna ur. mira')
ylabel('%')

rirx = 5;
for i = 2:200
    rirx(i) = b(1,1) + b(2,1)*rirx(i-1);
end

figure
plot(rirx)

se2store = zeros(n,1);

%for k = 30:60

k = 39;
    aux = zeros(n,1);
    aux(k:end) = 1;
    [c se2] = ols(rir,[aux X]);
    se2store(k) = se2;
%end
    
%m = min(se2store(30:60));
%k = find(se2store==m);

rir_eq1 = c(2,1)/(1-c(3,1));
rir_eq2 = (c(1,1)+c(2,1))/(1-c(3,1));

rir_eq1_plot = nan(n,1);
rir_eq2_plot = nan(n,1);

rir_eq1_plot(1:k-1) = rir_eq1;
rir_eq2_plot(k:end) = rir_eq2;

figure
plot(t,rir,'r')
hold on
plot(t,rir_eq1_plot)
plot(t,rir_eq2_plot)
legend('realna ur. mira','rovnovazna hodnota')
title('Strukturalni zmena')
ylabel('%')
grid


























    
    
    
    
    
    





    
    
    
    
    

