Home > matlab > dyn_ramsey_static.m

dyn_ramsey_static

PURPOSE ^

function [steady_state,params,check] = dyn_ramsey_static_(x)

SYNOPSIS ^

function [steady_state,params,check] = dyn_ramsey_static(x,M,options_,oo)

DESCRIPTION ^

 function  [steady_state,params,check] = dyn_ramsey_static_(x)
 Computes the static first order conditions for optimal policy

 INPUTS
    x:         vector of endogenous variables or instruments

 OUTPUTS
    resids:    residuals of non linear equations
    rJ:        Jacobian
    mult:      Lagrangian multipliers

 SPECIAL REQUIREMENTS
    none

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function [steady_state,params,check] = dyn_ramsey_static(x,M,options_,oo)
0002 
0003 % function  [steady_state,params,check] = dyn_ramsey_static_(x)
0004 % Computes the static first order conditions for optimal policy
0005 %
0006 % INPUTS
0007 %    x:         vector of endogenous variables or instruments
0008 %
0009 % OUTPUTS
0010 %    resids:    residuals of non linear equations
0011 %    rJ:        Jacobian
0012 %    mult:      Lagrangian multipliers
0013 %
0014 % SPECIAL REQUIREMENTS
0015 %    none
0016 
0017 % Copyright (C) 2003-2010 Dynare Team
0018 %
0019 % This file is part of Dynare.
0020 %
0021 % Dynare is free software: you can redistribute it and/or modify
0022 % it under the terms of the GNU General Public License as published by
0023 % the Free Software Foundation, either version 3 of the License, or
0024 % (at your option) any later version.
0025 %
0026 % Dynare is distributed in the hope that it will be useful,
0027 % but WITHOUT ANY WARRANTY; without even the implied warranty of
0028 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0029 % GNU General Public License for more details.
0030 %
0031 % You should have received a copy of the GNU General Public License
0032 % along with Dynare.  If not, see <http://www.gnu.org/licenses/>.
0033 
0034 
0035 steady_state = [];
0036 params = M.params;
0037 check = 0;
0038 options_.steadystate.nocheck = 1;
0039 nl_func = @(x) dyn_ramsey_static_1(x,M,options_,oo);
0040 
0041 if options_.steadystate_flag
0042     k_inst = [];
0043     instruments = options_.instruments;
0044     inst_nbr = size(options_.instruments,1);
0045     for i = 1:inst_nbr
0046         k_inst = [k_inst; strmatch(options_.instruments(i,:), ...
0047                                    M.endo_names,'exact')];
0048     end
0049     ys = oo.steady_state;
0050     if inst_nbr == 1
0051         inst_val = csolve(nl_func,oo.steady_state(k_inst),'',options_.solve_tolf,100);
0052     else
0053         [inst_val,info1] = dynare_solve(nl_func,ys(k_inst),0);
0054     end
0055     ys(k_inst) = inst_val;
0056     exo_ss = [oo.exo_steady_state oo.exo_det_steady_state];
0057     [xx,params,check] = evaluate_steady_state_file(ys,exo_ss,M,options_);
0058     [junk,jun,steady_state] = nl_func(inst_val);
0059 else
0060     n_var = M.orig_endo_nbr;
0061     xx = oo.steady_state(1:n_var);
0062     [xx,info1] = dynare_solve(nl_func,xx,0);
0063     [junk,junk,steady_state] = nl_func(xx);
0064 end
0065 
0066 
0067 
0068 function [resids,rJ,steady_state] = dyn_ramsey_static_1(x,M,options_,oo)
0069 resids = [];
0070 rJ = [];
0071 mult = [];
0072 
0073 % recovering usefull fields
0074 params = M.params;
0075 endo_nbr = M.endo_nbr;
0076 endo_names = M.endo_names;
0077 exo_nbr = M.exo_nbr;
0078 orig_endo_nbr = M.orig_endo_nbr;
0079 aux_vars_type = [M.aux_vars.type];
0080 orig_endo_aux_nbr = orig_endo_nbr + min(find(aux_vars_type == 6)) - 1; 
0081 orig_eq_nbr = M.orig_eq_nbr;
0082 inst_nbr = orig_endo_aux_nbr - orig_eq_nbr;
0083 % indices of Lagrange multipliers
0084 i_mult = [orig_endo_aux_nbr+(1:orig_eq_nbr)]';
0085 fname = M.fname;
0086 max_lead = M.maximum_lead;
0087 max_lag = M.maximum_lag;
0088 
0089 % indices of all endogenous variables
0090 i_endo = [1:endo_nbr]';
0091 % indices of endogenous variable except instruments
0092 % i_inst = M.instruments;
0093 % lead_lag incidence matrix
0094 i_lag = M.lead_lag_incidence;
0095 
0096 if options_.steadystate_flag
0097     k_inst = [];
0098     instruments = options_.instruments;
0099     for i = 1:size(instruments,1)
0100         k_inst = [k_inst; strmatch(instruments(i,:), ...
0101                                    endo_names,'exact')];
0102     end
0103     oo.steady_state(k_inst) = x;
0104     [x,params,check] = evaluate_steady_state_file(oo.steady_state,...
0105                                                   [oo.exo_steady_state; ...
0106                                                   oo.exo_det_steady_state], ...
0107                                                   M,options_);
0108 end
0109 
0110 xx = zeros(endo_nbr,1);
0111 xx(1:length(x)) = x;
0112 % setting steady state of auxiliary variables
0113 % that depends on original endogenous variables
0114 if any([M.aux_vars.type] ~= 6)
0115     needs_set_auxiliary_variables = 1;
0116     fh = str2func([M.fname '_set_auxiliary_variables']);
0117     s_a_v_func = @(z) fh(z,... 
0118                          [oo.exo_steady_state,...
0119                         oo.exo_det_steady_state],...
0120                          params);
0121     xx = s_a_v_func(xx);
0122 else
0123     needs_set_auxiliary_variables = 0;
0124 end
0125 
0126 % value and Jacobian of objective function
0127 ex = zeros(1,M.exo_nbr);
0128 [U,Uy,Uyy] = feval([fname '_objective_static'],x,ex, params);
0129 Uy = Uy';
0130 Uyy = reshape(Uyy,endo_nbr,endo_nbr);
0131 
0132 % set multipliers and auxiliary variables that
0133 % depends on multipliers to 0 to compute residuals
0134 [res,fJ] = feval([fname '_static'],xx,[oo.exo_simul oo.exo_det_simul], ...
0135                M.params);
0136 
0137 % index of multipliers and corresponding equations
0138 % the auxiliary variables before the Lagrange multipliers are treated
0139 % as ordinary endogenous variables
0140 aux_eq = [1:orig_endo_aux_nbr, orig_endo_aux_nbr+orig_eq_nbr+1:size(fJ,1)];
0141 A = fJ(aux_eq,orig_endo_aux_nbr+1:end);
0142 y = res(aux_eq);
0143 aux_vars = -A\y;
0144 
0145 resids1 = y+A*aux_vars;
0146 if inst_nbr == 1
0147     r1 = sqrt(resids1'*resids1);
0148 else
0149     [q,r,e] = qr([A y]');
0150     k = size(A,1)+(1-inst_nbr:0);
0151     r1 = r(end,k)';
0152 end
0153 if options_.steadystate_flag
0154     resids = r1;
0155 else
0156     resids = [res(orig_endo_nbr+(1:orig_endo_nbr-inst_nbr)); r1];
0157 end
0158 rJ = [];
0159 steady_state = [xx(1:orig_endo_aux_nbr); aux_vars];

Generated on Mon 21-May-2012 02:42:43 by m2html © 2005