Ramsey: exit with error code if solver fails at specified tolerance

Also adds penalty if steady state ventures into complex space
time-shift
Johannes Pfeifer 2016-08-02 17:09:18 +02:00 committed by Stéphane Adjemian (Lupi)
parent c470e028e1
commit eff52f51b7
3 changed files with 21 additions and 3 deletions

View File

@ -55,7 +55,13 @@ elseif options_.steadystate_flag
end
if inst_nbr == 1
%solve for instrument, using univariate solver, starting at initial value for instrument
inst_val = csolve(nl_func,ys_init(k_inst),'',options_.solve_tolf,100);
[inst_val, info1]= csolve(nl_func,ys_init(k_inst),'',options_.solve_tolf,options_.ramsey.maxit);
if info1==1 || info1==3
check=81;
end
if info1==4
check=87;
end
else
%solve for instrument, using multivariate solver, starting at
%initial value for instrument
@ -63,10 +69,13 @@ elseif options_.steadystate_flag
opt.jacobian_flag = 0;
[inst_val,info1] = dynare_solve(nl_func,ys_init(k_inst), ...
opt);
if info1~=0
check=81;
end
end
ys_init(k_inst) = inst_val;
exo_ss = [oo.exo_steady_state oo.exo_det_steady_state];
[xx,params,check] = evaluate_steady_state_file(ys_init,exo_ss,M,options_,~options_.steadystate.nocheck); %run steady state file again to update parameters
[xx,params] = evaluate_steady_state_file(ys_init,exo_ss,M,options_,~options_.steadystate.nocheck); %run steady state file again to update parameters
[junk,junk,steady_state] = nl_func(inst_val); %compute and return steady state
else
n_var = M.orig_endo_nbr;
@ -110,6 +119,12 @@ if options_.steadystate_flag
[oo.exo_steady_state; ...
oo.exo_det_steady_state], ...
M,options_,~options_.steadystate.nocheck);
if any(imag(x(1:M.orig_endo_nbr))) %return with penalty
resids=1+sum(abs(imag(x(1:M.orig_endo_nbr)))); %return with penalty
steady_state=NaN(endo_nbr,1);
return;
end
end
xx = zeros(endo_nbr,1); %initialize steady state vector

View File

@ -145,7 +145,6 @@ function [ys,params,info] = evaluate_steady_state(ys_init,M,options,oo,steadysta
%either if no steady state file or steady state file without problems
[ys,params,info] = dyn_ramsey_static(ys_init,M,options,oo);
if info
info=81;%case should not happen
return;
end
%check whether steady state really solves the model

View File

@ -148,6 +148,10 @@ if ~noprint
error(['Ramsey: The steady state file computation for the Ramsey problem resulted in NaNs at the initial values of the instruments']);
case 85
error(['Ramsey: The steady state file does not solve the static first order conditions conditional on the instruments.']);
case 86
error(['Ramsey: The steady state file provides complex numbers conditional on the instruments.']);
case 87
error(['Ramsey: The maximum number of iterations has been reached. Try increasing maxit.']);
case 102
error('Aim: roots not correctly computed by real_schur');
case 103