clear all close all set(0,'defaultlinelinewidth',1.5); % load data d = dbload('us_quarterly.csv'); %% get ranges first_date = get(d.gdp,'first'); last_date = get(d.gdp,'last'); rng_all = get(d.gdp,'range'); rng = qq(1970,1):enddate(d.gdp); % selected range %%hezci zobrazeni range % dat2str(rng)' %%vyber casove rady % d.gdp(rng) % cisla % d.gdp{rng} % casova rada %% logaritmus % Why? difference is percentage change d.l_gdp = 100*log(d.gdp); % plot graphs figure plot(d.gdp) title('GDP, level, billions of dollars') grid figure plot(d.l_gdp) title('GDP, 100*log') grid % Task: plot selected range return %% Linerani trend d.l_gdp_ltrend = trend(d.l_gdp,'connect=',false); % iris function d.l_gdp_lgap = d.l_gdp - d.l_gdp_ltrend; figure plot([d.l_gdp d.l_gdp_ltrend]) legend('log HDP','linearni trend','Location','NorthWest') title('Linearni trend') grid figure plot(d.l_gdp_lgap) title('Odchylka od linearniho trendu') ylabel('%') grid %% tempa rustu % mezictvrtletni, annualizovane d.dla_gdp = diff(d.l_gdp)*4; % alternativni zpusob zapisu d.dla_gdp2 = (d.l_gdp - d.l_gdp{-1})*4; % alternative way figure plot(d.dla_gdp) title('Mezictvrtlentí tempo rustu, (q-on-q), % annualizovane') grid % mezirocni % Task: porovnejte s vypoctem z nelogaritmovane rady, fce: pct %% Hodrick-Prescott filtr [d.l_gdp_trend, d.l_gdp_gap] = hpf(d.l_gdp,'lambda=',1600); figure plot([d.l_gdp d.l_gdp_trend]) title('Real GDP, 100*log') legend('level','trend','Location','NorthWest') grid figure plot([d.l_gdp_gap]) title('Real GDP gap, %') ylabel('% deviation from trend') grid % Task: Try different lambda %% Band-pass filter % frequencies of business cycle (lower is trend, higher are statistical % discrepancies) low = 8; high = 32; [d.l_gdp_bpgap] = bpass(d.l_gdp,[low high]); figure plot([d.l_gdp_bpgap d.l_gdp_gap]) title('Real GDP gap, %') ylabel('% deviation from trend') legend('Band pass filter','HP filter') grid % set(gcf,'Papersize',[32 26]); % set(gcf,'PaperPosition',[0 0 32 26]); % saveas(gcf,'filters_comparison','pdf'); %% statisticke charakteristiky % tempo rustu gr.mean = mean(d.d4l_gdp); gr.std = std(d.d4l_gdp); gr.min = min(d.d4l_gdp); gr.max = max(d.d4l_gdp); gr.ac = acfn(d.d4l_gdp,5); gr.pct_pos = length(find(d.d4l_gdp >0))/length(d.d4l_gdp); gr.pct_high = length(find(d.d4l_gdp > gr.mean))/length(d.d4l_gdp); % HP filtr disp('Tempo rustu') gr