Commit f8ecc4d6 authored by MichelJuillard's avatar MichelJuillard
Browse files

reorganized code for evaluating steady state file

parent abc60b60
......@@ -53,8 +53,7 @@ if options_.steadystate_flag
end
ys(k_inst) = inst_val;
exo_ss = [oo.exo_steady_state oo.exo_det_steady_state];
[xx,params,check] = evaluate_steady_state_file(ys,exo_ss,params,...
M.fname,options_.steadystate_flag);
[xx,params,check] = evaluate_steady_state_file(ys,exo_ss,M,options_);
else
n_var = M.orig_endo_nbr;
xx = oo.steady_state(1:n_var);
......@@ -103,9 +102,8 @@ if options_.steadystate_flag
oo.steady_state(k_inst) = x;
[x,params,check] = evaluate_steady_state_file(oo.steady_state,...
[oo.exo_steady_state; ...
oo.exo_det_steady_state] ...
,params,fname,...
options_.steadystate_flag);
oo.exo_det_steady_state], ...
M,options_);
end
xx = zeros(endo_nbr,1);
......
function [ys,params,info] = evaluate_steady_state(ys_init,M,options,oo,steadystate_check_flag)
% function [ys,info] = evaluate_steady_state(M,options,oo)
% function [ys,params,info] = evaluate_steady_state(ys_init,M,options,oo,steadystate_check_flag)
% Computes the steady state
%
% INPUTS
......@@ -45,7 +45,6 @@ function [ys,params,info] = evaluate_steady_state(ys_init,M,options,oo,steadysta
steadystate_flag = options.steadystate_flag;
params = M.params;
exo_ss = [oo.exo_steady_state; oo.exo_det_steady_state];
updated_params_flag = 0;
if length(M.aux_vars) > 0
h_set_auxiliary_variables = str2func([M.fname '_set_auxiliary_variables']);
......@@ -56,45 +55,7 @@ function [ys,params,info] = evaluate_steady_state(ys_init,M,options,oo,steadysta
[ys,params] = dyn_ramsey_static(ys_init,M,options,oo);
elseif steadystate_flag
% explicit steady state file
[ys,params1,check] = evaluate_steady_state_file(ys_init,exo_ss,params,M.fname,steadystate_flag);
if ~length(find(isnan(params))) && ~length(find(isnan(params1)))
updated_params_flag = max(abs(params1-params))>1e-12;
elseif length(find(isnan(params))) && ~length(find(isnan(params1)))
updated_params_flag = 1;
end
if updated_params_flag
params = params1;
end
% adding values for auxiliary variables
if length(M.aux_vars) > 0
ys = h_set_auxiliary_variables(ys,exo_ss,M.params);
end
check1 = 0;
if steadystate_check_flag
% Check whether the steady state obtained from the _steadystate file is a steady state.
[residuals,check] = evaluate_static_model(ys,exo_ss,params,M,options);
if check
info(1) = 19;
info(2) = check; % to be improved
return;
end
if max(abs(residuals)) > options.dynatol.f
info(1) = 19;
info(2) = residuals'*residuals;
return
end
elseif ~isempty(options.steadystate_partial)
ssvar = options.steadystate_partial.ssvar;
nov = length(ssvar);
indv = zeros(nov,1);
for i = 1:nov
indv(i) = strmatch(ssvar(i),M.endo_names,'exact');
end
[ys,check] = dynare_solve('restricted_steadystate',...
ys(indv),...
options.jacobian_flag, ...
exo_ss,indv);
end
[ys,params1,check] = evaluate_steady_state_file(ys_init,exo_ss,M,options);
elseif (options.bytecode == 0 && options.block == 0)
if options.linear == 0
% non linear model
......@@ -106,7 +67,7 @@ function [ys,params,info] = evaluate_steady_state(ys_init,M,options,oo,steadysta
% linear model
fh_static = str2func([M.fname '_static']);
[fvec,jacob] = fh_static(ys_init,exo_ss, ...
params);
params);
if max(abs(fvec)) > 1e-12
ys = ys_init-jacob\fvec;
else
......
function [ys,params1,check] = evaluate_steady_state_file(ys_init,exo_ss,params,fname,steadystate_flag)
% function [ys,params1,check] = evaluate_steady_state_file(ys_init,exo_ss,params,steadystate_flag)
function [ys,params,info] = evaluate_steady_state_file(ys_init,exo_ss,M,options)
% function [ys,params1,info] = evaluate_steady_state_file(ys_init,exo_ss,M,options)
% Evaluates steady state files
%
% INPUTS
% ys_init vector initial values used to compute the steady
% state
% exo_ss vector exogenous steady state
% params vector parameters
% steadystate_check_flag boolean if true, check that the
% steadystate verifies the
% static model
% M struct model parameters
% options struct options
%
% OUTPUTS
% ys vector steady state
% params1 vector model parameters possibly
% modified by user steadystate
% function
% check 2x1 vector error codes
% info 2x1 vector error codes
%
% SPECIAL REQUIREMENTS
% none
% Copyright (C) 2001-2011 Dynare Team
% Copyright (C) 2001-2012 Dynare Team
%
% This file is part of Dynare.
%
......@@ -38,17 +36,77 @@ function [ys,params1,check] = evaluate_steady_state_file(ys_init,exo_ss,params,f
% You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
if steadystate_flag == 1
% old format
assignin('base','tmp_00_',params);
evalin('base','M_.params=tmp_00_; clear(''tmp_00_'')');
h_steadystate = str2func([fname '_steadystate']);
[ys,check] = h_steadystate(ys_init, exo_ss);
params1 = evalin('base','M_.params');
ys = [];
params = [];
info = 0;
params = M.params;
fname = M.fname;
if options.steadystate_flag == 1
% old format
assignin('base','tmp_00_',params);
evalin('base','M_.params=tmp_00_; clear(''tmp_00_'')');
h_steadystate = str2func([fname '_steadystate']);
[ys,check] = h_steadystate(ys_init, exo_ss);
params1 = evalin('base','M_.params');
else % steadystate_flag == 2
% new format
h_steadystate = str2func([fname '_steadystate2']);
[ys,params1,check] = h_steadystate(ys_init, exo_ss, params);
end
\ No newline at end of file
if check
info(1) = 19
info(2) = NaN;
end
updated_params_flag = max(abs(params1-params)) > 1e-12;
if isnan(updated_params_flag) || (updated_params_flag && ~isempty(find(isnan(params1))))
info(1) = 24;
info(2) = NaN;
return
end
if updated_params_flag && ~isreal(params1)
info(1) = 23;
info(2) = sum(imag(params).^2);
return
end
if updated_params_flag
params = params1;
end
% adding values for auxiliary variables
if length(M.aux_vars) > 0
ys = h_set_auxiliary_variables(ys,exo_ss,params);
end
check1 = 0;
if ~options.steadystate.nocheck
% Check whether the steady state obtained from the _steadystate file is a steady state.
[residuals,check] = evaluate_static_model(ys,exo_ss,params,M,options);
if check
info(1) = 19;
info(2) = check; % to be improved
return;
end
if max(abs(residuals)) > options.dynatol.f
info(1) = 19;
info(2) = residuals'*residuals;
return
end
elseif ~isempty(options.steadystate_partial)
ssvar = options.steadystate_partial.ssvar;
nov = length(ssvar);
indv = zeros(nov,1);
for i = 1:nov
indv(i) = strmatch(ssvar(i),M.endo_names,'exact');
end
[ys,check] = dynare_solve('restricted_steadystate',...
ys(indv),...
options.jacobian_flag, ...
exo_ss,indv);
end
......@@ -31,6 +31,10 @@ function make_y_
global M_ options_ oo_ ys0_
[oo_.steady_state,M_.params,check] = ...
evaluate_steady_state_file(oo_.steady_state,oo_.exo_steady_state,M_, ...
options_);
if isempty(oo_.steady_state)
oo_.steady_state = zeros(M_.endo_nbr,1);
end
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment