dyn_ramsey_static.m 4.52 KB
Newer Older
1
function [steady_state,params,check] = dyn_ramsey_static(x,M,options_,oo)
2

3
% function  [steady_state,params,check] = dyn_ramsey_static_(x)
4
5
6
% Computes the static first order conditions for optimal policy
%
% INPUTS
7
%    x:         vector of endogenous variables or instruments
8
9
10
11
12
13
14
15
16
%
% OUTPUTS
%    resids:    residuals of non linear equations
%    rJ:        Jacobian
%    mult:      Lagrangian multipliers
%
% SPECIAL REQUIREMENTS
%    none

17
% Copyright (C) 2003-2010 Dynare Team
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
%
% 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/>.
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80


steady_state = [];
params = M.params;
check = 0;
nl_func = @(x) dyn_ramsey_static_1(x,M,options_,oo);

if options_.steadystate_flag
    k_inst = [];
    instruments = options_.instruments;
    inst_nbr = size(options_.instruments);
    for i = 1:inst_nbr
        k_inst = [k_inst; strmatch(options_.instruments(i,:), ...
                                   M.endo_names,'exact')];
    end
    ys = oo.steady_state;
    if inst_nbr == 1
        inst_val = csolve(nl_func,oo_.steady_state(k_inst),'',options_.solve_tolf,100);
    else
        [inst_val,info1] = dynare_solve(nl_func,ys(k_inst),0);
    end
    ys(k_inst) = inst_val;
    [x,params,check] = evaluate_steadystate_file(ys,exo_ss,params,M.fname,options_.steadystate_flag);
    if size(x,1) < M.endo_nbr 
        if length(M.aux_vars) > 0
            x =  feval([M.fname '_set_auxiliary_variables'],xx,...
                       [oo.exo_steady_state,...
                        oo.exo_det_steady_state],...
                       M.params);
        else
            error([M.fname '_steadystate.m doesn''t match the model']);
        end
    end
    [junk,junk,multbar] = dyn_ramsey_static_1(x(k_inst),M,options_,oo_);
    steady_state = [x(1:M.orig_endo_nbr); multbar];
else
    xx = oo.steady_state(1:M.orig_endo_nbr);
    [xx,info1] = dynare_solve(nl_func,xx,0);
    [junk,junk,multbar] = nl_func(xx);
    steady_state = [xx; multbar];
end



function [resids, rJ,mult] = dyn_ramsey_static_1(x,M,options_,oo)
resids = [];
rJ = [];
mult = [];
81
82

% recovering usefull fields
83
84
endo_nbr = M.endo_nbr;
exo_nbr = M.exo_nbr;
85
86
orig_endo_nbr = M.orig_endo_nbr;
orig_eq_nbr = M.orig_eq_nbr;
87
88
89
inst_nbr = orig_endo_nbr - orig_eq_nbr;
% indices of Lagrange multipliers
i_mult = [orig_endo_nbr+(1:orig_eq_nbr)]';
90
91
92
fname = M.fname;
max_lead = M.maximum_lead;
max_lag = M.maximum_lag;
93
94
95
96

% indices of all endogenous variables
i_endo = [1:endo_nbr]';
% indices of endogenous variable except instruments
97
% i_inst = M.instruments;
98
% lead_lag incidence matrix for endogenous variables
99
i_lag = M.lead_lag_incidence;
100
101
102
103
104
105

if options_.steadystate_flag
    k_inst = [];
    instruments = options_.instruments;
    for i = 1:size(instruments,1)
        k_inst = [k_inst; strmatch(options_.instruments(i,:), ...
106
                                   M.endo_names,'exact')];
107
    end
108
109
110
111
112
    oo.steady_state(k_inst) = x;
    [x,check] = feval([M.fname '_steadystate'],...
                      oo.steady_state,...
                      [oo.exo_steady_state; ...
                       oo.exo_det_steady_state]);
113
end
MichelJuillard's avatar
MichelJuillard committed
114

115
116
117
% setting steady state of auxiliary variables
xx = zeros(endo_nbr,1);
xx(1:orig_endo_nbr) = x(1:orig_endo_nbr);
MichelJuillard's avatar
MichelJuillard committed
118

119
120
121
122
x = feval([M.fname '_set_auxiliary_variables'],xx,...
          [oo.exo_steady_state,...
           oo.exo_det_steady_state],...
          M.params);
123
124

% value and Jacobian of objective function
125
ex = zeros(1,M.exo_nbr);
126
[U,Uy,Uyy] = feval([fname '_objective_static'],x,ex, M.params);
127
128
129
Uy = Uy';
Uyy = reshape(Uyy,endo_nbr,endo_nbr);

130
% set multipliers to 0 to compute residuals
131
132
[f,fJ] = feval([fname '_static'],x,[oo.exo_simul oo.exo_det_simul], ...
               M.params);
133

MichelJuillard's avatar
MichelJuillard committed
134
135
136
aux_eq = [1:orig_endo_nbr orig_endo_nbr+orig_eq_nbr+1:size(fJ,1)];
A = fJ(aux_eq,orig_endo_nbr+1:end);
y = f(aux_eq);
137
mult = -A\y;
138

139
resids1 = y+A*mult;
MichelJuillard's avatar
MichelJuillard committed
140
141
142
143
144
145
if inst_nbr == 1
    r1 = sqrt(resids1'*resids1);
else
    [q,r,e] = qr([A y]');
    r1 = r(end,(orig_endo_nbr-inst_nbr+1:end))';
end
146
if options_.steadystate_flag
MichelJuillard's avatar
MichelJuillard committed
147
    resids = r1;
148
else
MichelJuillard's avatar
MichelJuillard committed
149
    resids = [f(i_mult); r1];
150
151
end
rJ = [];