From ce5c510d06c404ef6a228e0e51f7b1269ed90bba Mon Sep 17 00:00:00 2001 From: michel Date: Tue, 6 Oct 2009 14:37:23 +0000 Subject: [PATCH] v4.1: add provision for _steady_state.m and auxiliary variables for leads on more than 1 period git-svn-id: https://www.dynare.org/svn/dynare/trunk@3022 ac1d8469-bf42-47a9-8791-bf33cf982152 --- .../add_auxiliary_variables_to_steadystate.m | 24 ++++++++++++++++--- matlab/dynare_estimation_1.m | 18 ++++++++++---- matlab/initial_estimation_checks.m | 6 ++++- matlab/model_diagnostics.m | 5 +++- matlab/osr1.m | 5 +++- matlab/resol.m | 6 ++++- matlab/steady_.m | 6 ++++- 7 files changed, 57 insertions(+), 13 deletions(-) diff --git a/matlab/add_auxiliary_variables_to_steadystate.m b/matlab/add_auxiliary_variables_to_steadystate.m index 387275500..c92e15eba 100644 --- a/matlab/add_auxiliary_variables_to_steadystate.m +++ b/matlab/add_auxiliary_variables_to_steadystate.m @@ -1,9 +1,27 @@ -function ys1 = add_auxiliary_variables_to_steadystate(ys,aux_vars) +function ys1 = add_auxiliary_variables_to_steadystate(ys,aux_vars,fname, ... + exo_steady_state, exo_det_steady_state,params) n = length(aux_vars); ys1 = [ys;zeros(n,1)]; k = size(ys,1)+1; + aux_lead_nbr = 0; for i=1:n - ys1(k) = ys(aux_vars(i).orig_endo_index); + if aux_vars(i).type == 1 + ys1(k) = ys(aux_vars(i).orig_endo_index); + elseif aux_vars(i).type == 0 + aux_lead_nbr = aux_lead_nbr + 1; + end k = k+1; end - \ No newline at end of file + + for i=1:aux_lead_nbr + 1; + res = feval([fname '_static'],ys1,... + [exo_steady_state; ... + exo_det_steady_state],params); + for j=1:n + if aux_vars(j).type == 0 + el = aux_vars(j).endo_index; + ys1(el) == res(el); + end + end + end + \ No newline at end of file diff --git a/matlab/dynare_estimation_1.m b/matlab/dynare_estimation_1.m index 2ba629ff3..ebb8f4154 100644 --- a/matlab/dynare_estimation_1.m +++ b/matlab/dynare_estimation_1.m @@ -281,10 +281,16 @@ if ~isempty(estim_params_) set_parameters(xparam1); end if options_.steadystate_flag% if the *_steadystate.m file is provided. - [ys,tchek] = feval([M_.fname '_steadystate'],[],[]); + [ys,tchek] = feval([M_.fname '_steadystate'],... + [zeros(M_.exo_nbr,1);... + oo_.exo_det_steady_state]); if size(ys,1) < M_.endo_nbr if isfield(M_,'aux_vars') - ys = add_auxiliary_variables_to_steadystate(ys,M_.aux_vars); + ys = add_auxiliary_variables_to_steadystate(ys,M_.aux_vars,... + M_.fname,... + zeros(M_.exo_nbr,1),... + oo_.exo_det_steady_state,... + M_.params); else error([M_.fname '_steadystate.m doesn''t match the model']); end @@ -521,14 +527,15 @@ if options_.mode_compute > 0 & options_.posterior_mode_estimation else [xparam1,fval,exitflag] = fminsearch(fh,xparam1,optim_options,gend); end - case 101 + + case 101 myoptions=soptions; myoptions(2)=1e-6; %accuracy of argument myoptions(3)=1e-6; %accuracy of function (see Solvopt p.29) myoptions(5)= 1.0; [xparam1,fval]=solvopt(xparam1,fh,[],myoptions,gend,data); - case 102 + case 102 %simulating annealing % LB=zeros(size(xparam1))-20; % UB=zeros(size(xparam1))+20; @@ -572,7 +579,8 @@ if options_.mode_compute > 0 & options_.posterior_mode_estimation ,neps,maxevl,LB,UB,c,idisp ,t,vm,gend); end otherwise - error(['ESTIMATION: mode_compute=' int2str(options_.mode_compute) ' option is unknown!']) + error(['ESTIMATION: mode_compute=' int2str(options_.mode_compute) ... + ' option is unknown!']) end if options_.mode_compute ~= 5 if options_.mode_compute ~= 6 diff --git a/matlab/initial_estimation_checks.m b/matlab/initial_estimation_checks.m index 6e4ed82dd..88db173cc 100644 --- a/matlab/initial_estimation_checks.m +++ b/matlab/initial_estimation_checks.m @@ -70,7 +70,11 @@ function initial_estimation_checks(xparam1,gend,data,data_index,number_of_observ oo_.exo_det_steady_state]); if size(ys,1) < M_.endo_nbr if isfield(M_,'aux_vars') - ys = add_auxiliary_variables_to_steadystate(ys,M_.aux_vars); + ys = add_auxiliary_variables_to_steadystate(ys,M_.aux_vars,... + M_.fname,... + oo_.exo_steady_state,... + oo_.exo_det_steady_state,... + M_.params); else error([M_.fname '_steadystate.m doesn''t match the model']); end diff --git a/matlab/model_diagnostics.m b/matlab/model_diagnostics.m index 0b239c134..acdb9e563 100644 --- a/matlab/model_diagnostics.m +++ b/matlab/model_diagnostics.m @@ -80,7 +80,10 @@ function model_diagnostics(M_,options_,oo_) [oo_.exo_steady_state; oo_.exo_det_steady_state]); if size(ys,1) < M_.endo_nbr if isfield(M_,'aux_vars') - ys = add_auxiliary_variables_to_steadystate(ys,M_.aux_vars); + ys = add_auxiliary_variables_to_steadystate(ys,M_.aux_vars,... + M_.fname,... + oo_.exo_steady_state,... + oo_.exo_det_steady_state); else error([M_.fname '_steadystate.m doesn''t match the model']); end diff --git a/matlab/osr1.m b/matlab/osr1.m index 261e496ba..030559725 100644 --- a/matlab/osr1.m +++ b/matlab/osr1.m @@ -48,7 +48,10 @@ function osr1(i_params,i_var,weights) [oo_.exo_steady_state; oo_.exo_det_steady_state]); if size(ys,1) < M_.endo_nbr if isfield(M_,'aux_vars') - ys = add_auxiliary_variables_to_steadystate(ys,M_.aux_vars); + ys = add_auxiliary_variables_to_steadystate(ys,M_.aux_vars,... + M_.fname,... + oo_.exo_steady_state,... + oo_.exo_det_steady_state); else error([M_.fname '_steadystate.m doesn''t match the model']); end diff --git a/matlab/resol.m b/matlab/resol.m index 43ab234ea..65c979644 100644 --- a/matlab/resol.m +++ b/matlab/resol.m @@ -73,7 +73,11 @@ if options_.steadystate_flag oo_.exo_det_steady_state]); if size(dr.ys,1) < M_.endo_nbr if isfield(M_,'aux_vars') - dr.ys = add_auxiliary_variables_to_steadystate(dr.ys,M_.aux_vars); + dr.ys = add_auxiliary_variables_to_steadystate(dr.ys,M_.aux_vars,... + M_.fname,... + oo_.exo_steady_state,... + oo_.exo_det_steady_state,... + M_.params); else error([M_.fname '_steadystate.m doesn''t match the model']); end diff --git a/matlab/steady_.m b/matlab/steady_.m index 32978fad4..a528a6550 100644 --- a/matlab/steady_.m +++ b/matlab/steady_.m @@ -43,7 +43,11 @@ function steady_() oo_.exo_det_steady_state]); if size(ys,1) < M_.endo_nbr if isfield(M_,'aux_vars') - ys = add_auxiliary_variables_to_steadystate(ys,M_.aux_vars); + ys = add_auxiliary_variables_to_steadystate(ys,M_.aux_vars,... + M_.fname,... + oo_.exo_steady_state,... + oo_.exo_det_steady_state,... + M_.params); else error([M_.fname '_steadystate.m doesn''t match the model']); end