2005-02-18 20:54:39 +01:00
|
|
|
|
% Copyright (C) 2001 Michel Juillard
|
|
|
|
|
%
|
2005-09-11 11:43:58 +02:00
|
|
|
|
function info=stoch_simul(var_list)
|
2006-11-18 08:37:22 +01:00
|
|
|
|
global M_ options_ oo_ it_
|
|
|
|
|
|
2007-01-22 17:34:54 +01:00
|
|
|
|
options_old = options_;
|
2005-02-18 20:54:39 +01:00
|
|
|
|
if options_.linear
|
2007-10-04 17:36:00 +02:00
|
|
|
|
options_.order = 1;
|
2005-02-18 20:54:39 +01:00
|
|
|
|
end
|
2007-10-04 17:36:00 +02:00
|
|
|
|
if (options_.order == 1)
|
|
|
|
|
options_.replic = 1;
|
|
|
|
|
end
|
|
|
|
|
|
2005-02-18 20:54:39 +01:00
|
|
|
|
|
2005-09-11 11:43:58 +02:00
|
|
|
|
TeX = options_.TeX;
|
|
|
|
|
|
|
|
|
|
iter_ = max(options_.periods,1);
|
2005-02-18 20:54:39 +01:00
|
|
|
|
if M_.exo_nbr > 0
|
2005-09-11 11:43:58 +02:00
|
|
|
|
oo_.exo_simul= ones(iter_ + M_.maximum_lag + M_.maximum_lead,1) * oo_.exo_steady_state';
|
2005-02-18 20:54:39 +01:00
|
|
|
|
end
|
|
|
|
|
|
2005-09-11 11:43:58 +02:00
|
|
|
|
check_model;
|
|
|
|
|
|
2006-01-18 17:50:33 +01:00
|
|
|
|
[oo_.dr, info] = resol(oo_.steady_state,0);
|
2005-09-11 11:43:58 +02:00
|
|
|
|
|
|
|
|
|
if info(1)
|
2006-11-18 08:37:22 +01:00
|
|
|
|
options_ = options_old;
|
2005-09-11 11:43:58 +02:00
|
|
|
|
print_info(info);
|
|
|
|
|
return
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
if ~options_.noprint
|
|
|
|
|
disp(' ')
|
|
|
|
|
disp('MODEL SUMMARY')
|
|
|
|
|
disp(' ')
|
|
|
|
|
disp([' Number of variables: ' int2str(M_.endo_nbr)])
|
|
|
|
|
disp([' Number of stochastic shocks: ' int2str(M_.exo_nbr)])
|
|
|
|
|
disp([' Number of state variables: ' ...
|
2006-01-18 17:50:33 +01:00
|
|
|
|
int2str(length(find(oo_.dr.kstate(:,2) <= M_.maximum_lag+1)))])
|
2005-09-11 11:43:58 +02:00
|
|
|
|
disp([' Number of jumpers: ' ...
|
2006-01-18 17:50:33 +01:00
|
|
|
|
int2str(length(find(oo_.dr.kstate(:,2) == M_.maximum_lag+2)))])
|
|
|
|
|
disp([' Number of static variables: ' int2str(oo_.dr.nstatic)])
|
2005-09-11 11:43:58 +02:00
|
|
|
|
my_title='MATRIX OF COVARIANCE OF EXOGENOUS SHOCKS';
|
2005-09-22 16:28:25 +02:00
|
|
|
|
labels = deblank(M_.exo_names);
|
2005-09-11 11:43:58 +02:00
|
|
|
|
headers = strvcat('Variables',labels);
|
|
|
|
|
lh = size(labels,2)+2;
|
2005-09-22 16:28:25 +02:00
|
|
|
|
table(my_title,headers,labels,M_.Sigma_e,lh,10,6);
|
2005-09-11 11:43:58 +02:00
|
|
|
|
disp(' ')
|
2006-01-18 17:50:33 +01:00
|
|
|
|
disp_dr(oo_.dr,options_.order,var_list);
|
2005-09-11 11:43:58 +02:00
|
|
|
|
end
|
2005-02-18 20:54:39 +01:00
|
|
|
|
|
|
|
|
|
if options_.simul == 0 & options_.nomoments == 0
|
2006-01-18 17:50:33 +01:00
|
|
|
|
disp_th_moments(oo_.dr,var_list);
|
2005-02-18 20:54:39 +01:00
|
|
|
|
elseif options_.simul == 1
|
|
|
|
|
if options_.periods == 0
|
|
|
|
|
error('STOCH_SIMUL error: number of periods for the simulation isn''t specified')
|
|
|
|
|
end
|
|
|
|
|
if options_.periods < options_.drop
|
|
|
|
|
disp(['STOCH_SIMUL error: The horizon of simulation is shorter' ...
|
|
|
|
|
' than the number of observations to be DROPed'])
|
2006-11-18 08:37:22 +01:00
|
|
|
|
options_ =options_old;
|
2005-02-18 20:54:39 +01:00
|
|
|
|
return
|
|
|
|
|
end
|
2006-01-18 17:50:33 +01:00
|
|
|
|
oo_.endo_simul = simult(repmat(oo_.dr.ys,1,M_.maximum_lag),oo_.dr);
|
2005-02-18 20:54:39 +01:00
|
|
|
|
dyn2vec;
|
|
|
|
|
if options_.nomoments == 0
|
2005-09-11 11:43:58 +02:00
|
|
|
|
disp_moments(oo_.endo_simul,var_list);
|
2005-02-18 20:54:39 +01:00
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
2005-09-11 11:43:58 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if options_.irf
|
|
|
|
|
n = size(var_list,1);
|
|
|
|
|
if n == 0
|
|
|
|
|
n = M_.endo_nbr;
|
|
|
|
|
ivar = [1:n]';
|
2005-09-22 16:28:25 +02:00
|
|
|
|
var_list = M_.endo_names;
|
2005-09-11 11:43:58 +02:00
|
|
|
|
if TeX
|
2005-09-22 16:28:25 +02:00
|
|
|
|
var_listTeX = M_.endo_names_tex;
|
2005-09-11 11:43:58 +02:00
|
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
ivar=zeros(n,1);
|
|
|
|
|
if TeX
|
|
|
|
|
var_listTeX = [];
|
|
|
|
|
end
|
|
|
|
|
for i=1:n
|
2005-09-22 16:28:25 +02:00
|
|
|
|
i_tmp = strmatch(var_list(i,:),M_.endo_names,'exact');
|
2005-09-11 11:43:58 +02:00
|
|
|
|
if isempty(i_tmp)
|
|
|
|
|
error (['One of the specified variables does not exist']) ;
|
|
|
|
|
else
|
|
|
|
|
ivar(i) = i_tmp;
|
|
|
|
|
if TeX
|
2005-09-22 16:28:25 +02:00
|
|
|
|
var_listTeX = strvcat(var_listTeX,deblank(M_.endo_names_tex(i_tmp,:)));
|
2005-09-11 11:43:58 +02:00
|
|
|
|
end
|
|
|
|
|
end
|
2005-02-18 20:54:39 +01:00
|
|
|
|
end
|
|
|
|
|
end
|
2005-09-11 11:43:58 +02:00
|
|
|
|
if TeX
|
|
|
|
|
fidTeX = fopen([M_.fname '_IRF.TeX'],'w');
|
|
|
|
|
fprintf(fidTeX,'%% TeX eps-loader file generated by stoch_simul.m (Dynare).\n');
|
|
|
|
|
fprintf(fidTeX,['%% ' datestr(now,0) '\n']);
|
|
|
|
|
fprintf(fidTeX,' \n');
|
|
|
|
|
end
|
|
|
|
|
olditer = iter_;% Est-ce vraiment utile ? Il y a la m<>me ligne dans irf...
|
2005-09-26 14:40:14 +02:00
|
|
|
|
SS(M_.exo_names_orig_ord,M_.exo_names_orig_ord)=M_.Sigma_e+1e-14*eye(M_.exo_nbr);
|
2005-09-11 11:43:58 +02:00
|
|
|
|
cs = transpose(chol(SS));
|
2005-09-26 14:40:14 +02:00
|
|
|
|
tit(M_.exo_names_orig_ord,:) = M_.exo_names;
|
2005-09-11 11:43:58 +02:00
|
|
|
|
if TeX
|
2005-09-26 14:40:14 +02:00
|
|
|
|
titTeX(M_.exo_names_orig_ord,:) = M_.exo_names_tex;
|
2005-02-18 20:54:39 +01:00
|
|
|
|
end
|
2005-09-11 11:43:58 +02:00
|
|
|
|
for i=1:M_.exo_nbr
|
2005-02-18 20:54:39 +01:00
|
|
|
|
if SS(i,i) > 1e-13
|
2006-01-18 17:50:33 +01:00
|
|
|
|
y=irf(oo_.dr,cs(M_.exo_names_orig_ord,i), options_.irf, options_.drop, ...
|
2005-02-18 20:54:39 +01:00
|
|
|
|
options_.replic, options_.order);
|
2005-09-11 11:43:58 +02:00
|
|
|
|
if options_.relative_irf
|
|
|
|
|
y = 100*y/cs(i,i);
|
|
|
|
|
end
|
|
|
|
|
irfs = [];
|
|
|
|
|
mylist = [];
|
|
|
|
|
if TeX
|
|
|
|
|
mylistTeX = [];
|
|
|
|
|
end
|
2005-02-18 20:54:39 +01:00
|
|
|
|
for j = 1:n
|
2006-10-02 11:15:55 +02:00
|
|
|
|
assignin('base',[deblank(M_.endo_names(ivar(j),:)) '_' deblank(M_.exo_names(i,:))],...
|
|
|
|
|
y(ivar(j),:)');
|
2007-07-05 06:34:24 +02:00
|
|
|
|
eval(['oo_.irfs.' deblank(M_.endo_names(ivar(j),:)) '_' ...
|
|
|
|
|
deblank(M_.exo_names(i,:)) ' = y(ivar(j),:);']);
|
2005-09-11 11:43:58 +02:00
|
|
|
|
if max(y(ivar(j),:)) - min(y(ivar(j),:)) > 1e-10
|
|
|
|
|
irfs = cat(1,irfs,y(ivar(j),:));
|
|
|
|
|
mylist = strvcat(mylist,deblank(var_list(j,:)));
|
|
|
|
|
if TeX
|
|
|
|
|
mylistTeX = strvcat(mylistTeX,deblank(var_listTeX(j,:)));
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
2007-07-05 06:34:24 +02:00
|
|
|
|
if options_.nograph == 0
|
|
|
|
|
number_of_plots_to_draw = size(irfs,1);
|
|
|
|
|
[nbplt,nr,nc,lr,lc,nstar] = pltorg(number_of_plots_to_draw);
|
|
|
|
|
if nbplt == 0
|
|
|
|
|
elseif nbplt == 1
|
|
|
|
|
if options_.relative_irf
|
|
|
|
|
hh = figure('Name',['Relative response to' ...
|
|
|
|
|
' orthogonalized shock to ' tit(i,:)]);
|
|
|
|
|
else
|
|
|
|
|
hh = figure('Name',['Orthogonalized shock to' ...
|
|
|
|
|
' ' tit(i,:)]);
|
|
|
|
|
end
|
2005-09-11 11:43:58 +02:00
|
|
|
|
for j = 1:number_of_plots_to_draw
|
2007-07-05 06:34:24 +02:00
|
|
|
|
subplot(nr,nc,j);
|
|
|
|
|
plot(1:options_.irf,transpose(irfs(j,:)),'-k','linewidth',1);
|
|
|
|
|
hold on
|
|
|
|
|
plot([1 options_.irf],[0 0],'-r','linewidth',0.5);
|
|
|
|
|
hold off
|
|
|
|
|
xlim([1 options_.irf]);
|
|
|
|
|
title(deblank(mylist(j,:)),'Interpreter','none');
|
2005-09-11 11:43:58 +02:00
|
|
|
|
end
|
2008-06-24 20:20:48 +02:00
|
|
|
|
eval(['print -depsc2 ' M_.fname '_IRF_' deblank(tit(i,:)) '.eps']);
|
|
|
|
|
if ~exist('OCTAVE_VERSION')
|
|
|
|
|
eval(['print -dpdf ' M_.fname '_IRF_' deblank(tit(i,:))]);
|
|
|
|
|
saveas(hh,[M_.fname '_IRF_' deblank(tit(i,:)) '.fig']);
|
|
|
|
|
end
|
2007-07-05 06:34:24 +02:00
|
|
|
|
if TeX
|
|
|
|
|
fprintf(fidTeX,'\\begin{figure}[H]\n');
|
|
|
|
|
for j = 1:number_of_plots_to_draw
|
|
|
|
|
fprintf(fidTeX,['\\psfrag{%s}[1][][0.5][0]{$%s$}\n'],deblank(mylist(j,:)),deblank(mylistTeX(j,:)));
|
|
|
|
|
end
|
|
|
|
|
fprintf(fidTeX,'\\centering \n');
|
|
|
|
|
fprintf(fidTeX,'\\includegraphics[scale=0.5]{%s_IRF_%s}\n',M_.fname,deblank(tit(i,:)));
|
|
|
|
|
fprintf(fidTeX,'\\caption{Impulse response functions (orthogonalized shock to $%s$).}',titTeX(i,:));
|
|
|
|
|
fprintf(fidTeX,'\\label{Fig:IRF:%s}\n',deblank(tit(i,:)));
|
|
|
|
|
fprintf(fidTeX,'\\end{figure}\n');
|
|
|
|
|
fprintf(fidTeX,' \n');
|
2005-09-11 11:43:58 +02:00
|
|
|
|
end
|
2007-07-05 06:34:24 +02:00
|
|
|
|
% close(hh)
|
|
|
|
|
else
|
|
|
|
|
for fig = 1:nbplt-1
|
|
|
|
|
if options_.relative_irf == 1
|
|
|
|
|
hh = figure('Name',['Relative response to orthogonalized shock' ...
|
|
|
|
|
' to ' tit(i,:) ' figure ' int2str(fig)]);
|
|
|
|
|
else
|
|
|
|
|
hh = figure('Name',['Orthogonalized shock to ' tit(i,:) ...
|
|
|
|
|
' figure ' int2str(fig)]);
|
|
|
|
|
end
|
|
|
|
|
for plt = 1:nstar
|
|
|
|
|
subplot(nr,nc,plt);
|
|
|
|
|
plot(1:options_.irf,transpose(irfs((fig-1)*nstar+plt,:)),'-k','linewidth',1);
|
|
|
|
|
hold on
|
|
|
|
|
plot([1 options_.irf],[0 0],'-r','linewidth',0.5);
|
|
|
|
|
hold off
|
|
|
|
|
xlim([1 options_.irf]);
|
|
|
|
|
title(deblank(mylist((fig-1)*nstar+plt,:)),'Interpreter','none');
|
|
|
|
|
end
|
2008-06-24 20:20:48 +02:00
|
|
|
|
eval(['print -depsc2 ' M_.fname '_IRF_' deblank(tit(i,:)) int2str(fig) '.eps']);
|
|
|
|
|
if ~exist('OCTAVE_VERSION')
|
|
|
|
|
eval(['print -dpdf ' M_.fname '_IRF_' deblank(tit(i,:)) int2str(fig)]);
|
|
|
|
|
saveas(hh,[M_.fname '_IRF_' deblank(tit(i,:)) int2str(fig) '.fig']);
|
|
|
|
|
end
|
2007-07-05 06:34:24 +02:00
|
|
|
|
if TeX
|
|
|
|
|
fprintf(fidTeX,'\\begin{figure}[H]\n');
|
|
|
|
|
for j = 1:nstar
|
|
|
|
|
fprintf(fidTeX,['\\psfrag{%s}[1][][0.5][0]{$%s$}\n'],deblank(mylist((fig-1)*nstar+j,:)),deblank(mylistTeX((fig-1)*nstar+j,:)));
|
|
|
|
|
end
|
|
|
|
|
fprintf(fidTeX,'\\centering \n');
|
|
|
|
|
fprintf(fidTeX,'\\includegraphics[scale=0.5]{%s_IRF_%s%s}\n',M_.fname,deblank(tit(i,:)),int2str(fig));
|
|
|
|
|
if options_.relative_irf
|
|
|
|
|
fprintf(fidTeX,['\\caption{Relative impulse response' ...
|
|
|
|
|
' functions (orthogonalized shock to $%s$).}'],deblank(titTeX(i,:)));
|
|
|
|
|
else
|
|
|
|
|
fprintf(fidTeX,['\\caption{Impulse response functions' ...
|
|
|
|
|
' (orthogonalized shock to $%s$).}'],deblank(titTeX(i,:)));
|
|
|
|
|
end
|
|
|
|
|
fprintf(fidTeX,'\\label{Fig:BayesianIRF:%s:%s}\n',deblank(tit(i,:)),int2str(fig));
|
|
|
|
|
fprintf(fidTeX,'\\end{figure}\n');
|
|
|
|
|
fprintf(fidTeX,' \n');
|
|
|
|
|
end
|
|
|
|
|
% close(hh);
|
|
|
|
|
end
|
|
|
|
|
hh = figure('Name',['Orthogonalized shock to ' tit(i,:) ' figure ' int2str(nbplt) '.']);
|
|
|
|
|
m = 0;
|
|
|
|
|
for plt = 1:number_of_plots_to_draw-(nbplt-1)*nstar;
|
|
|
|
|
m = m+1;
|
|
|
|
|
subplot(lr,lc,m);
|
|
|
|
|
plot(1:options_.irf,transpose(irfs((nbplt-1)*nstar+plt,:)),'-k','linewidth',1);
|
2005-09-11 11:43:58 +02:00
|
|
|
|
hold on
|
|
|
|
|
plot([1 options_.irf],[0 0],'-r','linewidth',0.5);
|
|
|
|
|
hold off
|
|
|
|
|
xlim([1 options_.irf]);
|
2007-07-05 06:34:24 +02:00
|
|
|
|
title(deblank(mylist((nbplt-1)*nstar+plt,:)),'Interpreter','none');
|
2005-09-11 11:43:58 +02:00
|
|
|
|
end
|
2008-06-24 20:20:48 +02:00
|
|
|
|
eval(['print -depsc2 ' M_.fname '_IRF_' deblank(tit(i,:)) int2str(nbplt) '.eps']);
|
|
|
|
|
if ~exist('OCTAVE_VERSION')
|
|
|
|
|
eval(['print -dpdf ' M_.fname '_IRF_' deblank(tit(i,:)) int2str(nbplt)]);
|
|
|
|
|
saveas(hh,[M_.fname '_IRF_' deblank(tit(i,:)) int2str(nbplt) '.fig']);
|
|
|
|
|
end
|
2005-09-11 11:43:58 +02:00
|
|
|
|
if TeX
|
|
|
|
|
fprintf(fidTeX,'\\begin{figure}[H]\n');
|
2007-07-05 06:34:24 +02:00
|
|
|
|
for j = 1:m
|
|
|
|
|
fprintf(fidTeX,['\\psfrag{%s}[1][][0.5][0]{$%s$}\n'],deblank(mylist((nbplt-1)*nstar+j,:)),deblank(mylistTeX((nbplt-1)*nstar+j,:)));
|
2005-09-11 11:43:58 +02:00
|
|
|
|
end
|
|
|
|
|
fprintf(fidTeX,'\\centering \n');
|
2007-07-05 06:34:24 +02:00
|
|
|
|
fprintf(fidTeX,'\\includegraphics[scale=0.5]{%s_IRF_%s%s}\n',M_.fname,deblank(tit(i,:)),int2str(nbplt));
|
2005-09-11 11:43:58 +02:00
|
|
|
|
if options_.relative_irf
|
2007-07-05 06:34:24 +02:00
|
|
|
|
fprintf(fidTeX,['\\caption{Relative impulse response functions' ...
|
|
|
|
|
' (orthogonalized shock to $%s$).}'],deblank(titTeX(i,:)));
|
2005-09-11 11:43:58 +02:00
|
|
|
|
else
|
|
|
|
|
fprintf(fidTeX,['\\caption{Impulse response functions' ...
|
|
|
|
|
' (orthogonalized shock to $%s$).}'],deblank(titTeX(i,:)));
|
|
|
|
|
end
|
2007-07-05 06:34:24 +02:00
|
|
|
|
fprintf(fidTeX,'\\label{Fig:IRF:%s:%s}\n',deblank(tit(i,:)),int2str(nbplt));
|
2005-09-11 11:43:58 +02:00
|
|
|
|
fprintf(fidTeX,'\\end{figure}\n');
|
|
|
|
|
fprintf(fidTeX,' \n');
|
|
|
|
|
end
|
2007-07-05 06:34:24 +02:00
|
|
|
|
% close(hh);
|
2005-09-11 11:43:58 +02:00
|
|
|
|
end
|
2005-02-18 20:54:39 +01:00
|
|
|
|
end
|
|
|
|
|
end
|
2007-07-05 06:34:24 +02:00
|
|
|
|
iter_ = olditer;
|
|
|
|
|
if TeX
|
|
|
|
|
fprintf(fidTeX,' \n');
|
|
|
|
|
fprintf(fidTeX,'%% End Of TeX file. \n');
|
|
|
|
|
fclose(fidTeX);
|
|
|
|
|
end
|
2005-09-11 11:43:58 +02:00
|
|
|
|
end
|
2005-02-18 20:54:39 +01:00
|
|
|
|
end
|
2006-05-24 18:46:32 +02:00
|
|
|
|
|
2006-07-03 14:24:27 +02:00
|
|
|
|
if options_.SpectralDensity == 1
|
2007-01-22 17:34:54 +01:00
|
|
|
|
[omega,f] = UnivariateSpectralDensity(oo_.dr,var_list);
|
2006-07-03 14:24:27 +02:00
|
|
|
|
end
|
2007-01-22 17:34:54 +01:00
|
|
|
|
|
2006-11-18 08:37:22 +01:00
|
|
|
|
|
|
|
|
|
options_ = options_old;
|