NK_baseline_steadystate.m: provide proper error handling
parent
c033a08cec
commit
ab6b642596
|
@ -2,14 +2,14 @@ function [ys,params,check] = NK_baseline_steadystate(ys,exo,M_,options_)
|
||||||
% 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
|
% computes the steady state for the NK_baseline.mod and uses a numerical
|
||||||
% solver to do so
|
% solver to do so
|
||||||
% Inputs:
|
% Inputs:
|
||||||
% - ys [vector] vector of initial values for the steady state of
|
% - ys [vector] vector of initial values for the steady state of
|
||||||
% the endogenous variables
|
% the endogenous variables
|
||||||
% - exo [vector] vector of values for the exogenous variables
|
% - exo [vector] vector of values for the exogenous variables
|
||||||
% - M_ [structure] Dynare model structure
|
% - M_ [structure] Dynare model structure
|
||||||
% - options [structure] Dynare options structure
|
% - options [structure] Dynare options structure
|
||||||
%
|
%
|
||||||
% Output:
|
% Output:
|
||||||
% - ys [vector] vector of steady state values for the the endogenous variables
|
% - ys [vector] vector of steady state values for the the endogenous variables
|
||||||
% - params [vector] vector of parameter values
|
% - params [vector] vector of parameter values
|
||||||
% - check [scalar] set to 0 if steady state computation worked and to
|
% - check [scalar] set to 0 if steady state computation worked and to
|
||||||
|
@ -35,8 +35,8 @@ function [ys,params,check] = NK_baseline_steadystate(ys,exo,M_,options_)
|
||||||
% read out parameters to access them with their name
|
% read out parameters to access them with their name
|
||||||
NumberOfParameters = M_.param_nbr;
|
NumberOfParameters = M_.param_nbr;
|
||||||
for ii = 1:NumberOfParameters
|
for ii = 1:NumberOfParameters
|
||||||
paramname = M_.param_names{ii};
|
paramname = M_.param_names{ii};
|
||||||
eval([ paramname ' = M_.params(' int2str(ii) ');']);
|
eval([ paramname ' = M_.params(' int2str(ii) ');']);
|
||||||
end
|
end
|
||||||
% initialize indicator
|
% initialize indicator
|
||||||
check = 0;
|
check = 0;
|
||||||
|
@ -65,6 +65,7 @@ Lambdax=mu_z;
|
||||||
%set the parameter gammma1
|
%set the parameter gammma1
|
||||||
gammma1=mu_z*mu_I/betta-(1-delta);
|
gammma1=mu_z*mu_I/betta-(1-delta);
|
||||||
if gammma1<0 % parameter violates restriction; Preventing this cannot be implemented via prior restriction as it is a composite of different parameters and the valid prior region has unknown form
|
if gammma1<0 % parameter violates restriction; Preventing this cannot be implemented via prior restriction as it is a composite of different parameters and the valid prior region has unknown form
|
||||||
|
params=M_.params;
|
||||||
check=1; %set failure indicator
|
check=1; %set failure indicator
|
||||||
return; %return without updating steady states
|
return; %return without updating steady states
|
||||||
end
|
end
|
||||||
|
@ -86,13 +87,20 @@ vp=(1-thetap)/(1-thetap*PI^((1-chi)*epsilon))*PIstar^(-epsilon);
|
||||||
vw=(1-thetaw)/(1-thetaw*PI^((1-chiw)*eta)*mu_z^eta)*PIstarw^(-eta);
|
vw=(1-thetaw)/(1-thetaw*PI^((1-chiw)*eta)*mu_z^eta)*PIstarw^(-eta);
|
||||||
tempvaromega=alppha/(1-alppha)*w/r*mu_z*mu_I;
|
tempvaromega=alppha/(1-alppha)*w/r*mu_z*mu_I;
|
||||||
|
|
||||||
[ld,fval,exitflag]=fzero(@(ld)(1-betta*thetaw*mu_z^(eta-1)*PI^(-(1-chiw)*(1-eta)))/(1-betta*thetaw*mu_z^(eta*(1+gammma))*PI^(eta*(1-chiw)*(1+gammma)))...
|
try
|
||||||
-(eta-1)/eta*wstar/(varpsi*PIstarw^(-eta*gammma)*ld^gammma)*((1-h*mu_z^(-1))^(-1)-betta*h*(mu_z-h)^(-1))*...
|
%proper error handling for cases for infeasible initial value, which would result in error instead of valid exitflag
|
||||||
((mu_A*mu_z^(-1)*vp^(-1)*tempvaromega^alppha-tempvaromega*(1-(1-delta)*(mu_z*mu_I)^(-1)))*ld-vp^(-1)*Phi)^(-1),0.25,options);
|
[ld,fval,exitflag]=fzero(@(ld)(1-betta*thetaw*mu_z^(eta-1)*PI^(-(1-chiw)*(1-eta)))/(1-betta*thetaw*mu_z^(eta*(1+gammma))*PI^(eta*(1-chiw)*(1+gammma)))...
|
||||||
|
-(eta-1)/eta*wstar/(varpsi*PIstarw^(-eta*gammma)*ld^gammma)*((1-h*mu_z^(-1))^(-1)-betta*h*(mu_z-h)^(-1))*...
|
||||||
|
((mu_A*mu_z^(-1)*vp^(-1)*tempvaromega^alppha-tempvaromega*(1-(1-delta)*(mu_z*mu_I)^(-1)))*ld-vp^(-1)*Phi)^(-1),0.25,options);
|
||||||
|
catch
|
||||||
|
exitflag = 0;
|
||||||
|
end
|
||||||
|
|
||||||
if exitflag <1
|
if exitflag <1
|
||||||
%indicate the SS computation was not sucessful; this would also be detected by Dynare
|
%indicate the SS computation was not sucessful; this would also be detected by Dynare
|
||||||
%setting the indicator here shows how to use this functionality to
|
%setting the indicator here shows how to use this functionality to
|
||||||
%filter out parameter draws
|
%filter out parameter draws
|
||||||
|
params=M_.params;
|
||||||
check=1; %set failure indicator
|
check=1; %set failure indicator
|
||||||
return; %return without updating steady states
|
return; %return without updating steady states
|
||||||
end
|
end
|
||||||
|
@ -115,11 +123,11 @@ g2=epsilon/(epsilon-1)*g1;
|
||||||
|
|
||||||
params=NaN(NumberOfParameters,1);
|
params=NaN(NumberOfParameters,1);
|
||||||
for iter = 1:length(M_.params) %update parameters set in the file
|
for iter = 1:length(M_.params) %update parameters set in the file
|
||||||
eval([ 'params(' num2str(iter) ') = ' M_.param_names{iter} ';' ])
|
eval([ 'params(' num2str(iter) ') = ' M_.param_names{iter} ';' ])
|
||||||
end
|
end
|
||||||
|
|
||||||
NumberOfEndogenousVariables = M_.orig_endo_nbr; %auxiliary variables are set automatically
|
NumberOfEndogenousVariables = M_.orig_endo_nbr; %auxiliary variables are set automatically
|
||||||
for ii = 1:NumberOfEndogenousVariables
|
for ii = 1:NumberOfEndogenousVariables
|
||||||
varname = M_.endo_names{ii};
|
varname = M_.endo_names{ii};
|
||||||
eval(['ys(' int2str(ii) ') = ' varname ';']);
|
eval(['ys(' int2str(ii) ') = ' varname ';']);
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue