2014-10-30 11:45:08 +01:00
function [steady_state,params,check] = dyn_ramsey_static ( ys_init,M,options_,oo)
2009-12-16 18:17:34 +01:00
2011-10-12 21:46:50 +02:00
% function [steady_state,params,check] = dyn_ramsey_static_(x)
2009-12-16 18:17:34 +01:00
% Computes the static first order conditions for optimal policy
%
% INPUTS
2011-10-12 21:46:50 +02:00
% x: vector of endogenous variables or instruments
2009-12-16 18:17:34 +01:00
%
% OUTPUTS
% resids: residuals of non linear equations
% rJ: Jacobian
% mult: Lagrangian multipliers
%
% SPECIAL REQUIREMENTS
% none
2015-02-16 09:08:02 +01:00
% Copyright (C) 2003-2015 Dynare Team
2009-12-16 18:17:34 +01:00
%
% This file is part of Dynare.
%
% Dynare is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% Dynare is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
2011-10-12 21:46:50 +02:00
params = M . params ;
check = 0 ;
2014-07-18 12:35:52 +02:00
options_ . steadystate . nocheck = 1 ; %disable checking because Lagrange multipliers are not accounted for in evaluate_steady_state_file
2014-03-11 13:22:04 +01:00
% dyn_ramsey_static_1 is a subfunction
2011-10-12 21:46:50 +02:00
nl_func = @ ( x ) dyn_ramsey_static_1 ( x , M , options_ , oo ) ;
2014-03-11 13:22:04 +01:00
% check_static_model is a subfunction
2014-10-30 11:45:08 +01:00
if check_static_model ( ys_init , M , options_ , oo ) && ~ options_ . steadystate_flag
steady_state = ys_init ;
2014-03-11 13:22:04 +01:00
return
elseif options_ . steadystate_flag
2011-10-12 21:46:50 +02:00
k_inst = [ ] ;
2012-04-21 21:16:57 +02:00
inst_nbr = size ( options_ . instruments , 1 ) ;
2011-10-12 21:46:50 +02:00
for i = 1 : inst_nbr
k_inst = [ k_inst ; strmatch ( options_ . instruments ( i , : ) , ...
M . endo_names , ' exact' ) ] ;
end
if inst_nbr == 1
2014-10-30 11:45:08 +01:00
inst_val = csolve ( nl_func , ys_init ( k_inst ) , ' ' , options_ . solve_tolf , 100 ) ; %solve for instrument, using univariate solver, starting at initial value for instrument
2011-10-12 21:46:50 +02:00
else
2014-10-30 11:45:08 +01:00
[ inst_val , info1 ] = dynare_solve ( nl_func , ys_init ( k_inst ) , 0 ) ; %solve for instrument, using multivariate solver, starting at initial value for instrument
2011-10-12 21:46:50 +02:00
end
2014-10-30 11:45:08 +01:00
ys_init ( k_inst ) = inst_val ;
2011-11-14 21:58:53 +01:00
exo_ss = [ oo . exo_steady_state oo . exo_det_steady_state ] ;
2014-10-30 11:45:08 +01:00
[ xx , params , check ] = evaluate_steady_state_file ( ys_init , exo_ss , M , options_ ) ; %run steady state file again to update parameters
[ junk , junk , steady_state ] = nl_func ( inst_val ) ; %compute and return steady state
2011-10-12 21:46:50 +02:00
else
2012-02-02 12:04:15 +01:00
n_var = M . orig_endo_nbr ;
2011-12-14 21:04:51 +01:00
xx = oo . steady_state ( 1 : n_var ) ;
2014-07-18 08:53:51 +02:00
[ xx , check ] = dynare_solve ( nl_func , xx , 0 ) ;
2012-04-21 21:16:57 +02:00
[ junk , junk , steady_state ] = nl_func ( xx ) ;
2011-10-12 21:46:50 +02:00
end
2011-12-14 21:04:51 +01:00
function [resids,rJ,steady_state] = dyn_ramsey_static_1 ( x,M,options_,oo)
2011-10-12 21:46:50 +02:00
resids = [ ] ;
rJ = [ ] ;
mult = [ ] ;
2009-12-16 18:17:34 +01:00
% recovering usefull fields
2012-02-02 12:04:15 +01:00
params = M . params ;
2010-05-29 07:48:00 +02:00
endo_nbr = M . endo_nbr ;
2012-02-02 12:04:15 +01:00
endo_names = M . endo_names ;
2011-10-12 21:46:50 +02:00
orig_endo_nbr = M . orig_endo_nbr ;
2012-02-02 12:04:15 +01:00
aux_vars_type = [ M . aux_vars . type ] ;
orig_endo_aux_nbr = orig_endo_nbr + min ( find ( aux_vars_type == 6 ) ) - 1 ;
2011-10-12 21:46:50 +02:00
orig_eq_nbr = M . orig_eq_nbr ;
2012-02-02 12:04:15 +01:00
inst_nbr = orig_endo_aux_nbr - orig_eq_nbr ;
2011-03-27 16:54:49 +02:00
% indices of Lagrange multipliers
2010-05-29 07:48:00 +02:00
fname = M . fname ;
2009-12-16 18:17:34 +01:00
if options_ . steadystate_flag
k_inst = [ ] ;
instruments = options_ . instruments ;
for i = 1 : size ( instruments , 1 )
2012-01-22 00:25:30 +01:00
k_inst = [ k_inst ; strmatch ( instruments ( i , : ) , ...
2012-02-02 12:04:15 +01:00
endo_names , ' exact' ) ] ;
2009-12-16 18:17:34 +01:00
end
2014-10-30 11:45:08 +01:00
ys_init = zeros ( size ( oo . steady_state ) ) ; %create starting vector for steady state computation as only instrument value is handed over
ys_init ( k_inst ) = x ; %set instrument, the only value required for steady state computation, to current value
2014-11-14 12:26:28 +01:00
[ x , params , check ] = evaluate_steady_state_file ( ys_init , ... %returned x now has size endo_nbr as opposed to input size of n_instruments
2011-11-14 21:58:53 +01:00
[ oo . exo_steady_state ; ...
2012-04-21 10:12:00 +02:00
oo . exo_det_steady_state ] , ...
M , options_ ) ;
2011-10-12 21:46:50 +02:00
end
2011-07-24 20:52:28 +02:00
2014-10-30 11:45:08 +01:00
xx = zeros ( endo_nbr , 1 ) ; %initialize steady state vector
xx ( 1 : M . orig_endo_nbr ) = x ( 1 : M . orig_endo_nbr ) ; %set values of original endogenous variables based on steady state file or initial value
% setting steady state of auxiliary variables that depends on original endogenous variables
if any ( [ M . aux_vars . type ] ~= 6 ) %auxiliary variables other than multipliers
2011-12-14 21:04:51 +01:00
needs_set_auxiliary_variables = 1 ;
fh = str2func ( [ M . fname ' _set_auxiliary_variables' ] ) ;
s_a_v_func = @ ( z ) fh ( z , ...
[ oo . exo_steady_state , ...
oo . exo_det_steady_state ] , ...
2012-02-02 12:04:15 +01:00
params ) ;
xx = s_a_v_func ( xx ) ;
2011-12-14 21:04:51 +01:00
else
needs_set_auxiliary_variables = 0 ;
end
2009-12-16 18:17:34 +01:00
% value and Jacobian of objective function
2010-05-29 07:48:00 +02:00
ex = zeros ( 1 , M . exo_nbr ) ;
2012-02-02 12:04:15 +01:00
[ U , Uy , Uyy ] = feval ( [ fname ' _objective_static' ] , x , ex , params ) ;
2009-12-16 18:17:34 +01:00
Uyy = reshape ( Uyy , endo_nbr , endo_nbr ) ;
2011-12-14 21:04:51 +01:00
% set multipliers and auxiliary variables that
% depends on multipliers to 0 to compute residuals
2012-06-06 16:29:26 +02:00
if ( options_ . bytecode )
2015-01-11 16:30:22 +01:00
[ chck , res , junk ] = bytecode ( ' static' , xx , [ oo . exo_steady_state oo . exo_det_steady_state ] , ...
2014-07-08 15:05:53 +02:00
params , ' evaluate' ) ;
2012-06-06 16:29:26 +02:00
fJ = junk . g1 ;
else
2015-01-11 16:30:22 +01:00
[ res , fJ ] = feval ( [ fname ' _static' ] , xx , [ oo . exo_steady_state oo . exo_det_steady_state ] , ...
2014-07-08 15:05:53 +02:00
params ) ;
2012-06-06 16:29:26 +02:00
end
2011-12-14 21:04:51 +01:00
% index of multipliers and corresponding equations
% the auxiliary variables before the Lagrange multipliers are treated
% as ordinary endogenous variables
2012-02-02 12:04:15 +01:00
aux_eq = [ 1 : orig_endo_aux_nbr , orig_endo_aux_nbr + orig_eq_nbr + 1 : size ( fJ , 1 ) ] ;
A = fJ ( aux_eq , orig_endo_aux_nbr + 1 : end ) ;
2011-12-14 21:04:51 +01:00
y = res ( aux_eq ) ;
2014-03-11 13:22:04 +01:00
mult = - A \ y ;
2009-12-16 18:17:34 +01:00
2014-03-11 13:22:04 +01:00
resids1 = y + A * mult ;
2011-06-22 11:31:35 +02:00
if inst_nbr == 1
r1 = sqrt ( resids1 ' * resids1 ) ;
else
[ q , r , e ] = qr ( [ A y ] ' ) ;
2012-02-02 12:04:15 +01:00
k = size ( A , 1 ) + ( 1 - inst_nbr : 0 ) ;
r1 = r ( end , k ) ' ;
2011-06-22 11:31:35 +02:00
end
2009-12-16 18:17:34 +01:00
if options_ . steadystate_flag
2011-06-22 11:31:35 +02:00
resids = r1 ;
2009-12-16 18:17:34 +01:00
else
2012-02-02 12:04:15 +01:00
resids = [ res ( orig_endo_nbr + ( 1 : orig_endo_nbr - inst_nbr ) ) ; r1 ] ;
2009-12-16 18:17:34 +01:00
end
rJ = [ ] ;
2014-03-11 13:22:04 +01:00
if needs_set_auxiliary_variables
steady_state = s_a_v_func ( [ xx ( 1 : orig_endo_aux_nbr ) ; mult ] ) ;
else
steady_state = [ xx ( 1 : orig_endo_aux_nbr ) ; mult ] ;
end
function result = check_static_model ( ys,M,options_,oo)
result = false ;
if ( options_ . bytecode )
2015-01-11 16:30:22 +01:00
[ chck , res , junk ] = bytecode ( ' static' , ys , [ oo . exo_steady_state oo . exo_det_steady_state ] , ...
2014-03-11 13:22:04 +01:00
M . params , ' evaluate' ) ;
else
2015-01-11 16:30:22 +01:00
res = feval ( [ M . fname ' _static' ] , ys , [ oo . exo_steady_state oo . exo_det_steady_state ] , ...
2014-03-11 13:22:04 +01:00
M . params ) ;
end
if norm ( res ) < options_ . solve_tolf
result = true ;
end