Remove global variables from user-defined steady state files

M_ and options_ are now passed as an input; params is an output as in the _steadystate2.m files
time-shift
Johannes Pfeifer 2019-11-26 17:05:14 +01:00
parent fc6c78e5ea
commit 0c01c31491
4 changed files with 16 additions and 14 deletions

View File

@ -1,19 +1,20 @@
function [ys,check] = NK_baseline_steadystate(ys,exo)
% function [ys,check] = NK_baseline_steadystate(ys,exo)
function [ys,params,check] = NK_baseline_steadystate(ys,exo,M_,options_)
% function [ys,params,check] = NK_baseline_steadystate(ys,exo,M_,options_)
% computes the steady state for the NK_baseline.mod and uses a numerical
% solver to do so
% Inputs:
% - ys [vector] vector of initial values for the steady state of
% the endogenous variables
% - exo [vector] vector of values for the exogenous variables
% - M_ [structure] Dynare model structure
% - options [structure] Dynare options structure
%
% Output:
% - ys [vector] vector of steady state values for the the endogenous variables
% - params [vector] vector of parameter values
% - check [scalar] set to 0 if steady state computation worked and to
% 1 of not (allows to impose restrictions on parameters)
global M_
% read out parameters to access them with their name
NumberOfParameters = M_.param_nbr;
for ii = 1:NumberOfParameters
@ -95,8 +96,9 @@ g2=epsilon/(epsilon-1)*g1;
%% end own model equations
params=NaN(NumberOfParameters,1);
for iter = 1:length(M_.params) %update parameters set in the file
eval([ 'M_.params(' num2str(iter) ') = ' M_.param_names{iter} ';' ])
eval([ 'params(' num2str(iter) ') = ' M_.param_names{iter} ';' ])
end
NumberOfEndogenousVariables = M_.orig_endo_nbr; %auxiliary variables are set automatically

View File

@ -46,8 +46,7 @@ if options.steadystate_flag == 1
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,params1,check] = h_steadystate(ys_init, exo_ss,M,options);
else % steadystate_flag == 2
% new format
h_steadystate = str2func([fname '.steadystate']);

View File

@ -1,12 +1,13 @@
function [ys_, check_] = expectation_ss_old_steadystate(ys_orig_, exo_)
function [ys_, params, check_] = expectation_ss_old_steadystate(ys_orig_, exo_,M_,options_)
ys_=zeros(6,1);
global M_
params=NaN(size(M_.params));
params=M_.params;
ys_(4)=0;
ys_(6)=0;
ys_(5)=0.3333333333333333;
ys_(3)=((1/M_.params(1)-(1-M_.params(4)))/(M_.params(3)*ys_(5)^(1-M_.params(3))))^(1/(M_.params(3)-1));
ys_(1)=ys_(5)^(1-M_.params(3))*ys_(3)^M_.params(3);
ys_(2)=ys_(1)-M_.params(4)*ys_(3);
M_.params(5)=(1-M_.params(3))*ys_(1)/(ys_(2)*ys_(5)^(1+M_.params(6)));
params(5)=(1-M_.params(3))*ys_(1)/(ys_(2)*ys_(5)^(1+M_.params(6)));
check_=0;
end

View File

@ -1,5 +1,4 @@
function [ys,check] = walsh1_old_ss_steadystate(ys,exo)
global M_
function [ys,params,check] = walsh1_old_ss_steadystate(ys,exo,M_,options_)
% read out parameters to access them with their name
NumberOfParameters = M_.param_nbr;
@ -34,8 +33,9 @@ check = 0;
%% end own model equations
for iter = 1:length(M_.params) %update parameters set in the file
eval([ 'M_.params(' num2str(iter) ') = ' M_.param_names{iter} ';' ])
params=NaN(NumberOfParameters,1);
for iter = 1:NumberOfParameters %update parameters set in the file
eval([ 'params(' num2str(iter) ') = ' M_.param_names{iter} ';' ])
end
NumberOfEndogenousVariables = M_.orig_endo_nbr; %auxiliary variables are set automatically