Home > matlab > stoch_simul_sparse.m

stoch_simul_sparse

PURPOSE ^

This file is a modified version of stoch_simul.m: common parts should be factorized!

SYNOPSIS ^

function info=stoch_simul_sparse(var_list)

DESCRIPTION ^

 This file is a modified version of stoch_simul.m: common parts should be factorized!

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function info=stoch_simul_sparse(var_list)
0002 % This file is a modified version of stoch_simul.m: common parts should be factorized!
0003 
0004 % Copyright (C) 2001-2010 Dynare Team
0005 %
0006 % This file is part of Dynare.
0007 %
0008 % Dynare is free software: you can redistribute it and/or modify
0009 % it under the terms of the GNU General Public License as published by
0010 % the Free Software Foundation, either version 3 of the License, or
0011 % (at your option) any later version.
0012 %
0013 % Dynare is distributed in the hope that it will be useful,
0014 % but WITHOUT ANY WARRANTY; without even the implied warranty of
0015 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0016 % GNU General Public License for more details.
0017 %
0018 % You should have received a copy of the GNU General Public License
0019 % along with Dynare.  If not, see <http://www.gnu.org/licenses/>.
0020 
0021 global M_ options_ oo_ it_
0022 
0023 options_old = options_;
0024 if options_.linear
0025     options_.order = 1;
0026 end
0027 if (options_.order == 1)
0028     options_.replic = 1;
0029 end
0030 
0031 
0032 TeX = options_.TeX;
0033 
0034 iter_ = max(options_.periods,1);
0035 if M_.exo_nbr > 0
0036     oo_.exo_simul= ones(iter_ + M_.maximum_lag + M_.maximum_lead,1) * oo_.exo_steady_state';
0037 end
0038 
0039 check_model;
0040 
0041 [oo_.dr,info,M_,options_,oo_] = resol(0,M_,options_,oo_);
0042 
0043 if info(1)
0044     options_ = options_old;
0045     print_info(info, options_.noprint);
0046     return
0047 end
0048 
0049 oo_dr_kstate = [];
0050 oo_dr_nstatic = 0;
0051 for i=1:length(M_.block_structure.block)
0052     oo_dr_kstate = [ oo_dr_kstate ; M_.block_structure.block(i).dr.kstate];
0053     oo_dr_nstatic = oo_dr_nstatic + M_.block_structure.block(i).dr.nstatic;
0054 end
0055 
0056 if ~options_.noprint
0057     disp(' ')
0058     disp('MODEL SUMMARY')
0059     disp(' ')
0060     disp(['  Number of variables:         ' int2str(M_.endo_nbr)])
0061     disp(['  Number of stochastic shocks: ' int2str(M_.exo_nbr)])
0062     disp(['  Number of state variables:   ' ...
0063           int2str(length(find(oo_dr_kstate(:,2) <= M_.maximum_lag+1)))])
0064     disp(['  Number of jumpers:           ' ...
0065           int2str(length(find(oo_dr_kstate(:,2) == M_.maximum_lag+2)))])
0066     disp(['  Number of static variables:  ' int2str(oo_dr_nstatic)])
0067     my_title='MATRIX OF COVARIANCE OF EXOGENOUS SHOCKS';
0068     labels = deblank(M_.exo_names);
0069     headers = char('Variables',labels);
0070     lh = size(labels,2)+2;
0071     dyntable(my_title,headers,labels,M_.Sigma_e,lh,10,6);
0072     disp(' ')
0073     disp_dr_sparse(oo_.dr,options_.order,var_list);
0074 end
0075 
0076 if options_.periods == 0 && options_.nomoments == 0
0077     disp_th_moments(oo_.dr,var_list);
0078 elseif options_.periods ~= 0
0079     if options_.periods < options_.drop
0080         disp(['STOCH_SIMUL error: The horizon of simulation is shorter' ...
0081               ' than the number of observations to be DROPed'])
0082         options_ =options_old;
0083         return
0084     end
0085     if isempty(M_.endo_histval)
0086         y0 = oo_.dr.ys;
0087     else
0088         y0 = M_.endo_histval;
0089     end
0090     oo_.endo_simul = simult(y0,oo_.dr);
0091     dyn2vec;
0092     if options_.nomoments == 0
0093         disp_moments(oo_.endo_simul,var_list);
0094     end
0095 end
0096 
0097 
0098 
0099 if options_.irf
0100     if size(var_list,1) == 0
0101         var_list = M_.endo_names(1:M_.orig_endo_nbr, :);
0102         if TeX
0103             var_listTeX = M_.endo_names_tex(1:M_.orig_endo_nbr, :);
0104         end
0105     end
0106 
0107     n = size(var_list,1);
0108     ivar=zeros(n,1);
0109     if TeX
0110         var_listTeX = [];
0111     end
0112     for i=1:n
0113         i_tmp = strmatch(var_list(i,:),M_.endo_names,'exact');
0114         if isempty(i_tmp)
0115             error (['One of the specified variables does not exist']) ;
0116         else
0117             ivar(i) = i_tmp;
0118             if TeX
0119                 if isempty(var_listTeX)
0120                     var_listTeX = deblank(M_.endo_names_tex(i_tmp,:));
0121                 else
0122                     var_listTeX = char(var_listTeX,deblank(M_.endo_names_tex(i_tmp,:)));
0123                 end
0124             end
0125         end
0126     end
0127 
0128     if TeX
0129         fidTeX = fopen([M_.fname '_IRF.TeX'],'w');
0130         fprintf(fidTeX,'%% TeX eps-loader file generated by stoch_simul.m (Dynare).\n');
0131         fprintf(fidTeX,['%% ' datestr(now,0) '\n']);
0132         fprintf(fidTeX,' \n');
0133     end
0134     SS(M_.exo_names_orig_ord,M_.exo_names_orig_ord)=M_.Sigma_e+1e-14*eye(M_.exo_nbr);
0135     cs = transpose(chol(SS));
0136     tit(M_.exo_names_orig_ord,:) = M_.exo_names;
0137     if TeX
0138         titTeX(M_.exo_names_orig_ord,:) = M_.exo_names_tex;
0139     end
0140     irf_shocks_indx = getIrfShocksIndx();
0141     for i=irf_shocks_indx
0142         if SS(i,i) > 1e-13
0143             y=irf(oo_.dr,cs(M_.exo_names_orig_ord,i), options_.irf, options_.drop, ...
0144                   options_.replic, options_.order);
0145             if options_.relative_irf
0146                 y = 100*y/cs(i,i);
0147             end
0148             irfs   = [];
0149             mylist = [];
0150             if TeX
0151                 mylistTeX = [];
0152             end
0153             for j = 1:n
0154                 assignin('base',[deblank(M_.endo_names(ivar(j),:)) '_' deblank(M_.exo_names(i,:))],...
0155                          y(ivar(j),:)');
0156                 eval(['oo_.irfs.' deblank(M_.endo_names(ivar(j),:)) '_' ...
0157                       deblank(M_.exo_names(i,:)) ' = y(ivar(j),:);']);
0158                 if max(y(ivar(j),:)) - min(y(ivar(j),:)) > 1e-10
0159                     irfs  = cat(1,irfs,y(ivar(j),:));
0160                     if isempty(mylist)
0161                         mylist = deblank(var_list(j,:));
0162                     else
0163                         mylist = char(mylist,deblank(var_list(j,:)));
0164                     end
0165                     if TeX
0166                         if isempty(mylistTeX)
0167                             mylistTeX = deblank(var_listTeX(j,:));
0168                         else
0169                             mylistTeX = char(mylistTeX,deblank(var_listTeX(j,:)));
0170                         end
0171                     end
0172                 end
0173             end
0174             if options_.nograph == 0
0175                 number_of_plots_to_draw = size(irfs,1);
0176                 [nbplt,nr,nc,lr,lc,nstar] = pltorg(number_of_plots_to_draw);
0177                 if nbplt == 0
0178                 elseif nbplt == 1
0179                     if options_.relative_irf
0180                         hh = dyn_figure(options_,'Name',['Relative response to' ...
0181                                             ' orthogonalized shock to ' tit(i,:)]);
0182                     else
0183                         hh = dyn_figure(options_,'Name',['Orthogonalized shock to' ...
0184                                             ' ' tit(i,:)]);
0185                     end
0186                     for j = 1:number_of_plots_to_draw
0187                         subplot(nr,nc,j);
0188                         plot(1:options_.irf,transpose(irfs(j,:)),'-k','linewidth',1);
0189                         hold on
0190                         plot([1 options_.irf],[0 0],'-r','linewidth',0.5);
0191                         hold off
0192                         xlim([1 options_.irf]);
0193                         title(deblank(mylist(j,:)),'Interpreter','none');
0194                     end
0195                     dyn_saveas(hh,[ M_.fname '_IRF_' deblank(tit(i,:)) ],options_);
0196                     if TeX
0197                         fprintf(fidTeX,'\\begin{figure}[H]\n');
0198                         for j = 1:number_of_plots_to_draw
0199                             fprintf(fidTeX,['\\psfrag{%s}[1][][0.5][0]{$%s$}\n'],deblank(mylist(j,:)),deblank(mylistTeX(j,:)));
0200                         end
0201                         fprintf(fidTeX,'\\centering \n');
0202                         fprintf(fidTeX,'\\includegraphics[scale=0.5]{%s_IRF_%s}\n',M_.fname,deblank(tit(i,:)));
0203                         fprintf(fidTeX,'\\caption{Impulse response functions (orthogonalized shock to $%s$).}',titTeX(i,:));
0204                         fprintf(fidTeX,'\\label{Fig:IRF:%s}\n',deblank(tit(i,:)));
0205                         fprintf(fidTeX,'\\end{figure}\n');
0206                         fprintf(fidTeX,' \n');
0207                     end
0208                 else
0209                     for fig = 1:nbplt-1
0210                         if options_.relative_irf == 1
0211                             hh = dyn_figure(options_,'Name',['Relative response to orthogonalized shock' ...
0212                                                 ' to ' tit(i,:) ' figure ' int2str(fig)]);
0213                         else
0214                             hh =dyn_figure(options_,'Name',['Orthogonalized shock to ' tit(i,:) ...
0215                                                 ' figure ' int2str(fig)]);
0216                         end
0217                         for plt = 1:nstar
0218                             subplot(nr,nc,plt);
0219                             plot(1:options_.irf,transpose(irfs((fig-1)*nstar+plt,:)),'-k','linewidth',1);
0220                             hold on
0221                             plot([1 options_.irf],[0 0],'-r','linewidth',0.5);
0222                             hold off
0223                             xlim([1 options_.irf]);
0224                             title(deblank(mylist((fig-1)*nstar+plt,:)),'Interpreter','none');
0225                         end
0226                         dyn_saveas(hh,[ M_.fname '_IRF_' deblank(tit(i,:)) int2str(fig)],options_);
0227                         if TeX
0228                             fprintf(fidTeX,'\\begin{figure}[H]\n');
0229                             for j = 1:nstar
0230                                 fprintf(fidTeX,['\\psfrag{%s}[1][][0.5][0]{$%s$}\n'],deblank(mylist((fig-1)*nstar+j,:)),deblank(mylistTeX((fig-1)*nstar+j,:)));
0231                             end
0232                             fprintf(fidTeX,'\\centering \n');
0233                             fprintf(fidTeX,'\\includegraphics[scale=0.5]{%s_IRF_%s%s}\n',M_.fname,deblank(tit(i,:)),int2str(fig));
0234                             if options_.relative_irf
0235                                 fprintf(fidTeX,['\\caption{Relative impulse response' ...
0236                                                 ' functions (orthogonalized shock to $%s$).}'],deblank(titTeX(i,:)));
0237                             else
0238                                 fprintf(fidTeX,['\\caption{Impulse response functions' ...
0239                                                 ' (orthogonalized shock to $%s$).}'],deblank(titTeX(i,:)));
0240                             end
0241                             fprintf(fidTeX,'\\label{Fig:BayesianIRF:%s:%s}\n',deblank(tit(i,:)),int2str(fig));
0242                             fprintf(fidTeX,'\\end{figure}\n');
0243                             fprintf(fidTeX,' \n');
0244                         end
0245                         %                                       close(hh);
0246                     end
0247                     hh = dyn_figure(options_,'Name',['Orthogonalized shock to ' tit(i,:) ' figure ' int2str(nbplt) '.']);
0248                     m = 0;
0249                     for plt = 1:number_of_plots_to_draw-(nbplt-1)*nstar;
0250                         m = m+1;
0251                         subplot(lr,lc,m);
0252                         plot(1:options_.irf,transpose(irfs((nbplt-1)*nstar+plt,:)),'-k','linewidth',1);
0253                         hold on
0254                         plot([1 options_.irf],[0 0],'-r','linewidth',0.5);
0255                         hold off
0256                         xlim([1 options_.irf]);
0257                         title(deblank(mylist((nbplt-1)*nstar+plt,:)),'Interpreter','none');
0258                     end
0259                     dyn_saveas(hh,[ M_.fname '_IRF_' deblank(tit(i,:)) int2str(nbplt) ],options_);
0260                     if TeX
0261                         fprintf(fidTeX,'\\begin{figure}[H]\n');
0262                         for j = 1:m
0263                             fprintf(fidTeX,['\\psfrag{%s}[1][][0.5][0]{$%s$}\n'],deblank(mylist((nbplt-1)*nstar+j,:)),deblank(mylistTeX((nbplt-1)*nstar+j,:)));
0264                         end
0265                         fprintf(fidTeX,'\\centering \n');
0266                         fprintf(fidTeX,'\\includegraphics[scale=0.5]{%s_IRF_%s%s}\n',M_.fname,deblank(tit(i,:)),int2str(nbplt));
0267                         if options_.relative_irf
0268                             fprintf(fidTeX,['\\caption{Relative impulse response functions' ...
0269                                             ' (orthogonalized shock to $%s$).}'],deblank(titTeX(i,:)));
0270                         else
0271                             fprintf(fidTeX,['\\caption{Impulse response functions' ...
0272                                             ' (orthogonalized shock to $%s$).}'],deblank(titTeX(i,:)));
0273                         end
0274                         fprintf(fidTeX,'\\label{Fig:IRF:%s:%s}\n',deblank(tit(i,:)),int2str(nbplt));
0275                         fprintf(fidTeX,'\\end{figure}\n');
0276                         fprintf(fidTeX,' \n');
0277                     end
0278                 end
0279             end
0280         end
0281         if TeX
0282             fprintf(fidTeX,' \n');
0283             fprintf(fidTeX,'%% End Of TeX file. \n');
0284             fclose(fidTeX);
0285         end
0286     end
0287 end
0288 
0289 if options_.SpectralDensity.trigger == 1
0290     [omega,f] = UnivariateSpectralDensity(oo_.dr,var_list);
0291 end
0292 
0293 
0294 options_ = options_old;

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