Home > matlab > simultxdet.m

simultxdet

PURPOSE ^

function [y_,int_width]=simultxdet(y0,ex,ex_det, iorder,var_list,M_,oo_,options_)

SYNOPSIS ^

function [y_,int_width]=simultxdet(y0,ex,ex_det, iorder,var_list,M_,oo_,options_)

DESCRIPTION ^

function [y_,int_width]=simultxdet(y0,ex,ex_det, iorder,var_list,M_,oo_,options_)

 Simulates a stochastic model in the presence of deterministic exogenous shocks

 INPUTS:
    y0:        initial values, of length M_.maximum_lag
    ex:        matrix of stochastic exogenous shocks, starting at period 1
    ex_det:    matrix of deterministic exogenous shocks, starting at period 1-M_.maximum_lag
    iorder:    order of approximation
    var_list:  list of endogenous variables to simulate

 The forecast horizon is equal to size(ex, 1).
 The condition size(ex,1)+M_.maximum_lag=size(ex_det,1) must be verified
  for consistency.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [y_,int_width]=simultxdet(y0,ex,ex_det, iorder,var_list,M_,oo_,options_)
0002 %function [y_,int_width]=simultxdet(y0,ex,ex_det, iorder,var_list,M_,oo_,options_)
0003 %
0004 % Simulates a stochastic model in the presence of deterministic exogenous shocks
0005 %
0006 % INPUTS:
0007 %    y0:        initial values, of length M_.maximum_lag
0008 %    ex:        matrix of stochastic exogenous shocks, starting at period 1
0009 %    ex_det:    matrix of deterministic exogenous shocks, starting at period 1-M_.maximum_lag
0010 %    iorder:    order of approximation
0011 %    var_list:  list of endogenous variables to simulate
0012 %
0013 % The forecast horizon is equal to size(ex, 1).
0014 % The condition size(ex,1)+M_.maximum_lag=size(ex_det,1) must be verified
0015 %  for consistency.
0016 
0017 % Copyright (C) 2008-2011 Dynare Team
0018 %
0019 % This file is part of Dynare.
0020 %
0021 % Dynare is free software: you can redistribute it and/or modify
0022 % it under the terms of the GNU General Public License as published by
0023 % the Free Software Foundation, either version 3 of the License, or
0024 % (at your option) any later version.
0025 %
0026 % Dynare is distributed in the hope that it will be useful,
0027 % but WITHOUT ANY WARRANTY; without even the implied warranty of
0028 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0029 % GNU General Public License for more details.
0030 %
0031 % You should have received a copy of the GNU General Public License
0032 % along with Dynare.  If not, see <http://www.gnu.org/licenses/>.
0033 
0034 dr = oo_.dr;
0035 ykmin = M_.maximum_lag;
0036 endo_nbr = M_.endo_nbr;
0037 exo_det_steady_state = oo_.exo_det_steady_state;
0038 nstatic = dr.nstatic;
0039 npred =dr.npred;
0040 nc = size(dr.ghx,2);
0041 iter = size(ex,1);
0042 if size(ex_det, 1) ~= iter+ykmin
0043     error('Size mismatch: number of forecasting periods for stochastic exogenous and deterministic exogenous don''t match')
0044 end
0045 nx = size(dr.ghu,2);
0046 y_ = zeros(size(y0,1),iter+ykmin);
0047 y_(:,1:ykmin) = y0;
0048 k1 = [ykmin:-1:1];
0049 k2 = dr.kstate(find(dr.kstate(:,2) <= ykmin+1),[1 2]);
0050 k2 = k2(:,1)+(ykmin+1-k2(:,2))*endo_nbr;
0051 k3 = M_.lead_lag_incidence(1:ykmin,:)';
0052 k3 = find(k3(:));
0053 k4 = dr.kstate(find(dr.kstate(:,2) < ykmin+1),[1 2]);
0054 k4 = k4(:,1)+(ykmin+1-k4(:,2))*endo_nbr;
0055 
0056 nvar = size(var_list,1);
0057 if nvar == 0
0058     nvar = endo_nbr;
0059     ivar = [1:nvar];
0060 else
0061     ivar=zeros(nvar,1);
0062     for i=1:nvar
0063         i_tmp = strmatch(var_list(i,:),M_.endo_names,'exact');
0064         if isempty(i_tmp)
0065             disp(var_list(i,:));
0066             error (['One of the variable specified does not exist']) ;
0067         else
0068             ivar(i) = i_tmp;
0069         end
0070     end
0071 end
0072 
0073 if iorder == 1
0074     for i = ykmin+1: iter+ykmin
0075         tempx1 = y_(dr.order_var,k1);
0076         tempx2 = tempx1-repmat(dr.ys(dr.order_var),1,ykmin);
0077         tempx = tempx2(k2);
0078         y_(dr.order_var,i) = dr.ys(dr.order_var)+dr.ghx*tempx+dr.ghu* ...
0079             ex(i-ykmin,:)';
0080         for j=1:min(ykmin+M_.exo_det_length+1-i,M_.exo_det_length)
0081             y_(dr.order_var,i) = y_(dr.order_var,i) + dr.ghud{j}*(ex_det(i+j-1,:)'-exo_det_steady_state);
0082         end
0083         
0084         k1 = k1+1;
0085     end
0086 elseif iorder == 2
0087     for i = ykmin+1: iter+ykmin
0088         tempx1 = y_(dr.order_var,k1);
0089         tempx2 = tempx1-repmat(dr.ys(dr.order_var),1,ykmin);
0090         tempx = tempx2(k2);
0091         tempu = ex(i-ykmin,:)';
0092         tempuu = kron(tempu,tempu);
0093         tempxx = kron(tempx,tempx);
0094         tempxu = kron(tempx,tempu);
0095         y_(dr.order_var,i) = dr.ys(dr.order_var)+dr.ghs2/2+dr.ghx*tempx+ ...
0096             dr.ghu*tempu+0.5*(dr.ghxx*tempxx+dr.ghuu*tempuu)+dr.ghxu* ...
0097             tempxu;
0098         for j=1:min(ykmin+M_.exo_det_length+1-i,M_.exo_det_length)
0099             tempud = ex_det(i+j-1,:)'-exo_det_steady_state;
0100             tempudud = kron(tempud,tempud);
0101             tempxud = kron(tempx,tempud);
0102             tempuud = kron(tempu,tempud);
0103             y_(dr.order_var,i) = y_(dr.order_var,i) + dr.ghud{j}*tempud + ...
0104                 dr.ghxud{j}*tempxud + dr.ghuud{j}*tempuud + ...
0105                 0.5*dr.ghudud{j,j}*tempudud;
0106             for k=1:j-1
0107                 tempudk = ex_det(i+k-1,:)'-exo_det_steady_state;
0108                 tempududk = kron(tempudk,tempud);
0109                 y_(dr.order_var,i) = y_(dr.order_var,i) + ...
0110                     dr.ghudud{k,j}*tempududk;
0111             end
0112         end
0113         k1 = k1+1;
0114     end
0115 end
0116 
0117 [A,B] = kalman_transition_matrix(dr,nstatic+(1:npred),1:nc,M_.exo_nbr);
0118 
0119 inv_order_var = dr.inv_order_var;
0120 ghx1 = dr.ghx(inv_order_var(ivar),:);
0121 ghu1 = dr.ghu(inv_order_var(ivar),:);
0122 
0123 sigma_u = B*M_.Sigma_e*B';
0124 sigma_u1 = ghu1*M_.Sigma_e*ghu1';
0125 sigma_y = 0;
0126 
0127 for i=1:iter
0128     sigma_y1 = ghx1*sigma_y*ghx1'+sigma_u1;
0129     var_yf(i,:) = diag(sigma_y1)';
0130     if i == iter
0131         break
0132     end
0133     sigma_u = A*sigma_u*A';
0134     sigma_y = sigma_y+sigma_u;
0135 end
0136 
0137 fact = norminv((1-options_.conf_sig)/2,0,1);
0138 
0139 int_width = zeros(iter,endo_nbr);
0140 for i=1:nvar
0141     int_width(:,i) = fact*sqrt(var_yf(:,i));
0142 end

Generated on Tue 22-May-2012 02:40:23 by m2html © 2005