%Set up the Import Options and import the data
clear all
close all
clc
opts = spreadsheetImportOptions("NumVariables", 7);

% Specify sheet and range
opts.Sheet = "Hárok1";
opts.DataRange = "A2:G122";

% Specify column names and types
opts.VariableNames = ["Var1", "Real_GDP", "IR", "HPI", "CPI", "Consumption", "Investment"];
opts.SelectedVariableNames = ["Real_GDP", "IR", "HPI", "CPI", "Consumption", "Investment"];
opts.VariableTypes = ["char", "double", "double", "double", "double", "double", "double"];

% Specify variable properties
opts = setvaropts(opts, "Var1", "WhitespaceRule", "preserve");
opts = setvaropts(opts, "Var1", "EmptyFieldRule", "auto");

% Import the data
projektmamo = readtable("C:\Users\tomas\OneDrive\Documents\MAMO\Projekt\projekt_mamo.xlsx", opts, "UseExcel", false);

%% Convert to output type
projektmamo = table2array(projektmamo);

%% Clear temporary variables
clear opts
%%

x = projektmamo;

gdp = x(:,1);
i = x(:,6);
c = x(:,5);
q = x(:,3);
ir = x(:,2);
pi = x(:,4);

gdp = log(gdp);
c = log(c);
i = log(i);
q = log(q);
ir = ir./400;
pi = log(pi);

[gdp_t,gdp_gap]=hp(gdp,1600);
[c_t,c_gap]=hp(c,1600);
[i_t,i_gap]=hp(i,1600);
[q_t,q_gap]=hp(q,1600);
[ir_t,ir_gap]=hp(ir,1600);
[pi_t,pi_gap]=hp(pi,1600);

%gdp_gap = gdp_gap*100;
%c_gap = c_gap*100;
%i_gap = i_gap*100;
%q_gap = q_gap*100;
%ir_gap = ir_gap*100;
%pi_gap = pi_gap*100;

t = (1992.00:0.25: 2022.00)';
%%
figure
set(gcf,'Name','Data for estimation (hp filtered)');

subplot(321)
plot(t,gdp_gap,'b.-')
title('Output gap')
axis([min(t)-0.25, max(t)+0.25, min(gdp_gap)-0.015 max(gdp_gap)+0.015])

subplot(322)
plot(t,q_gap,'b.-')
title('Real house price gap')
axis([min(t)-0.25, max(t)+0.25, min(q_gap)-0.015 max(q_gap)+0.015])

subplot(323)
plot(t,pi_gap,'b.-')
title('Inflation gap (cpi)')
axis([min(t)-0.25, max(t)+0.25, min(pi_gap)-0.015 max(pi_gap)+0.015])

subplot(324)
plot(t,ir_gap,'b.-')
title('Nominal interest rate gap')
axis([min(t)-0.25, max(t)+0.25, min(ir_gap)-0.0025 max(ir_gap)+0.0025])

subplot(325)
plot(t,c_gap,'b.-')
title('Consumption gap')
axis([min(t)-0.25, max(t)+0.25, min(c_gap)-0.0025 max(c_gap)+0.0025])

subplot(326)
plot(t,i_gap,'b.-')
title('Investment gap')
axis([min(t)-0.25, max(t)+0.25, min(i_gap)-0.0025 max(i_gap)+0.0025])

Yhat = gdp_gap(1:length(t));
Chat = c_gap(1:length(t));
Rhat = ir_gap(1:length(t));
qhat = q_gap(1:length(t));
pihat = pi_gap(1:length(t));
ihat = i_gap(1:length(t));

y=[Yhat, Chat, Rhat, qhat, pihat, ihat]

save y
%%
%return
dynare projekt.mod
return
close all

%%%

%%ploting parameters
PARAM_NAME_list={'alfa', 'm', 'm2','theta','psi','rpi','rR','rhou','rhoj','rhoA','rhoi'};
kk=48;
for k=1:(8)
    for j=1:11
    paramean(j,k)=[oo_recursive_{1,kk}.posterior_mean.parameters.(PARAM_NAME_list{j})];
    parahpdd(j,k)=[oo_recursive_{1,kk}.posterior_hpdinf.parameters.(PARAM_NAME_list{j})];
    parahpdh(j,k)=[oo_recursive_{1,kk}.posterior_hpdsup.parameters.(PARAM_NAME_list{j})];    
    end
kk=kk+4;    
end

figure
for i=1:11
subplot(4,3,i)
plot(2012.00:1:2019.00,paramean(i,:),'k+','LineWidth',2)
hold on
plot(2012.00:1:2019.00,parahpdd(i,:),'k*','LineWidth',2)
plot(2012.00:1:2019.00,parahpdh(i,:),'k*','LineWidth',2)
 mnx=2011.75; mxx=2019.25; 
 mny=min(parahpdd(i,:))-std(parahpdd(i,:)); mxy=max(parahpdh(i,:))+std(parahpdh(i,:));
                    axis([mnx mxx mny mxy])
title(PARAM_NAME_list{i})
grid on
end
legend('Posterior mean', 'HPDI');



