From a6eb943aaef31106cd95840307479dc2de5421ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= Date: Thu, 12 Oct 2023 15:44:53 -0400 Subject: [PATCH] Remove oo_ as an input argument to perfect_foresight_solver_core --- matlab/ep/extended_path_core.m | 2 +- matlab/ep/extended_path_homotopy.m | 4 +-- .../perfect_foresight_solver.m | 4 +-- .../perfect_foresight_solver_core.m | 35 ++++++++++--------- 4 files changed, 23 insertions(+), 22 deletions(-) diff --git a/matlab/ep/extended_path_core.m b/matlab/ep/extended_path_core.m index 6cc5f8db9..4b837c964 100644 --- a/matlab/ep/extended_path_core.m +++ b/matlab/ep/extended_path_core.m @@ -56,7 +56,7 @@ if order == 0 options.lmmcp = olmmcp; options.solve_algo = solve_algo; options.stack_solve_algo = stack_solve_algo; - [endogenousvariablespaths, info_convergence] = perfect_foresight_solver_core(M, options, oo); + [endogenousvariablespaths, info_convergence] = perfect_foresight_solver_core(oo.endo_simul, oo.exo_simul, oo.steady_state, oo.exo_steady_state, M, options); else switch(algo) case 0 diff --git a/matlab/ep/extended_path_homotopy.m b/matlab/ep/extended_path_homotopy.m index 77fbf0e9f..3b08e70f6 100644 --- a/matlab/ep/extended_path_homotopy.m +++ b/matlab/ep/extended_path_homotopy.m @@ -35,7 +35,7 @@ if ismember(method, [1, 2]) oo.endo_simul(:,1) = oo.steady_state + weight*(endo_simul0(:,1) - oo.steady_state); oo.exo_simul = bsxfun(@plus, weight*exo_simul, (1-weight)*transpose(oo.exo_steady_state)); if order==0 - [endo_simul_new, success] = perfect_foresight_solver_core(M, options, oo); + [endo_simul_new, success] = perfect_foresight_solver_core(oo.endo_simul, oo.exo_simul, oo.steady_state, oo.exo_steady_state, M, options); else switch(algo) case 0 @@ -102,7 +102,7 @@ if isequal(method, 3) || (isequal(method, 2) && noconvergence) oo.endo_simul = endo_simul; oo.exo_simul = bsxfun(@plus, weight*exo_simul, (1-weight)*transpose(oo.exo_steady_state)); if order==0 - [endo_simul_new, success] = perfect_foresight_solver_core(M, options, oo); + [endo_simul_new, success] = perfect_foresight_solver_core(oo.endo_simul, oo.exo_simul, oo.steady_state, oo.exo_steady_state, M, options); else switch(algo) case 0 diff --git a/matlab/perfect-foresight-models/perfect_foresight_solver.m b/matlab/perfect-foresight-models/perfect_foresight_solver.m index 29ab48c66..d12c94df8 100644 --- a/matlab/perfect-foresight-models/perfect_foresight_solver.m +++ b/matlab/perfect-foresight-models/perfect_foresight_solver.m @@ -226,7 +226,7 @@ while step > options_.simul.homotopy_min_step_size end % Solve for the paths of the endogenous variables. - [oo_.endo_simul, success, maxerror, solver_iter, per_block_status] = perfect_foresight_solver_core(M_, options_, oo_); + [oo_.endo_simul, success, maxerror, solver_iter, per_block_status] = perfect_foresight_solver_core(oo_.endo_simul, oo_.exo_simul, oo_.steady_state, oo_.exo_steady_state, M_, options_); else success = false; maxerror = NaN; @@ -339,7 +339,7 @@ elseif options_.simul.homotopy_marginal_linearization_fallback > 0 && current_sh extra_simul_time_counter = tic; new_success = create_scenario(new_share); if new_success - [oo_.endo_simul, new_success] = perfect_foresight_solver_core(M_, options_, oo_); + [oo_.endo_simul, new_success] = perfect_foresight_solver_core(oo_.endo_simul, oo_.exo_simul, oo_.steady_state, oo_.exo_steady_state, M_, options_); end extra_simul_time_elapsed = toc(extra_simul_time_counter); if new_success diff --git a/matlab/perfect-foresight-models/perfect_foresight_solver_core.m b/matlab/perfect-foresight-models/perfect_foresight_solver_core.m index c37b77990..1148d5f43 100644 --- a/matlab/perfect-foresight-models/perfect_foresight_solver_core.m +++ b/matlab/perfect-foresight-models/perfect_foresight_solver_core.m @@ -1,11 +1,14 @@ -function [y, success, maxerror, iter, per_block_status] = perfect_foresight_solver_core(M_, options_, oo_) +function [y, success, maxerror, iter, per_block_status] = perfect_foresight_solver_core(y, exo_simul, steady_state, exo_steady_state, M_, options_) % Core function calling solvers for perfect foresight model % % INPUTS +% - y [matrix] initial path of endogenous (typically oo_.endo_simul) +% - exo_simul [matrix] path of exogenous +% - steady_state [vector] steady state of endogenous variables +% - exo_steady_state [vector] steady state of exogenous variables % - M_ [struct] contains a description of the model. % - options_ [struct] contains various options. -% - oo_ [struct] contains results % % OUTPUTS % - y [double array] path for the endogenous variables (solution) @@ -62,50 +65,48 @@ if options_.block end if options_.bytecode try - y = bytecode('dynamic', 'block_decomposed', M_, options_, oo_.endo_simul, oo_.exo_simul, M_.params, repmat(oo_.steady_state,1, periods+2), periods); + y = bytecode('dynamic', 'block_decomposed', M_, options_, y, exo_simul, M_.params, repmat(steady_state,1, periods+2), periods); success = true; catch ME if options_.verbosity >= 1 disp(ME.message) end - y = oo_.endo_simul; % Set something for y, need for computing maxerror success = false; end else - [y, success, maxerror, per_block_status] = solve_block_decomposed_problem(oo_.endo_simul, oo_.exo_simul, oo_.steady_state, options_, M_); + [y, success, maxerror, per_block_status] = solve_block_decomposed_problem(y, exo_simul, steady_state, options_, M_); end else if options_.bytecode try - y = bytecode('dynamic', M_, options_, oo_.endo_simul, oo_.exo_simul, M_.params, repmat(oo_.steady_state, 1, periods+2), periods); + y = bytecode('dynamic', M_, options_, y, exo_simul, M_.params, repmat(steady_state, 1, periods+2), periods); success = true; catch ME if options_.verbosity >= 1 disp(ME.message) end - y = oo_.endo_simul; % Set something for y, need for computing maxerror success = false; end else if M_.maximum_endo_lead == 0 && M_.maximum_endo_lag>0 && ~options_.lmmcp.status % Purely backward model - [y, success] = sim1_purely_backward(oo_.endo_simul, oo_.exo_simul, oo_.steady_state, M_, options_); + [y, success] = sim1_purely_backward(y, exo_simul, steady_state, M_, options_); elseif M_.maximum_endo_lag == 0 && M_.maximum_endo_lead>0 && ~options_.lmmcp.status % Purely forward model - [y, success] = sim1_purely_forward(oo_.endo_simul, oo_.exo_simul, oo_.steady_state, M_, options_); + [y, success] = sim1_purely_forward(y, exo_simul, steady_state, M_, options_); elseif M_.maximum_endo_lag == 0 && M_.maximum_endo_lead == 0 && ~options_.lmmcp.status % Purely static model - [y, success] = sim1_purely_static(oo_.endo_simul, oo_.exo_simul, oo_.steady_state, M_, options_); + [y, success] = sim1_purely_static(y, exo_simul, steady_state, M_, options_); else % General case switch options_.stack_solve_algo case 0 if options_.linear_approximation - [y, success, maxerror] = sim1_linear(oo_.endo_simul, oo_.exo_simul, oo_.steady_state, oo_.exo_steady_state, M_, options_); + [y, success, maxerror] = sim1_linear(y, exo_simul, steady_state, exo_steady_state, M_, options_); else - [y, success, maxerror, iter] = sim1(oo_.endo_simul, oo_.exo_simul, oo_.steady_state, M_, options_); + [y, success, maxerror, iter] = sim1(y, exo_simul, steady_state, M_, options_); end case {1 6} if options_.linear_approximation error('Invalid value of stack_solve_algo option!') end - [y, success, maxerror, iter] = sim1_lbj(oo_.endo_simul, oo_.exo_simul, oo_.steady_state, M_, options_); + [y, success, maxerror, iter] = sim1_lbj(y, exo_simul, steady_state, M_, options_); case 7 if options_.linear_approximation if isequal(options_.solve_algo, 10) @@ -117,9 +118,9 @@ else warning('It would be more efficient to set option solve_algo equal to 0!') end end - [y, success] = solve_stacked_linear_problem(oo_.endo_simul, oo_.exo_simul, oo_.steady_state, oo_.exo_steady_state, M_, options_); + [y, success] = solve_stacked_linear_problem(y, exo_simul, steady_state, exo_steady_state, M_, options_); else - [y, success, maxerror] = solve_stacked_problem(oo_.endo_simul, oo_.exo_simul, oo_.steady_state, M_, options_); + [y, success, maxerror] = solve_stacked_problem(y, exo_simul, steady_state, M_, options_); end otherwise error('Invalid value of stack_solve_algo option!') @@ -131,7 +132,7 @@ end % Some solvers do not compute the maximum error, so do it here if needed if nargout > 2 && isempty(maxerror) if options_.bytecode - residuals = bytecode('dynamic', 'evaluate', M_, options_, y, oo_.exo_simul, M_.params, oo_.steady_state, periods); + residuals = bytecode('dynamic', 'evaluate', M_, options_, y, exo_simul, M_.params, steady_state, periods); else ny = size(y, 1); if M_.maximum_lag > 0 @@ -146,7 +147,7 @@ if nargout > 2 && isempty(maxerror) end yy = y(:,M_.maximum_lag+(1:periods)); - residuals = perfect_foresight_problem(yy(:), y0, yT, oo_.exo_simul, M_.params, oo_.steady_state, periods, M_, options_); + residuals = perfect_foresight_problem(yy(:), y0, yT, exo_simul, M_.params, steady_state, periods, M_, options_); end maxerror = max(max(abs(residuals))); end