% S T A T E _ U S . M % ################### %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % SESTAVENI A OVERENI STAVOVEHO MODELU EKONOMIKY USA % % ************************************************** % % % % Restrukturovani kvantifikovaneho ekonometrickeho modlu zadaneho ve tvaru % % x_t = A0*x_t + A1*x_t-1 + B1*u_t + C1*z_t % % do tvaru maticoveho stavoveho modelu % % x_t = As*x_t-1 + B*u_t + C*z_t % % respektive do tvaru prirustkoveho maticoveho stavoveho modelu % % x_t - x_t-1 = A*x_t-1 + B*u_t + C*z_t % % % % Zpracoval: Osvald Vasicek KAMI ESF MU Brno % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% close all clear all load data_us [N,N2]=size(USAMACRO); % Promenne ekonometrickeho modelu % ******************************* % CC, I, Y, G, M [ billons of 1982 dollars] % R [ percent per year ] % t [ quarter ] % % Cas (t) CC =USAMACRO(5:N,2); % real aggregate personal consumption I =USAMACRO(5:N,3); % real gross domestic investment Y =USAMACRO(5:N,5); % real GNP ( net of export and imports ) G =USAMACRO(5:N,6); % real government spending M =USAMACRO(5:N,7); % real money stock ( M1 ) R =USAMACRO(5:N,4); % interest rate on 3-month Treasury bills t =USAMACRO(5:N,1); % time % Cas (t_1) CC_1=USAMACRO(4:N-1,2); I_1 =USAMACRO(4:N-1,3); Y_1 =USAMACRO(4:N-1,5); G_1 =USAMACRO(4:N-1,6); M_1 =USAMACRO(4:N-1,7); R_1 =USAMACRO(4:N-1,4); % Cas (t-2) C_2 =USAMACRO(3:N-2,2); I_2 =USAMACRO(3:N-2,3); Y_2 =USAMACRO(3:N-2,5); G_2 =USAMACRO(3:N-2,6); M_2 =USAMACRO(3:N-2,7); R_2 =USAMACRO(3:N-2,4); % Cas (t-3) R_3 =USAMACRO(2:N-3,4); % Cas (t-4) R_4 =USAMACRO(1:N-4,4); % 1.diference v case (t) d_C =USAMACRO(5:N,2)-USAMACRO(4:N-1,2); d_I =USAMACRO(5:N,3)-USAMACRO(4:N-1,3); d_R =USAMACRO(5:N,4)-USAMACRO(4:N-1,4); d_Y =USAMACRO(5:N,5)-USAMACRO(4:N-1,5); d_G =USAMACRO(5:N,6)-USAMACRO(4:N-1,6); d_M =USAMACRO(5:N,7)-USAMACRO(4:N-1,7); % 1.diference v case (t-1) d_C_1 =USAMACRO(4:N-1,2)-USAMACRO(3:N-2,2); d_I_1 =USAMACRO(4:N-1,3)-USAMACRO(3:N-2,3); d_R_1 =USAMACRO(4:N-1,4)-USAMACRO(3:N-2,4); d_Y_1 =USAMACRO(4:N-1,5)-USAMACRO(3:N-2,5); d_G_1 =USAMACRO(4:N-1,6)-USAMACRO(3:N-2,6); d_M_1 =USAMACRO(4:N-1,7)-USAMACRO(3:N-2,7); % Vektor jednicek pro urovnovou konstantu const=ones(size(G)); % Exogenni, vstupni, stavovy vektor a pocatecni podminka % ------------------------------------------------------ % Koncovy krok modelu Nf = length(G)-1 % tj. 1987 % Pocatecni krok modelu Ns = 133; % % 9; % tj. I.Q / 1950 % Delka modelovaneho intervalu Nr=length((Ns:Nf)'); % Kalendarni cas modelovaneho intervalu t_e=t(Ns:Nf); % Exogenni vektor z_t % 1 z= [const(Ns:Nf)]; % Ridici vektor u_t % 1 2 u= [G(Ns:Nf) d_M(Ns:Nf)]; % Stavovy vektor x_t % 1 2 3 4 % 5 6 7 8 x= [CC(Ns:Nf) I(Ns:Nf) R(Ns:Nf) Y(Ns:Nf)... Y_1(Ns:Nf) R_1(Ns:Nf) R_2(Ns:Nf) R_3(Ns:Nf)]; % Zpozdeny stavovy vektor x_t-1 % 1 2 3 4 % 5 6 7 8 x_1= [CC_1(Ns:Nf) I_1(Ns:Nf) R_1(Ns:Nf) Y_1(Ns:Nf)... Y_2(Ns:Nf) R_2(Ns:Nf) R_3(Ns:Nf) R_4(Ns:Nf)]; % Pocatecni podminka x0 % 1 2 3 4 5 6 7 8 x0=[CC(Ns) I(Ns) R(Ns) Y(Ns) Y_1(Ns) R_1(Ns) R_2(Ns) R_3(Ns)]; % M a t i c o v y s t a v o v y m o d e l % x_t = As*x_t-1 + B*u_t + C*z_t % ****************************************** n=8; % rozmer endogenniho / stavoveho vektoru x_t r=2; % rozmer autonomniho exogenniho / ridiciho vektoru u_t s=1; % rozmer ryze exogeniho / nerizeneho vstupniho vektoru z_t % Matice parametru stavovoho modelu As, B, C - odhad pomoci PEM % ------------------------------------------------------------- % M a t i c e As ( parametry s t a v u u_t-1 ) As = [ 1.2143 0 0 -0.0900 -0.0712 0 0 -1.9842 -0.2675 0 0 0.5740 -0.1176 0 0 -8.1125 0.0006 0 0.7516 0.0006 -0.0005 0.2875 0 -0.1843 0.9249 0 0 0.5049 -0.1939 0 0 -9.5826 0 0 0 1.0000 0 0 0 0 0 0 1.0000 0 0 0 0 0 0 0 0 0 0 1.0000 0 0 0 0 0 0 0 0 1.0000 0]; % M a t i c e B ( parametry r i z e n y c h v s t u p u u_t ) B = [ 0.1856 0 -0.4707 0 -0.0003 -0.0166 0.6950 0 0 0 0 0 0 0 0 0]; % M a t i c e C ( parametry e x o g e n n i c h v s t u p u z_t ) C = [ -5.8391 -8.6264 -0.2067 -12.0276 0 0 0 0]; % M a t i c o v y s t a v o v y m o d e l % ------------------------------------------- % Pocatecni podminka x_s(1,1:n)= x0; for t = 2 : Nr, disp(' t_s ='); disp(t); x_s(t,1:n)=[As*x_s(t-1,1:n)'+B*u(t,1:r)'+C*z(t,1:s)']'; end % 4. D i f e r e n c n i m a t i c o v y s t a v o v y m o d e l % x_t - x_t-1 = As*x_t-1 + B*u_t + C*z_t % ********************************************* % Jednotkova diagonalni matice Io = eye(n); % M a t i c e A ( parametry s t a v u x_t-1 ) A = As -Io; % D i f e r e n c n i m a t i c o v y s t a v o v y m o d e l % ---------------------------------------------------------------- % Pocatecni podminka x_ss(1,1:n)= x0; for t = 2 : Nr, disp(' t_ss ='); disp(t); d_x_ss(t,1:n) = [A*x_ss(t-1,1:n)' + B*u(t,1:r)' + C*z(t,1:s)']'; x_ss(t,1:n) = x_ss(t-1,1:n) + d_x_ss(t,1:n); end disp(' '); disp(' '); format bank disp( t_e(1)) disp( t_e(end)) disp(' Model rizeneho systemu pro " L Q O C " je pripraven !!!'); format %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% t = USAMACRO(5:N,1); UDAT = [G d_M]; ZDAT = [const]; XDAT = [CC I R Y CC_1 I_1 Y_1 R_1 Y_2 R_2 R_3]; PARAM= [A B C]; save state_us CC I R Y CC_1 I_1 R_1 Y_1 Y_2 R_2 R_3... G d_M... const t... UDAT ZDAT XDAT... A B C %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% t_s = t_e; figure(1) clf set(gcf,'Name',' C = real aggregate personal consumption'); hndl2=plot(USAMACRO(:,1),USAMACRO(:,2),'r.-'); set(hndl2,'LineWidth',0.5); hold on plot(t_s,x_s(:,1),'yo-'); hold on plot(t_s,x_ss(:,1),'c*-'); hold off title('Real Aggregate Personal Consumption'); legend('historical natural values','matrix state model',... 'difference matrix state model'); ylabel('State x1(t) = C [ billions of 1982 dollars ]'); xlabel('Time [ quarter ]'); grid figure(2) clf set(gcf,'Name',' I = real gross domestic investment'); hndl3=plot(USAMACRO(:,1),USAMACRO(:,3),'r.-'); set(hndl3,'LineWidth',0.5); hold on plot(t_s,x_s(:,2),'yo-'); hold on plot(t_s,x_ss(:,2),'c*-'); hold off title('Real Gross Domestic Investment'); legend('historical natural values','matrix state model',... 'difference matrix state model'); ylabel('State x2(t) = I [ billions of 1982 dollars ]'); xlabel('Time [ quarter ]'); grid figure(3) clf set(gcf,'Name',' R = interest rate on 3-month Treasury bills'); hndl4=plot(USAMACRO(:,1),USAMACRO(:,4),'r.-'); set(hndl4,'LineWidth',0.5); hold on plot(t_s,x_s(:,3),'yo-'); hold on plot(t_s,x_ss(:,3),'c*-'); hold off title('Interest Rate on 3-Month Treasury Bills'); legend('historical natural values','matrix state model',... 'difference matrix state model'); ylabel('State x3(t) = R [ percent per year ]'); xlabel('Time [ quarter ]'); grid figure(4) clf set(gcf,'Name',' Y = real GNP (net of exports and imports)'); hndl5=plot(USAMACRO(:,1),USAMACRO(:,5),'r.-'); set(hndl5,'LineWidth',0.5); hold on plot(t_s,x_s(:,4),'yo-'); hold on plot(t_s,x_ss(:,4),'c*-'); hold off title('Real GNP (net export and import)'); legend('historical natural values','matrix state model',... 'difference matrix state model'); ylabel('State x4(t) = Y [ billions of 1982 dollars ]'); xlabel('Time [ quarter ]'); grid figure(5) clf set(gcf,'Name',' G = real government expending'); hndl6=plot(USAMACRO(:,1),USAMACRO(:,6),'r-'); set(hndl6,'LineWidth',0.5); hold off title('Real Gavernment Spending'); ylabel('Control u1(t) = G [ billions of 1982 dollars'); xlabel('Time [ quarter ]'); grid figure(6) clf set(gcf,'Name',' d_M = differences of real money stock M1'); hndl7=plot(USAMACRO(2:N,1),(USAMACRO(2:N,7)-USAMACRO(1:N-1,7)),'r'); set(hndl7,'LineWidth',0.5); hold off title('First Diferences of Real Money Stock M1'); ylabel('Control u2(t) = d_M [ billions of 1982 dollars ]'); xlabel('Time [ quarter ]'); grid set(0,'DefaultAxesFontSize',7) figure(7) clf set(gcf,'Name','Observed Historical Data') subplot(321) hndl2=plot(USAMACRO(:,1),USAMACRO(:,2),'c'); set(hndl2,'LineWidth',0.5); hold off title('Real Aggregate Personal Consumption'); ylabel('C [ billions of 1982 dollars ]'); %...xlabel('Time [ quarter ]'); grid subplot(322) hndl3=plot(USAMACRO(:,1),USAMACRO(:,3),'c'); set(hndl3,'LineWidth',0.5); hold off title('Real Gross Domestic Investment'); ylabel('I [ billions of 1982 dollars ]'); %...xlabel('Time [ quarter ]'); grid subplot(323) hndl4=plot(USAMACRO(:,1),USAMACRO(:,4),'c'); set(hndl4,'LineWidth',0.5); hold off title('Interest Rate on 3-Month Treasury Bills'); ylabel('R [ percent per year ]'); %...xlabel('Time [ quarter ]'); grid subplot(324) hndl5=plot(USAMACRO(:,1),USAMACRO(:,5),'c'); set(hndl5,'LineWidth',0.5); hold off title('Real GNP (net export and import)'); ylabel('Y [ billions of 1982 dollars ]'); %...xlabel('Time [ quarter ]'); grid subplot(325) hndl6=plot(USAMACRO(:,1),USAMACRO(:,6),'r'); set(hndl6,'LineWidth',0.5); hold off title('Real Gavernment Spending'); ylabel('G [ billions of 1982 dollars'); xlabel('Time [ quarter ]'); grid subplot(326) hndl7=plot(USAMACRO(2:N,1),(USAMACRO(2:N,7)-USAMACRO(1:N-1,7)),'r'); set(hndl7,'LineWidth',0.5); hold off title('First Diferences of Real Money Stock M1'); ylabel('d_M [ billions of 1982 dollars ]'); xlabel('Time [ quarter ]'); grid