2008-08-01 14:40:33 +02:00
|
|
|
function y_=simult(ys, dr)
|
2007-12-21 18:06:34 +01:00
|
|
|
% function y_=simult(ys, dr)
|
|
|
|
% Recursive Monte Carlo simulations
|
2005-02-18 20:54:39 +01:00
|
|
|
%
|
2007-12-21 18:06:34 +01:00
|
|
|
% INPUTS
|
|
|
|
% ys: vector of variables in steady state
|
|
|
|
% dr: structure of decisions rules for stochastic simulations
|
|
|
|
%
|
|
|
|
% OUTPUTS
|
|
|
|
% y_: stochastic simulations results
|
|
|
|
%
|
|
|
|
% SPECIAL REQUIREMENTS
|
|
|
|
% none
|
|
|
|
%
|
|
|
|
|
2008-08-01 14:40:33 +02:00
|
|
|
% Copyright (C) 2001-2007 Dynare Team
|
|
|
|
%
|
|
|
|
% This file is part of Dynare.
|
|
|
|
%
|
|
|
|
% Dynare is free software: you can redistribute it and/or modify
|
|
|
|
% it under the terms of the GNU General Public License as published by
|
|
|
|
% the Free Software Foundation, either version 3 of the License, or
|
|
|
|
% (at your option) any later version.
|
|
|
|
%
|
|
|
|
% Dynare is distributed in the hope that it will be useful,
|
|
|
|
% but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
% GNU General Public License for more details.
|
|
|
|
%
|
|
|
|
% You should have received a copy of the GNU General Public License
|
|
|
|
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
|
2005-02-18 20:54:39 +01:00
|
|
|
|
|
|
|
global M_ options_ oo_
|
|
|
|
global it_ means_
|
|
|
|
|
|
|
|
order = options_.order;
|
|
|
|
replic = options_.replic;
|
2006-11-25 09:54:17 +01:00
|
|
|
if replic == 0
|
2009-12-16 18:17:34 +01:00
|
|
|
replic = 1;
|
2006-11-25 09:54:17 +01:00
|
|
|
end
|
2005-02-18 20:54:39 +01:00
|
|
|
seed = options_.simul_seed;
|
|
|
|
|
|
|
|
it_ = M_.maximum_lag + 1 ;
|
|
|
|
|
|
|
|
if replic > 1
|
2009-12-16 18:17:34 +01:00
|
|
|
fname = [M_.fname,'_simul'];
|
|
|
|
fh = fopen(fname,'w+');
|
2005-02-18 20:54:39 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
% eliminate shocks with 0 variance
|
|
|
|
i_exo_var = setdiff([1:M_.exo_nbr],find(diag(M_.Sigma_e) == 0));
|
|
|
|
nxs = length(i_exo_var);
|
|
|
|
oo_.exo_simul = zeros(M_.maximum_lag+M_.maximum_lead+options_.periods,M_.exo_nbr);
|
|
|
|
chol_S = chol(M_.Sigma_e(i_exo_var,i_exo_var));
|
|
|
|
|
|
|
|
for i=1:replic
|
2009-12-16 18:17:34 +01:00
|
|
|
if isempty(seed)
|
|
|
|
randn('state',sum(100*clock));
|
|
|
|
else
|
|
|
|
randn('state',seed+i-1);
|
|
|
|
end
|
|
|
|
if ~isempty(M_.Sigma_e)
|
|
|
|
oo_.exo_simul(:,i_exo_var) = randn(M_.maximum_lag+M_.maximum_lead+options_.periods,nxs)*chol_S;
|
|
|
|
end
|
|
|
|
y_ = simult_(ys,dr,oo_.exo_simul,order);
|
|
|
|
if replic > 1
|
|
|
|
fwrite(fh,y_(:,M_.maximum_lag+1:end),'float64');
|
|
|
|
end
|
2005-02-18 20:54:39 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
if replic > 1
|
2009-12-16 18:17:34 +01:00
|
|
|
fclose(fh);
|
2005-02-18 20:54:39 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
% 02/20/01 MJ replaced ys by dr.ys
|
|
|
|
% 02/22/01 MJ removed commented out lines
|
|
|
|
% removed useless temps
|
|
|
|
% stderr_ replaced by M_.Sigma_e
|
|
|
|
% 02/28/01 MJ changed expression for M_.Sigma_e
|
|
|
|
% 02/18/03 MJ added ys in the calling sequence for arbitrary initial values
|
|
|
|
% suppressed useless calling parameter istoch
|
|
|
|
% 05/10/03 MJ removed repmat() in call to simult_() for lag > 1
|
|
|
|
% 05/29/03 MJ test for 0 variances
|