diff --git a/matlab/dr1.m b/matlab/dr1.m index 82c22690c7be928dbdaf72b02578787d689fad4a..0be5b97c697db7d2a100617b473b0caf329185d6 100644 --- a/matlab/dr1.m +++ b/matlab/dr1.m @@ -83,11 +83,49 @@ function [dr,info,M_,options_,oo_] = dr1(dr,task,M_,options_,oo_) M_.maximum_lag = orig_model.maximum_lag; M_.maximum_endo_lag = orig_model.maximum_endo_lag; end - old_solve_algo = options_.solve_algo; - % options_.solve_algo = 1; - oo_.steady_state = dynare_solve('dyn_ramsey_static_',oo_.steady_state,0,M_,options_,oo_,it_); - options_.solve_algo = old_solve_algo; - [junk,junk,multbar] = dyn_ramsey_static_(oo_.steady_state,M_,options_,oo_,it_); + + if options_.steadystate_flag + k_inst = []; + instruments = options_.instruments; + for i = 1:size(instruments,1) + k_inst = [k_inst; strmatch(options_.instruments(i,:), ... + M_.endo_names,'exact')]; + end + ys = oo_.steady_state; + inst_val = dynare_solve('dyn_ramsey_static_', ... + oo_.steady_state(k_inst),0, ... + M_,options_,oo_,it_); + ys(k_inst) = inst_val; + [x,check] = feval([M_.fname '_steadystate'],... + ys,[oo_.exo_steady_state; ... + oo_.exo_det_steady_state]); + if size(x,1) < M_.endo_nbr + if length(M_.aux_vars) > 0 + x = add_auxiliary_variables_to_steadystate(x,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 + end + oo_.steady_state = x; + [junk,junk,multbar] = dyn_ramsey_static_(oo_.steady_state(k_inst),M_,options_,oo_,it_); + else + oo_.steady_state = dynare_solve('dyn_ramsey_static_', ... + oo_.steady_state,0,M_,options_,oo_,it_); + [junk,junk,multbar] = dyn_ramsey_static_(oo_.steady_state,M_,options_,oo_,it_); + end + check1 = max(abs(feval([M_.fname '_static'],... + oo_.steady_state,... + [oo_.exo_steady_state; ... + oo_.exo_det_steady_state], M_.params))) > options_.dynatol ; + if check1 + error(['The steadystate values returned by ' M_.fname ... + '_steadystate.m don''t solve the static model!' ]) + end + [jacobia_,M_] = dyn_ramsey_dynamic_(oo_.steady_state,multbar,M_,options_,oo_,it_); klen = M_.maximum_lag + M_.maximum_lead + 1; dr.ys = [oo_.steady_state;zeros(M_.exo_nbr,1);multbar]; diff --git a/matlab/dyn_ramsey_static_.m b/matlab/dyn_ramsey_static_.m index 9362eeaec1dc8473838259f5a85757794aab9580..0bff491eaee42361fea21d2835e6d88f6d291591 100644 --- a/matlab/dyn_ramsey_static_.m +++ b/matlab/dyn_ramsey_static_.m @@ -49,14 +49,39 @@ function [resids, rJ,mult] = dyn_ramsey_static_(x,M_,options_,oo_,it_) % lead_lag incidence matrix for endogenous variables i_lag = M_.lead_lag_incidence; + if options_.steadystate_flag + k_inst = []; + instruments = options_.instruments; + for i = 1:size(instruments,1) + k_inst = [k_inst; strmatch(options_.instruments(i,:), ... + M_.endo_names,'exact')]; + end + oo_.steady_state(k_inst) = x; + [x,check] = feval([M_.fname '_steadystate'],... + oo_.steady_state,... + [oo_.exo_steady_state; ... + oo_.exo_det_steady_state]); + if size(x,1) < M_.endo_nbr + if length(M_.aux_vars) > 0 + x = add_auxiliary_variables_to_steadystate(x,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 + end + end + % value and Jacobian of objective function ex = zeros(1,M_.exo_nbr); [U,Uy,Uyy] = feval([fname '_objective_static'],x(i_endo),ex, M_.params); Uy = Uy'; Uyy = reshape(Uyy,endo_nbr,endo_nbr); - % value and Jacobian of dynamic function y = repmat(x(i_endo),1,max_lag+max_lead+1); + % value and Jacobian of dynamic function k = find(i_lag'); it_ = 1; % [f,fJ,fH] = feval([fname '_dynamic'],y(k),ex); @@ -83,7 +108,11 @@ function [resids, rJ,mult] = dyn_ramsey_static_(x,M_,options_,oo_,it_) resids1 = Uy+A*mult; % resids = [f; sqrt(resids1'*resids1/endo_nbr)]; [q,r,e] = qr([A Uy]'); - resids = [f; r(end,(endo_nbr-inst_nbr+1:end))']; + if options_.steadystate_flag + resids = [r(end,(endo_nbr-inst_nbr+1:end))']; + else + resids = [f; r(end,(endo_nbr-inst_nbr+1:end))']; + end rJ = []; return; diff --git a/preprocessor/DynareBison.yy b/preprocessor/DynareBison.yy index 4e426691f61f021cdf23b18abe5fd934ef83ce33..912cd898c06a2c43370e4bfb955f4644643e7a87 100644 --- a/preprocessor/DynareBison.yy +++ b/preprocessor/DynareBison.yy @@ -97,7 +97,7 @@ class ParsingDriver; %token END ENDVAL EQUAL ESTIMATION ESTIMATED_PARAMS ESTIMATED_PARAMS_BOUNDS ESTIMATED_PARAMS_INIT %token FILENAME FILTER_STEP_AHEAD FILTERED_VARS FIRST_OBS %token <string_val> FLOAT_NUMBER -%token FORECAST K_ORDER_SOLVER +%token FORECAST K_ORDER_SOLVER INSTRUMENTS %token GAMMA_PDF GRAPH CONDITIONAL_VARIANCE_DECOMPOSITION %token HISTVAL HOMOTOPY_SETUP HOMOTOPY_MODE HOMOTOPY_STEPS HP_FILTER HP_NGRID %token IDENTIFICATION INF_CONSTANT INITVAL INITVAL_FILE @@ -1293,6 +1293,7 @@ ramsey_policy_options_list : ramsey_policy_options_list COMMA ramsey_policy_opti ramsey_policy_options : stoch_simul_options | o_planner_discount + | o_instruments ; write_latex_dynamic_model : WRITE_LATEX_DYNAMIC_MODEL ';' @@ -1875,6 +1876,7 @@ o_equations : EQUATIONS EQUAL vec_int | EQUATIONS EQUAL INT_NUMBER { driver.option_num("ms.equations",$3); } ; +o_instruments : INSTRUMENTS EQUAL '(' symbol_list ')' {driver.option_symbol_list("instruments"); }; range : symbol ':' symbol { diff --git a/preprocessor/DynareFlex.ll b/preprocessor/DynareFlex.ll index d22450726505e68b4c4ec0d6e2db2f14498d3c3f..ea329b9f5a8ca1d99ce56feaa14bd9cd5d397836 100644 --- a/preprocessor/DynareFlex.ll +++ b/preprocessor/DynareFlex.ll @@ -315,7 +315,7 @@ int sigma_e = 0; <DYNARE_STATEMENT>draws_nbr_mean_var_estimate {return token::DRAWS_NBR_MEAN_VAR_ESTIMATE;} <DYNARE_STATEMENT>draws_nbr_modified_harmonic_mean {return token::DRAWS_NBR_MODIFIED_HARMONIC_MEAN;} <DYNARE_STATEMENT>dirichlet_scale {return token::DIRICHLET_SCALE;} - +<DYNARE_STATEMENT>instruments {return token::INSTRUMENTS;} /* These four (var, varexo, varexo_det, parameters) are for change_type */ <DYNARE_STATEMENT>var { return token::VAR; }