diff --git a/matlab/dyn_forecast.m b/matlab/dyn_forecast.m index 828fa0e5dd2621087194fb2e5d4463f86c5a2f4c..5cbc3b2990880eedeacd645a9f6a7c899ce694f3 100644 --- a/matlab/dyn_forecast.m +++ b/matlab/dyn_forecast.m @@ -54,6 +54,16 @@ elseif nargin==6 mean_varobs=dataset_info.descriptive.mean'; end +if options_.order>1 && M_.exo_det_nbr == 0 + error('forecasting without varexo_det does not support order>1.') +end +if options_.order>2 && M_.exo_det_nbr > 0 + error('forecasting with varexo_det does not support order>2.') +end +if options_.order==2 && options_.pruning + error('forecasting with varexo_det does not support pruning.') +end + oo_=make_ex_(M_,options_,oo_); maximum_lag = M_.maximum_lag; @@ -152,9 +162,9 @@ end if M_.exo_det_nbr == 0 if isequal(M_.H,0) - [yf,int_width] = forcst(oo_.dr,y0,horizon,var_list,M_,oo_,options_); + [yf,int_width] = forcst(oo_.dr,y0,horizon,var_list,M_,options_); else - [yf,int_width,int_width_ME] = forcst(oo_.dr,y0,horizon,var_list,M_,oo_,options_); + [yf,int_width,int_width_ME] = forcst(oo_.dr,y0,horizon,var_list,M_,options_); end else exo_det_length = size(oo_.exo_det_simul,1)-M_.maximum_lag; diff --git a/matlab/estimation/dynare_estimation_1.m b/matlab/estimation/dynare_estimation_1.m index d291f9388d53f77f04883cac5a93b5f2e04a8a35..8d1efefbc4b2c4cc48206352a3923d96b2522f4e 100644 --- a/matlab/estimation/dynare_estimation_1.m +++ b/matlab/estimation/dynare_estimation_1.m @@ -12,7 +12,7 @@ function dynare_estimation_1(var_list_,dname) % SPECIAL REQUIREMENTS % none -% Copyright © 2003-2023 Dynare Team +% Copyright © 2003-2024 Dynare Team % % This file is part of Dynare. % @@ -582,12 +582,25 @@ if options_.particle.status end %Run and store classical smoother if needed -if (~((any(bayestopt_.pshape > 0) && options_.mh_replic) || (any(bayestopt_.pshape> 0) && options_.load_mh_file)) ... - || ~options_.smoother ) && ~options_.partial_information % to be fixed +if options_.smoother && ... %Bayesian smoother requested before + (any(bayestopt_.pshape > 0) && options_.mh_replic || ... % Bayesian with MCMC run + any(bayestopt_.pshape > 0) && options_.load_mh_file) % Bayesian with loaded MCMC + % nothing to do +elseif options_.partial_information ||... + options_.order>1 %no particle smoother + % smoothing not yet supported +else %% ML estimation, or posterior mode without Metropolis-Hastings or Metropolis without Bayesian smoothed variables oo_=save_display_classical_smoother_results(xparam1,M_,oo_,options_,bayestopt_,dataset_,dataset_info,estim_params_); end -if options_.forecast > 0 && options_.mh_replic == 0 && ~options_.load_mh_file + +if options_.forecast == 0 || options_.mh_replic > 0 || options_.load_mh_file + % nothing to do +elseif options_.order>1 && M_.exo_det_nbr == 0 || ... + options_.order>2 && M_.exo_det_nbr > 0 || ... + options_.order==2 && options_.pruning + %forecasting not yet supported +else oo_.forecast = dyn_forecast(var_list_,M_,options_,oo_,'smoother',dataset_info); end diff --git a/matlab/forcst.m b/matlab/forcst.m index 79c1af76e495a8a31bdff63298e2dfb112435207..6ab1e0078dd914c5c7f71ca37f4fd44029f82341 100644 --- a/matlab/forcst.m +++ b/matlab/forcst.m @@ -1,5 +1,5 @@ -function [yf,int_width,int_width_ME]=forcst(dr,y0,horizon,var_list,M_,oo_,options_) -% function [yf,int_width,int_width_ME]=forecst(dr,y0,horizon,var_list,M_,oo_,options_) +function [yf,int_width,int_width_ME]=forcst(dr,y0,horizon,var_list,M_,options_) +% function [yf,int_width,int_width_ME]=forecst(dr,y0,horizon,var_list,M_,options_) % computes mean forecast for a given value of the parameters % computes also confidence band for the forecast % @@ -10,7 +10,6 @@ function [yf,int_width,int_width_ME]=forcst(dr,y0,horizon,var_list,M_,oo_,option % var_list: list of variables (character matrix) % M_: Dynare model structure % options_: Dynare options structure -% oo_: Dynare results structure % OUTPUTS: % yf: mean forecast @@ -22,7 +21,7 @@ function [yf,int_width,int_width_ME]=forcst(dr,y0,horizon,var_list,M_,oo_,option % SPECIAL REQUIREMENTS % none -% Copyright © 2003-2019 Dynare Team +% Copyright © 2003-2024 Dynare Team % % This file is part of Dynare. % @@ -39,6 +38,10 @@ function [yf,int_width,int_width_ME]=forcst(dr,y0,horizon,var_list,M_,oo_,option % You should have received a copy of the GNU General Public License % along with Dynare. If not, see <https://www.gnu.org/licenses/>. +if options_.order>1 + error('forcst.m: Only order=1 is supported. Skipping computuations.') +end + yf = simult_(M_,options_,y0,dr,zeros(horizon,M_.exo_nbr),1); nstatic = M_.nstatic; nspred = M_.nspred; diff --git a/matlab/stochastic_solver/simultxdet.m b/matlab/stochastic_solver/simultxdet.m index 7585ddfe96f3e46b87f2ed64d9c9e6c58ff6444c..b5aee2536d985565c7f44842e2968c864fba5cd6 100644 --- a/matlab/stochastic_solver/simultxdet.m +++ b/matlab/stochastic_solver/simultxdet.m @@ -1,5 +1,5 @@ function [y_,int_width,int_width_ME]=simultxdet(y0,ex,ex_det, iorder,var_list,M_,oo_,options_) -%function [y_,int_width]=simultxdet(y0,ex,ex_det, iorder,var_list,M_,oo_,options_) +%function [y_,int_width,int_width_ME]=simultxdet(y0,ex,ex_det, iorder,var_list,M_,oo_,options_) % % Simulates a stochastic model in the presence of deterministic exogenous shocks % @@ -39,6 +39,11 @@ function [y_,int_width,int_width_ME]=simultxdet(y0,ex,ex_det, iorder,var_list,M_ % You should have received a copy of the GNU General Public License % along with Dynare. If not, see <https://www.gnu.org/licenses/>. +if options_.order>2 + error('simultxdet.m: Forecasting with varexo_det does not support order>2.') +elseif options_.order==2 && options_.pruning + error('simultxdet.m: Forecasting with varexo_det does not support pruning.') +end dr = oo_.dr; ykmin = M_.maximum_lag; endo_nbr = M_.endo_nbr; @@ -50,7 +55,6 @@ iter = size(ex,1); if size(ex_det, 1) ~= iter+ykmin error('Size mismatch: number of forecasting periods for stochastic exogenous and deterministic exogenous don''t match') end -nx = size(dr.ghu,2); y_ = zeros(size(y0,1),iter+ykmin); y_(:,1:ykmin) = y0; k1 = ykmin:-1:1; diff --git a/tests/conditional_forecasts/3/fs2000_conditional_forecast_initval.mod b/tests/conditional_forecasts/3/fs2000_conditional_forecast_initval.mod index 5a061b3e13da6e6c70d05a65f8db7a2903f0e652..4f986280dcdbb9d8c8f4ac9bd20e80bf7ed66091 100644 --- a/tests/conditional_forecasts/3/fs2000_conditional_forecast_initval.mod +++ b/tests/conditional_forecasts/3/fs2000_conditional_forecast_initval.mod @@ -63,7 +63,7 @@ steady(tolx=1e-10,tolf=1e-12); check; -stoch_simul(irf=0); +stoch_simul(irf=0,order=1); conditional_forecast_paths; var gy_obs; diff --git a/tests/conditional_forecasts/4/fs2000_conditional_forecast_histval.mod b/tests/conditional_forecasts/4/fs2000_conditional_forecast_histval.mod index 51433faebb55eeff21ec863ad9b5a655ffa1aec2..3c073b553e12442b260cc04e50437b70915bd161 100644 --- a/tests/conditional_forecasts/4/fs2000_conditional_forecast_histval.mod +++ b/tests/conditional_forecasts/4/fs2000_conditional_forecast_histval.mod @@ -61,7 +61,7 @@ steady; check; -stoch_simul(irf=0); +stoch_simul(irf=0,order=1); conditional_forecast_paths; var gy_obs; diff --git a/tests/smoother2histval/fs2000_smooth_stoch_simul.mod b/tests/smoother2histval/fs2000_smooth_stoch_simul.mod index 587c789d82d66bcea6c4474fa979e01c454c4c05..081ea37b949e216453163890f16055ebd0cadd72 100644 --- a/tests/smoother2histval/fs2000_smooth_stoch_simul.mod +++ b/tests/smoother2histval/fs2000_smooth_stoch_simul.mod @@ -87,6 +87,6 @@ steady; smoother2histval(period = 5); options_.loglinear=0; -stoch_simul(nomoments); +stoch_simul(nomoments,order=1); forecast; diff --git a/tests/stochastic_simulations/histval_predetermined.mod b/tests/stochastic_simulations/histval_predetermined.mod index 4bfdbc3e97cebfb97444d4519673de55ede8d7b0..372a3c795078d51c5de9b8ef831c873e74e13c36 100644 --- a/tests/stochastic_simulations/histval_predetermined.mod +++ b/tests/stochastic_simulations/histval_predetermined.mod @@ -54,6 +54,6 @@ b(0) = 0.1; a(0) = 0.3; end; -stoch_simul(nograph, periods = 200); +stoch_simul(nograph, periods = 200,order=1); forecast; \ No newline at end of file diff --git a/tests/stochastic_simulations/histval_sto.mod b/tests/stochastic_simulations/histval_sto.mod index db4ab3c616b9e5e390dd60726b5a5e86d658baeb..eaffc92c1be4aef8903cf8de4cce7a2f62a92363 100644 --- a/tests/stochastic_simulations/histval_sto.mod +++ b/tests/stochastic_simulations/histval_sto.mod @@ -49,7 +49,7 @@ a(-1) = 0.3; u(-1) = 0.1; end; -stoch_simul(nograph, periods = 200); +stoch_simul(nograph, periods = 200,order=1); forecast;