From a2061b6f4ef9b6232d0681aad9b14725a514d22c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= Date: Wed, 21 Dec 2011 18:37:45 +0100 Subject: [PATCH] Initialize empirical simulations with information provided in histval Closes: #195, #157 --- matlab/simult.m | 8 ++++---- matlab/stoch_simul.m | 10 +++++++++- matlab/stoch_simul_sparse.m | 7 ++++++- preprocessor/ComputingTasks.cc | 9 --------- 4 files changed, 19 insertions(+), 15 deletions(-) diff --git a/matlab/simult.m b/matlab/simult.m index 0f8b66e28..303da134f 100644 --- a/matlab/simult.m +++ b/matlab/simult.m @@ -1,9 +1,9 @@ -function y_=simult(ys, dr) -% function y_=simult(ys, dr) +function y_=simult(y0, dr) +% function y_=simult(y0, dr) % Recursive Monte Carlo simulations % % INPUTS -% ys: vector of variables in steady state +% y0: vector of variables in initial period of the simulation % dr: structure of decisions rules for stochastic simulations % % OUTPUTS @@ -54,7 +54,7 @@ for i=1:replic if ~isempty(M_.Sigma_e) oo_.exo_simul(:,i_exo_var) = randn(options_.periods,nxs)*chol_S; end - y_ = simult_(ys,dr,oo_.exo_simul,order); + y_ = simult_(y0,dr,oo_.exo_simul,order); % elimninating initial value y_ = y_(:,2:end); if replic > 1 diff --git a/matlab/stoch_simul.m b/matlab/stoch_simul.m index 7d6e18b8e..ec6d09664 100644 --- a/matlab/stoch_simul.m +++ b/matlab/stoch_simul.m @@ -130,7 +130,15 @@ if options_.periods > 0 && ~PI_PCL_solver options_ =options_old; return end - oo_.endo_simul = simult(oo_.dr.ys,oo_.dr); + % Note that the first column of oo_.endo_simul is preserved by the following + % call to simult; this is important because stoch_simul can be followed by + % forecast (see ticket #157) + if size(oo_.endo_simul,2) == 0 + y0 = oo_.dr.ys; + else + y0 = oo_.endo_simul(:,1); + end + oo_.endo_simul = simult(y0,oo_.dr); dyn2vec; end diff --git a/matlab/stoch_simul_sparse.m b/matlab/stoch_simul_sparse.m index 21194408f..29488b9bb 100644 --- a/matlab/stoch_simul_sparse.m +++ b/matlab/stoch_simul_sparse.m @@ -82,7 +82,12 @@ elseif options_.periods ~= 0 options_ =options_old; return end - oo_.endo_simul = simult(repmat(oo_.dr.ys,1,M_.maximum_lag),oo_.dr); + if size(oo_.endo_simul,2) < maximum_lag + y0 = oo_.dr.ys; + else + y0 = oo_.endo_simul(:,1); + end + oo_.endo_simul = simult(y0,oo_.dr); dyn2vec; if options_.nomoments == 0 disp_moments(oo_.endo_simul,var_list); diff --git a/preprocessor/ComputingTasks.cc b/preprocessor/ComputingTasks.cc index dcd000d46..4cc96f966 100644 --- a/preprocessor/ComputingTasks.cc +++ b/preprocessor/ComputingTasks.cc @@ -135,15 +135,6 @@ StochSimulStatement::checkPass(ModFileStructure &mod_file_struct) cerr << "ERROR: in 'stoch_simul', you cannot use option 'pruning' with 'k_order_solver' option or with 3rd order approximation" << endl; exit(EXIT_FAILURE); } - - // Workaround for ticket #157 - it = options_list.num_options.find("periods"); - if (it != options_list.num_options.end() && atoi(it->second.c_str()) > 0 - && mod_file_struct.histval_present) - { - cerr << "ERROR: the 'periods' option of 'stoch_simul' is not compatible with a 'histval' block" << endl; - exit(EXIT_FAILURE); - } } void