resol.m 5.24 KB
Newer Older
1
2
3
4
5
6
function [dr,info,M,options,oo] = resol(check_flag,M,options,oo)

%@info:
%! @deftypefn {Function File} {[@var{dr},@var{info},@var{M},@var{options},@var{oo}] =} resol (@var{check_flag},@var{M},@var{options},@var{oo})
%! @anchor{resol}
%! @sp 1
7
%! Computes the perturbation-based decisions rules of the DSGE model (orders 1 to 3).
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
%! @sp 2
%! @strong{Inputs}
%! @sp 1
%! @table @ @var
%! @item check_flag
%! Integer scalar, equal to 0 if all the approximation is required, positive if only the eigenvalues are to be computed.
%! @item M
%! Matlab's structure describing the model (initialized by @code{dynare}).
%! @item options
%! Matlab's structure describing the options (initialized by @code{dynare}).
%! @item oo
%! Matlab's structure gathering the results (initialized by @code{dynare}).
%! @end table
%! @sp 2
%! @strong{Outputs}
%! @sp 1
%! @table @ @var
%! @item dr
%! Matlab's structure describing the reduced form solution of the model.
%! @item info
%! Integer scalar, error code.
%! @sp 1
%! @table @ @code
%! @item info==0
%! No error.
%! @item info==1
%! The model doesn't determine the current variables uniquely.
%! @item info==2
%! MJDGGES returned an error code.
%! @item info==3
%! Blanchard & Kahn conditions are not satisfied: no stable equilibrium.
%! @item info==4
%! Blanchard & Kahn conditions are not satisfied: indeterminacy.
%! @item info==5
%! Blanchard & Kahn conditions are not satisfied: indeterminacy due to rank failure.
%! @item info==6
%! The jacobian evaluated at the deterministic steady state is complex.
%! @item info==19
46
%! The steadystate routine has thrown an exception (inconsistent deep parameters).
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
%! @item info==20
%! Cannot find the steady state, info(2) contains the sum of square residuals (of the static equations).
%! @item info==21
%! The steady state is complex, info(2) contains the sum of square of imaginary parts of the steady state.
%! @item info==22
%! The steady has NaNs.
%! @item info==23
%! M_.params has been updated in the steadystate routine and has complex valued scalars.
%! @item info==24
%! M_.params has been updated in the steadystate routine and has some NaNs.
%! @item info==30
%! Ergodic variance can't be computed.
%! @end table
%! @sp 1
%! @item M
%! Matlab's structure describing the model (initialized by @code{dynare}).
%! @item options
%! Matlab's structure describing the options (initialized by @code{dynare}).
%! @item oo
%! Matlab's structure gathering the results (initialized by @code{dynare}).
%! @end table
%! @sp 2
%! @strong{This function is called by:}
%! @sp 1
%! @ref{dynare_estimation_init}
%! @sp 2
%! @strong{This function calls:}
%! @sp 1
%! None.
%! @end deftypefn
%@eod:
78

Stéphane Adjemian's avatar
Stéphane Adjemian committed
79
% Copyright (C) 2001-2017 Dynare Team
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
%
% 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/>.
assia's avatar
assia committed
95

96
if isfield(oo,'dr')
97
    dr = oo.dr;
98
end
michel's avatar
michel committed
99

100
101
if M.exo_nbr == 0
    oo.exo_steady_state = [] ;
michel's avatar
michel committed
102
103
end

104
[dr.ys,M.params,info] = evaluate_steady_state(oo.steady_state,M,options,oo,~options.steadystate.nocheck);
michel's avatar
   
michel committed
105

106
if info(1)
107
    oo.dr = dr;
108
    return
michel's avatar
michel committed
109
110
end

111
if options.loglinear
112
    threshold = 1e-16;
113
114
    % Find variables with non positive steady state. Skip auxiliary
    % variables for lagges/leaded exogenous variables
115
    idx = find(dr.ys(get_all_variables_but_lagged_leaded_exogenous(M))<threshold);
116
    if length(idx)
117
118
119
120
121
122
123
124
        if options.debug
            variables_with_non_positive_steady_state = M.endo_names(idx,:);
            skipline()
            fprintf('You are attempting to simulate/estimate a loglinear approximation of a model, but\n')
            fprintf('the steady state level of the following variables is not strictly positive:\n')
            for var_iter=1:length(idx)
                fprintf(' - %s (%s)\n',deblank(variables_with_non_positive_steady_state(var_iter,:)), num2str(dr.ys(idx(var_iter))))
            end
125
            if isinestimationobjective()
126
127
128
129
130
131
132
133
                fprintf('You should check that the priors and/or bounds over the deep parameters are such\n')
                fprintf('that the steady state levels of all the variables are strictly positive, or consider\n')
                fprintf('a linearization of the model instead of a log linearization.\n')
            else
                fprintf('You should check that the calibration of the deep parameters is such that the\n')
                fprintf('steady state levels of all the variables are strictly positive, or consider\n')
                fprintf('a linearization of the model instead of a log linearization.\n')
            end
134
        end
135
        info(1)=26;
136
        info(2)=sum(dr.ys(dr.ys<threshold).^2);
137
        return
138
139
140
    end
end

141
142
if options.block
    [dr,info,M,options,oo] = dr_block(dr,check_flag,M,options,oo);
143
else
144
    [dr,info] = stochastic_solvers(dr,check_flag,M,options,oo);
145
end
Houtan Bastani's avatar
Houtan Bastani committed
146
oo.dr = dr;