From f1aff2b3701b09f8f8de649485fed905253fd209 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Adjemian=20=28Charybdis=29?= Date: Sun, 10 Apr 2022 15:51:55 +0200 Subject: [PATCH] Remove calls to dbstack in dynare_solve. Adding three input parameters for maxit, tolf and tolx. Closes #1841. --- matlab/+occbin/IVF_core.m | 29 +++++++--------- matlab/backward/backward_model_inversion.m | 4 ++- .../simul_backward_nonlinear_model_.m | 13 ++++--- matlab/dyn_ramsey_static.m | 14 ++++---- matlab/dynare_solve.m | 29 ++-------------- matlab/dynare_solve_block_or_bytecode.m | 34 +++++++++---------- ...lve_stochastic_perfect_foresight_model_1.m | 6 +--- matlab/evaluate_steady_state.m | 18 ++++------ matlab/evaluate_steady_state_file.m | 2 +- matlab/partial_information/PCL_resol.m | 5 ++- matlab/partial_information/dr1_PI.m | 4 ++- .../sim1_purely_backward.m | 9 +++-- .../sim1_purely_forward.m | 8 +++-- .../sim1_purely_static.m | 9 +++-- .../solve_stacked_linear_problem.m | 4 ++- .../solve_stacked_problem.m | 8 +++-- matlab/simul_static_model.m | 2 +- matlab/static_model_inversion.m | 3 +- tests/pac/trend-component-28/example2.mod | 5 +-- tests/pac/trend-component-28/example4.mod | 2 +- 20 files changed, 96 insertions(+), 112 deletions(-) diff --git a/matlab/+occbin/IVF_core.m b/matlab/+occbin/IVF_core.m index 31e56e3c0..6f84572c4 100644 --- a/matlab/+occbin/IVF_core.m +++ b/matlab/+occbin/IVF_core.m @@ -1,13 +1,13 @@ function [filtered_errs, resids, Emat, stateval, error_code] = IVF_core(M_,oo_,options_,err_index,filtered_errs_init,my_obs_list,obs,init_val) % function [filtered_errs, resids, Emat, stateval] = IVF_core(M_,oo_,options_,err_index,filtered_errs_init,my_obs_list,obs,init_val) -% Computes thre +% Computes thre % % Outputs: % - filtered_errs [T by N_obs] filtered shocks % - resids [T by N_obs] residuals % - Emat [N by N_obs by T] response matrix of endogenous variables to shocks at each point in time % - stateval [T by N] vector of endogenous variables -% - error_code [4 by 1] error code +% - error_code [4 by 1] error code % % Inputs % - M_ [structure] Matlab's structure describing the model (M_). @@ -16,7 +16,7 @@ function [filtered_errs, resids, Emat, stateval, error_code] = IVF_core(M_,oo_,o % - err_index [double] index of shocks with strictly positive variance in M_.exo_names % - filtered_errs_init [T by N_obs] initial values for the shocks % - my_obs_list [cell] names of observables -% - obs [T by N_obs] observed data +% - obs [T by N_obs] observed data % - init_val [N by 1] initial value of endogenous variables % Original authors: Pablo Cuba-Borda, Luca Guerrieri, Matteo Iacoviello, and Molin Zhong @@ -28,7 +28,7 @@ function [filtered_errs, resids, Emat, stateval, error_code] = IVF_core(M_,oo_,o % However the authors would appreciate acknowledgement of the source by % citation of any of the following papers: % -% Pablo Cuba-Borda, Luca Guerrieri, Matteo Iacoviello, and Molin Zhong (2019): "Likelihood evaluation of models +% Pablo Cuba-Borda, Luca Guerrieri, Matteo Iacoviello, and Molin Zhong (2019): "Likelihood evaluation of models % with occasionally binding constraints", Journal of Applied Econometrics, % 34(7), 1073-1085 @@ -70,14 +70,14 @@ if options_.occbin.likelihood.waitbar hh = dyn_waitbar(0,'IVF_core: Filtering the shocks'); set(hh,'Name','IVF_core: Filtering the shocks.'); end - + for this_period=1:sample_length if options_.occbin.likelihood.waitbar dyn_waitbar(this_period/sample_length, hh, sprintf('Period %u of %u', this_period,sample_length)); end current_obs = obs(this_period,:); init_val_old = init_val; - + inan = ~isnan(current_obs); current_obs = current_obs(inan); obs_list = my_obs_list(inan); @@ -85,23 +85,20 @@ for this_period=1:sample_length opts_simul.exo_pos=err_index(inan); %err_index is predefined mapping from observables to shocks opts_simul.endo_init = init_val_old; opts_simul.SHOCKS = filtered_errs_init(this_period,inan); -% [ err_vals_out, exitflag ] = csolve(@(err_vals) occbin.match_function(... -% err_vals, obs_list,current_obs, opts_simul, M_,oo_,options_),... -% err0',@(err_vals) occbin.match_function(... -% err_vals, obs_list,current_obs, opts_simul, M_,oo_,options_),options_.solve_tolf,options_.occbin.solver.maxit); - [err_vals_out, exitflag] = dynare_solve(@occbin.match_function, filtered_errs_init(this_period,inan)', options_, obs_list,current_obs, opts_simul, M_,oo_,options_); - + % TODO We should probably have a specific field for maxit (new option?) + [err_vals_out, exitflag] = dynare_solve(@occbin.match_function, filtered_errs_init(this_period,inan)', options_.steady.maxit, options_.solve_tolf, options_.solve_tolx, options_, obs_list, current_obs, opts_simul, M_, oo_, options_); + if exitflag filtered_errs=NaN; error_code(1) = 304; error_code(4) = 1000; if options_.occbin.likelihood.waitbar; dyn_waitbar_close(hh); end - return + return end filtered_errs(this_period,inan)=err_vals_out'; - + opts_simul.SHOCKS = err_vals_out; - + [ resids(this_period,inan), ~, stateval(this_period,:), Emat(:,inan,this_period), M_] = occbin.match_function(... err_vals_out,obs_list,current_obs,opts_simul, M_,oo_,options_); init_val = stateval(this_period,:); %update @@ -123,7 +120,7 @@ for this_period=1:sample_length end end if options_.occbin.likelihood.waitbar - dyn_waitbar_close(hh); + dyn_waitbar_close(hh); end end \ No newline at end of file diff --git a/matlab/backward/backward_model_inversion.m b/matlab/backward/backward_model_inversion.m index 0dd709e5b..8eb7c6f88 100644 --- a/matlab/backward/backward_model_inversion.m +++ b/matlab/backward/backward_model_inversion.m @@ -108,7 +108,9 @@ for t = 1:nobs(constraints) % values) and the free exogenous variables (initialized with 0). z = [Y(freeendogenousvariables_id,ity-1); zeros(nxfree, 1)]; % Solves for z. - [z, failed, ~, ~, errorcode] = dynare_solve(model_dtransf, z, DynareOptions, model_dynamic, ylag, ycur, X, DynareModel.params, DynareOutput.steady_state, itx, ModelInversion); + [z, failed, ~, ~, errorcode] = dynare_solve(model_dtransf, z, ... + DynareOptions.simul.maxit, DynareOptions.dynatol.f, DynareOptions.dynatol.x, ... + DynareOptions, model_dynamic, ylag, ycur, X, DynareModel.params, DynareOutput.steady_state, itx, ModelInversion); if failed error('Nonlinear solver failed with errorcode=%i', errorcode) end diff --git a/matlab/backward/simul_backward_nonlinear_model_.m b/matlab/backward/simul_backward_nonlinear_model_.m index d84b605ed..f9db34eca 100644 --- a/matlab/backward/simul_backward_nonlinear_model_.m +++ b/matlab/backward/simul_backward_nonlinear_model_.m @@ -56,13 +56,16 @@ for it = initialconditions.nobs+(1:samplesize) y = y_; % A good guess for the initial conditions is the previous values for the endogenous variables. try if ismember(DynareOptions.solve_algo, [12,14]) - [DynareOutput.endo_simul(:,it), errorflag, ~, ~, errorcode] = ... - dynare_solve(model_dynamic_s, y, DynareOptions, ... - DynareModel.isloggedlhs, DynareModel.isauxdiffloggedrhs, DynareModel.endo_names, DynareModel.lhs, ... - model_dynamic, ylag, DynareOutput.exo_simul, DynareModel.params, DynareOutput.steady_state, it); + [DynareOutput.endo_simul(:,it), errorflag, ~, ~, errorcode] = dynare_solve(model_dynamic_s, y, ... + DynareOptions.simul.maxit, DynareOptions.dynatol.f, DynareOptions.dynatol.x, ... + DynareOptions, ... + DynareModel.isloggedlhs, DynareModel.isauxdiffloggedrhs, DynareModel.endo_names, DynareModel.lhs, ... + model_dynamic, ylag, DynareOutput.exo_simul, DynareModel.params, DynareOutput.steady_state, it); else [DynareOutput.endo_simul(:,it), errorflag, ~, ~, errorcode] = ... - dynare_solve(model_dynamic_s, y, DynareOptions, ... + dynare_solve(model_dynamic_s, y, ... + DynareOptions.simul.maxit, DynareOptions.dynatol.f, DynareOptions.dynatol.x, ... + DynareOptions, ... model_dynamic, ylag, DynareOutput.exo_simul, DynareModel.params, DynareOutput.steady_state, it); end if errorflag diff --git a/matlab/dyn_ramsey_static.m b/matlab/dyn_ramsey_static.m index 09b1eb5cb..efffeb60b 100644 --- a/matlab/dyn_ramsey_static.m +++ b/matlab/dyn_ramsey_static.m @@ -1,6 +1,5 @@ -function [steady_state,params,check] = dyn_ramsey_static(ys_init,M,options_,oo) +function [steady_state, params, check] = dyn_ramsey_static(ys_init, M, options_, oo) -% function [steady_state,params,check] = dyn_ramsey_static_(ys_init,M,options_,oo) % Computes the steady state for optimal policy % % INPUTS @@ -18,7 +17,7 @@ function [steady_state,params,check] = dyn_ramsey_static(ys_init,M,options_,oo) % SPECIAL REQUIREMENTS % none -% Copyright (C) 2003-2020 Dynare Team +% Copyright © 2003-2022 Dynare Team % % This file is part of Dynare. % @@ -66,9 +65,8 @@ elseif options_.steadystate_flag %initial value for instrument opt = options_; opt.jacobian_flag = false; - [inst_val,info1] = dynare_solve(nl_func,ys_init(k_inst), ... - opt); - if info1~=0 + [inst_val, errorflag] = dynare_solve(nl_func, ys_init(k_inst), options_.ramsey.maxit, options_.solve_tolf, options_.solve_tolx, opt); + if errorflag check=81; end end @@ -81,8 +79,8 @@ else xx = oo.steady_state(1:n_var); opt = options_; opt.jacobian_flag = false; - [xx,info1] = dynare_solve(nl_func,xx,opt); - if info1~=0 + [xx, errorflag] = dynare_solve(nl_func, xx, options_.ramsey.maxit, options_.solve_tolf, options_.solve_tolx, opt); + if errorflag check=81; end [~,~,steady_state] = nl_func(xx); diff --git a/matlab/dynare_solve.m b/matlab/dynare_solve.m index 985ddd479..94fe6aba7 100644 --- a/matlab/dynare_solve.m +++ b/matlab/dynare_solve.m @@ -1,4 +1,4 @@ -function [x, errorflag, fvec, fjac, errorcode] = dynare_solve(f, x, options, varargin) +function [x, errorflag, fvec, fjac, errorcode] = dynare_solve(f, x, maxit, tolf, tolx, options, varargin) % Solves a nonlinear system of equations, f(x) = 0 with n unknowns % and n equations. @@ -41,32 +41,6 @@ function [x, errorflag, fvec, fjac, errorcode] = dynare_solve(f, x, options, var jacobian_flag = options.jacobian_flag; % true iff Jacobian is returned by f routine (as a second output argument). -% Set tolerance parameter depending the the caller function. -stack = dbstack; -if isoctave - [~, name, ext]=fileparts(stack(2).file); - caller_file_name=[name,ext]; -else - if size(stack,1)>1 - caller_file_name=stack(2).file; - else - caller_file_name=stack(1).file; - end -end -if strcmp(caller_file_name, 'solve_stacked_problem.m') || strcmp(caller_file_name, 'sim1_purely_backward.m') - tolf = options.dynatol.f; - tolx = options.dynatol.x; -else - tolf = options.solve_tolf; - tolx = options.solve_tolx; -end - -if strcmp(caller_file_name,'dyn_ramsey_static.m') - maxit = options.ramsey.maxit; -else - maxit = options.steady.maxit; -end - errorflag = false; % Let's be optimistic! nn = size(x,1); @@ -96,6 +70,7 @@ else end % checking initial values +% TODO We should have an option to deactivate the randomization. if jacobian_flag [fvec, fjac] = feval(f, x, arguments{:}); wrong_initial_guess_flag = false; diff --git a/matlab/dynare_solve_block_or_bytecode.m b/matlab/dynare_solve_block_or_bytecode.m index c56d4e613..a2832f17f 100644 --- a/matlab/dynare_solve_block_or_bytecode.m +++ b/matlab/dynare_solve_block_or_bytecode.m @@ -1,5 +1,6 @@ function [x,info] = dynare_solve_block_or_bytecode(y, exo, params, options, M) -% Copyright (C) 2010-2022 Dynare Team + +% Copyright © 2010-2022 Dynare Team % % This file is part of Dynare. % @@ -25,12 +26,11 @@ if options.block && ~options.bytecode if M.block_structure_stat.block(b).Simulation_Type ~= 1 && ... M.block_structure_stat.block(b).Simulation_Type ~= 2 if options.solve_algo <= 4 || options.solve_algo >= 9 - [y, check] = dynare_solve('block_mfs_steadystate', ... - ss(M.block_structure_stat.block(b).variable), ... - options, b, ss, exo, params, T, M); - if check ~= 0 - % error(['STEADY: convergence - % problems in block ' int2str(b)]) + [y, errorflag] = dynare_solve('block_mfs_steadystate', ... + ss(M.block_structure_stat.block(b).variable), ... + options.simul.maxit, options.solve_tolf, options.solve_tolx, ... + options, b, ss, exo, params, T, M); + if errorflag info = 1; return end @@ -65,13 +65,11 @@ elseif options.bytecode for b = 1:length(M.block_structure_stat.block) if M.block_structure_stat.block(b).Simulation_Type ~= 1 && ... M.block_structure_stat.block(b).Simulation_Type ~= 2 - [y, check] = dynare_solve('block_bytecode_mfs_steadystate', ... - x(M.block_structure_stat ... - .block(b).variable), ... - options, b, x, exo, params, T, M); - if check - % error(['STEADY: convergence problems in block ' - % int2str(b)]) + [y, errorflag] = dynare_solve('block_bytecode_mfs_steadystate', ... + x(M.block_structure_stat.block(b).variable), ... + options.simul.maxit, options.solve_tolf, options.solve_tolx, ... + options, b, x, exo, params, T, M); + if errorflag info = 1; return end @@ -89,10 +87,10 @@ elseif options.bytecode end end else - [x, check] = dynare_solve('bytecode_steadystate', y, ... - options, exo, params); - if check - % error('STEADY: convergence problems') + [x, errorflag] = dynare_solve('bytecode_steadystate', y, ... + options.simul.maxit, options.solve_tolf, options.solve_tolx, ... + options, exo, params); + if errorflag info = 1; return end diff --git a/matlab/ep/solve_stochastic_perfect_foresight_model_1.m b/matlab/ep/solve_stochastic_perfect_foresight_model_1.m index d3f7ec78d..5d2817dad 100644 --- a/matlab/ep/solve_stochastic_perfect_foresight_model_1.m +++ b/matlab/ep/solve_stochastic_perfect_foresight_model_1.m @@ -143,9 +143,5 @@ Options.steady.maxit = 100; y = repmat(steady_state,block_nbr,1); Options.solve_algo = Options.ep.solve_algo; Options.steady.maxit = Options.ep.maxit; -[y, errorflag, ~, ~, errorcode] = dynare_solve(@ep_problem_2,y,Options,exo_simul,pfm); -if info - flag = 1; - err = info; -end +[y, errorflag, ~, ~, errorcode] = dynare_solve(@ep_problem_2, y, Options.simul.maxit, Options.dynatol.f, Options.dynatol.x, Options, exo_simul, pfm); endo_simul(:,2) = y(1:ny); \ No newline at end of file diff --git a/matlab/evaluate_steady_state.m b/matlab/evaluate_steady_state.m index 651363dc5..0f83e14c0 100644 --- a/matlab/evaluate_steady_state.m +++ b/matlab/evaluate_steady_state.m @@ -261,18 +261,14 @@ elseif steadystate_flag elseif ~options.bytecode && ~options.block if ~options.linear % non linear model - static_model = str2func([M.fname '.static']); - [ys, check] = dynare_solve(@static_problem, ... - ys_init, ... - options, exo_ss, params, ... - M.endo_nbr, ... - static_model); + static_model = str2func(sprintf('%s.static', M.fname)); + [ys, check] = dynare_solve(@static_problem, ys_init, ... + options.steady.maxit, options.solve_tolf, options.solve_tolx, ... + options, exo_ss, params, M.endo_nbr, static_model); if check && options.debug - [ys, check, fvec, fjac, errorcode] = dynare_solve(@static_problem, ... - ys_init, ... - options, exo_ss, params, ... - M.endo_nbr, ... - static_model); + [ys, check, fvec, fjac, errorcode] = dynare_solve(@static_problem, ys_init, ... + options.steady.maxit, options.solve_tolf, options.solve_tolx, ... + options, exo_ss, params, M.endo_nbr, static_model); dprintf('Nonlinear solver routine returned errorcode=%i.', errorcode) skipline() [infrow,infcol]=find(isinf(fjac) | isnan(fjac)); diff --git a/matlab/evaluate_steady_state_file.m b/matlab/evaluate_steady_state_file.m index 4a804962f..5d6d4ea00 100644 --- a/matlab/evaluate_steady_state_file.m +++ b/matlab/evaluate_steady_state_file.m @@ -127,5 +127,5 @@ elseif ~isempty(options.steadystate_partial) for i = 1:nov indv(i) = strmatch(ssvar(i), M.endo_names, 'exact'); end - ys = dynare_solve('restricted_steadystate', ys(indv), options, exo_ss,indv); + ys = dynare_solve('restricted_steadystate', ys(indv), options.steady.maxit, options.dynatol.f, options.dynatol.x, options, exo_ss, indv); end diff --git a/matlab/partial_information/PCL_resol.m b/matlab/partial_information/PCL_resol.m index 39dd0f9e0..da95e7539 100644 --- a/matlab/partial_information/PCL_resol.m +++ b/matlab/partial_information/PCL_resol.m @@ -91,9 +91,8 @@ else oo_.exo_det_steady_state], M_.params))) > options_.solve_tolf opt = options_; opt.jacobian_flag = false; - [dr.ys,check1] = dynare_solve(fh,dr.ys,opt,... - [oo_.exo_steady_state; ... - oo_.exo_det_steady_state], M_.params); + [dr.ys, check1] = dynare_solve(fh,dr.ys, options.steady_.maxit, options_.solve_tolf, options_.solve_tolx, ... + opt, [oo_.exo_steady_state; oo_.exo_det_steady_state], M_.params); end else % linear models diff --git a/matlab/partial_information/dr1_PI.m b/matlab/partial_information/dr1_PI.m index dfafa44a0..0b12df983 100644 --- a/matlab/partial_information/dr1_PI.m +++ b/matlab/partial_information/dr1_PI.m @@ -89,7 +89,9 @@ if options_.ramsey_policy && ~options_.ACES_solver % options_.solve_algo = 1; opt = options_; opt.jacobian_flag = false; - oo_.steady_state = dynare_solve('ramsey_static',oo_.steady_state,opt,M_,options_,oo_,it_); + oo_.steady_state = dynare_solve('ramsey_static', oo_.steady_state, ... + options_.ramsey.maxit, options_.solve_tolf, options_.solve_tolx, ... + opt, M_, options_, oo_, it_); options_.solve_algo = old_solve_algo; [~,~,multbar] = ramsey_static(oo_.steady_state,M_,options_,oo_,it_); [jacobia_,M_] = ramsey_dynamic(oo_.steady_state,multbar,M_,options_,oo_,it_); diff --git a/matlab/perfect-foresight-models/sim1_purely_backward.m b/matlab/perfect-foresight-models/sim1_purely_backward.m index 2b1ab8664..568ebe709 100644 --- a/matlab/perfect-foresight-models/sim1_purely_backward.m +++ b/matlab/perfect-foresight-models/sim1_purely_backward.m @@ -39,11 +39,14 @@ for it = M.maximum_lag + (1:options.periods) y = endogenousvariables(:,it-1); % Values at previous period, also used as guess value for current period ylag = y(iyb); if ismember(options.solve_algo, [12,14]) - [tmp, check, ~, ~, errorcode] = dynare_solve(dynamicmodel_s, y, options, M.isloggedlhs, M.isauxdiffloggedrhs, M.endo_names, M.lhs, ... + [tmp, check, ~, ~, errorcode] = dynare_solve(dynamicmodel_s, y, ... + options.simul.maxit, options.dynatol.f, options.dynatol.x, ... + options, M.isloggedlhs, M.isauxdiffloggedrhs, M.endo_names, M.lhs, ... dynamicmodel, ylag, exogenousvariables, M.params, steadystate, it); else - [tmp, check, ~, ~, errorcode] = dynare_solve(dynamicmodel_s, y, options, ... - dynamicmodel, ylag, exogenousvariables, M.params, steadystate, it); + [tmp, check, ~, ~, errorcode] = dynare_solve(dynamicmodel_s, y, ... + options.simul.maxit, options.dynatol.f, options.dynatol.x, ... + options, dynamicmodel, ylag, exogenousvariables, M.params, steadystate, it); end if check info.status = false; diff --git a/matlab/perfect-foresight-models/sim1_purely_forward.m b/matlab/perfect-foresight-models/sim1_purely_forward.m index 9872a8e31..715c544e8 100644 --- a/matlab/perfect-foresight-models/sim1_purely_forward.m +++ b/matlab/perfect-foresight-models/sim1_purely_forward.m @@ -33,10 +33,14 @@ info.status = true; for it = options.periods:-1:1 yf = endogenousvariables(:,it+1); % Values at next period, also used as guess value for current period if ismember(options.solve_algo, [12,14]) - [tmp, check, ~, ~, errorcode] = dynare_solve(dynamicmodel_s, yf, options, M.isloggedlhs, M.isauxdiffloggedrhs, M.endo_names, M.lhs, ... + [tmp, check, ~, ~, errorcode] = dynare_solve(dynamicmodel_s, yf, ... + options.simul.maxit, options.dynatol.f, options.dynatol.x, ... + options, M.isloggedlhs, M.isauxdiffloggedrhs, M.endo_names, M.lhs, ... dynamicmodel, yf(iyf), exogenousvariables, M.params, steadystate, it); else - [tmp, check, ~, ~, errorcode] = dynare_solve(dynamicmodel_s, yf, options, ... + [tmp, check, ~, ~, errorcode] = dynare_solve(dynamicmodel_s, yf, ... + options.simul.maxit, options.dynatol.f, options.dynatol.x, ... + options, ... dynamicmodel, yf(iyf), exogenousvariables, M.params, steadystate, it); end if check diff --git a/matlab/perfect-foresight-models/sim1_purely_static.m b/matlab/perfect-foresight-models/sim1_purely_static.m index 74de6ecb8..8563d730d 100644 --- a/matlab/perfect-foresight-models/sim1_purely_static.m +++ b/matlab/perfect-foresight-models/sim1_purely_static.m @@ -36,11 +36,14 @@ y = endogenousvariables(:,1); for it = 1:options.periods if ismember(options.solve_algo, [12,14]) - [tmp, check, ~, ~, errorcode] = dynare_solve(dynamicmodel_s, y, options, M.isloggedlhs, M.isauxdiffloggedrhs, M.endo_names, M.lhs, ... + [tmp, check, ~, ~, errorcode] = dynare_solve(dynamicmodel_s, y, ... + options.simul.maxit, options.dynatol.f, options.dynatol.x, ... + options, M.isloggedlhs, M.isauxdiffloggedrhs, M.endo_names, M.lhs, ... dynamicmodel, exogenousvariables, M.params, steadystate, it); else - [tmp, check, ~, ~, errorcode] = dynare_solve(dynamicmodel_s, y, options, ... - dynamicmodel, exogenousvariables, M.params, steadystate, it); + [tmp, check, ~, ~, errorcode] = dynare_solve(dynamicmodel_s, y, ... + options.simul.maxit, options.dynatol.f, options.dynatol.x, ... + options, dynamicmodel, exogenousvariables, M.params, steadystate, it); end if check info.status = false; diff --git a/matlab/perfect-foresight-models/solve_stacked_linear_problem.m b/matlab/perfect-foresight-models/solve_stacked_linear_problem.m index 2a30699de..5803d039e 100644 --- a/matlab/perfect-foresight-models/solve_stacked_linear_problem.m +++ b/matlab/perfect-foresight-models/solve_stacked_linear_problem.m @@ -41,7 +41,9 @@ jendo = transpose(1:nd); z = bsxfun(@minus, z, steadystate_y); x = bsxfun(@minus, exogenousvariables, steadystate_x'); -[y, check, ~, ~, errorcode] = dynare_solve(@linear_perfect_foresight_problem,z(:), options, ... +[y, check, ~, ~, errorcode] = dynare_solve(@linear_perfect_foresight_problem, z(:), ... + options.simul.maxit, options.dynatol.f, options.dynatol.x, ... + options, ... jacobian, y0-steadystate_y, yT-steadystate_y, ... x, M.params, steadystate_y, ... M.maximum_lag, options.periods, M.endo_nbr, i_cols, ... diff --git a/matlab/perfect-foresight-models/solve_stacked_problem.m b/matlab/perfect-foresight-models/solve_stacked_problem.m index 484d7f9cf..5b39815d7 100644 --- a/matlab/perfect-foresight-models/solve_stacked_problem.m +++ b/matlab/perfect-foresight-models/solve_stacked_problem.m @@ -46,14 +46,18 @@ if (options.solve_algo == 10 || options.solve_algo == 11)% mixed complementarity options.mcppath.lb = repmat(lb,options.periods,1); options.mcppath.ub = repmat(ub,options.periods,1); end - [y, check, ~, ~, errorcode] = dynare_solve(@perfect_foresight_mcp_problem,z(:),options, ... + [y, check, ~, ~, errorcode] = dynare_solve(@perfect_foresight_mcp_problem, z(:), ... + options.simul.maxit, options.dynatol.f, options.dynatol.x, ... + options, ... dynamicmodel, y0, yT, ... exogenousvariables, M.params, steadystate, ... M.maximum_lag, options.periods, M.endo_nbr, i_cols, ... i_cols_J1, i_cols_1, i_cols_T, i_cols_j, i_cols_0, i_cols_J0, ... eq_index); else - [y, check, ~, ~, errorcode] = dynare_solve(@perfect_foresight_problem,z(:), options, y0, yT, exogenousvariables, M.params, steadystate, options.periods, M, options); + [y, check, ~, ~, errorcode] = dynare_solve(@perfect_foresight_problem, z(:), ... + options.simul.maxit, options.dynatol.f, options.dynatol.x, ... + options, y0, yT, exogenousvariables, M.params, steadystate, options.periods, M, options); end if all(imag(y)<.1*options.dynatol.x) diff --git a/matlab/simul_static_model.m b/matlab/simul_static_model.m index 44e8d09e0..05d94b808 100644 --- a/matlab/simul_static_model.m +++ b/matlab/simul_static_model.m @@ -88,7 +88,7 @@ staticmodel = str2fun(sprintf('%s.static', M_.fname)); % Simulations (call a Newton-like algorithm for each period). for t=1:samplesize y = zeros(M_.endo_nbr, 1); - [oo_.endo_simul(:,t), info, ~, ~, errorcode] = dynare_solve(staticmodel, y, options_, oo_.exo_simul(t,:), M_.params); + [oo_.endo_simul(:,t), info, ~, ~, errorcode] = dynare_solve(staticmodel, y, options_.simul.maxit, options_.dynatol.f, options_.dynatol.x, options_, oo_.exo_simul(t,:), M_.params); if info error('Newton failed (with error code %i).', errorcode) end diff --git a/matlab/static_model_inversion.m b/matlab/static_model_inversion.m index c2b8d80e2..06bb20ba3 100644 --- a/matlab/static_model_inversion.m +++ b/matlab/static_model_inversion.m @@ -103,7 +103,8 @@ for t = 1:nobs(constraints) % values) and the free exogenous variables (initialized with 0). z = [Y(freeendogenousvariables_id,ity); zeros(nxfree, 1)]; % Solves for z. - [z, errorflag, ~, ~, errorcode] = dynare_solve(model_stransf, z, DynareOptions, model_dynamic, ycur, X(itx, :), DynareModel.params, ModelInversion); + [z, errorflag, ~, ~, errorcode] = dynare_solve(model_stransf, z, DynareOptions.simul.maxit, DynareOptions.dynatol.f, DynareOptions.dynatol.x, ... + DynareOptions, model_dynamic, ycur, X(itx, :), DynareModel.params, ModelInversion); if errorflag error('Enable to solve the system of equations (with error code %i).', errorcode) end diff --git a/tests/pac/trend-component-28/example2.mod b/tests/pac/trend-component-28/example2.mod index 9034fb10f..0880667e6 100644 --- a/tests/pac/trend-component-28/example2.mod +++ b/tests/pac/trend-component-28/example2.mod @@ -48,7 +48,7 @@ c_z_2 = -.1; c_z_dx2 = .3; c_z_u = .3; c_z_dv = .4; -c_z_s = -.2; +c_z_s = -.2; cx = 1.0; cy = 1.0; @@ -122,6 +122,7 @@ init = rand(10, M_.endo_nbr+M_.exo_nbr); initialconditions = dseries(init, 2000Q1, vertcat(M_.endo_names,M_.exo_names)); // Simulate the model for 500 periods +options_.dynatol.f = 1e-9; TrueData = simul_backward_model(initialconditions, 500); TrueData_ = copy(TrueData); @@ -144,4 +145,4 @@ fprintf('Max. abs. error is %s.\n', num2str(max(abs(TrueData.x3.data(12:end)-Tru if max(abs(TrueData.x3.data(12:end)-TrueData_.x3.data(12:end)))>1e-5 error('equation.evaluate() returned wrong values.') -end \ No newline at end of file +end diff --git a/tests/pac/trend-component-28/example4.mod b/tests/pac/trend-component-28/example4.mod index b73c4720c..41beb37c2 100644 --- a/tests/pac/trend-component-28/example4.mod +++ b/tests/pac/trend-component-28/example4.mod @@ -119,7 +119,7 @@ init = ones(10, M_.endo_nbr+M_.exo_nbr); initialconditions = dseries(init, 2000Q1, vertcat(M_.endo_names,M_.exo_names)); // Simulate the model for 500 periods -options_.solve_tolf = 1e-9; +options_.dynatol.f = 1e-9; TrueData = simul_backward_model(initialconditions, 5000); TrueData_ = copy(TrueData);