File: extended_path_initialization.m

package info (click to toggle)
dynare 6.4-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 67,648 kB
  • sloc: cpp: 79,109; ansic: 28,917; objc: 12,430; yacc: 4,528; pascal: 1,993; lex: 1,441; sh: 1,129; python: 634; makefile: 626; lisp: 163; xml: 18
file content (137 lines) | stat: -rw-r--r-- 4,955 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
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
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
function [initial_conditions, innovations, pfm, ep, verbosity, options_, oo_] = extended_path_initialization(initial_conditions, sample_size, exogenousvariables, options_, M_, oo_)
% [initial_conditions, innovations, pfm, ep, verbosity, options_, oo_] = extended_path_initialization(initial_conditions, sample_size, exogenousvariables, options_, M_, oo_)
% Initialization of the extended path routines.
%
% INPUTS
%  o initial_conditions     [double]    m*1 array, where m is the number of endogenous variables in the model.
%  o sample_size            [integer]   scalar, size of the sample to be simulated.
%  o exogenousvariables     [double]    T*n array, values for the structural innovations.
%  o options_               [struct]    Dynare's options structure
%  o M_                     [struct]    Dynare's model structure
%  o oo_                    [struct]    Dynare's result structure
%
% OUTPUTS
%
% ALGORITHM
%
% SPECIAL REQUIREMENTS

% Copyright © 2016-2023 Dynare Team
%
% 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 <https://www.gnu.org/licenses/>.

ep  = options_.ep;

% Set verbosity levels.
options_.verbosity = ep.verbosity;
verbosity = ep.verbosity+ep.debug;

% Set maximum number of iterations for the deterministic solver.
options_.simul.maxit = ep.maxit;

% Prepare a structure needed by the matlab implementation of the perfect foresight model solver
pfm = setup_stochastic_perfect_foresight_model_solver(M_, options_, oo_);

% Check that the user did not use varexo_det
if M_.exo_det_nbr~=0
    error('Extended path does not support varexo_det.')
end

% Set default initial conditions.
if isempty(initial_conditions)
    if isempty(M_.endo_histval)
        initial_conditions = oo_.steady_state;
    else
        initial_conditions = M_.endo_histval;
    end
end

% Set the number of periods for the (stochastic) perfect foresight model
pfm.periods = ep.periods;

pfm.i_upd = pfm.ny+(1:pfm.periods*pfm.ny);

pfm.block = options_.block;

% Set the algorithm for the perfect foresight solver
options_.stack_solve_algo = ep.stack_solve_algo;

% Compute the first order reduced form if needed.
dr = struct();
if ep.init
    options_.order = 1;
    oo_.dr=set_state_space(dr,M_);
    [oo_.dr,info,M_.params] = resol(0,M_,options_,oo_.dr,oo_.steady_state, oo_.exo_steady_state, oo_.exo_det_steady_state);
    if info(1)
        print_info(info,options_.noprint,options_);
    end
end

% Do not use a minimal number of perdiods for the perfect foresight solver (with bytecode and blocks)
options_.minimal_solving_period = options_.ep.periods;

% Set the covariance matrix of the structural innovations.
if isempty(exogenousvariables)
    innovations = struct();
    innovations.positive_var_indx = find(diag(M_.Sigma_e)>0);
    innovations.effective_number_of_shocks = length(innovations.positive_var_indx);
    innovations.covariance_matrix = M_.Sigma_e(innovations.positive_var_indx,innovations.positive_var_indx);
    innovations.covariance_matrix_upper_cholesky = chol(innovations.covariance_matrix);
else
    innovations = struct();
end

% Set seed.
if ep.set_dynare_seed_to_default
    options_=set_dynare_seed_local_options(options_,'default');
end

% hybrid correction
pfm.hybrid_order = ep.stochastic.hybrid_order;
if pfm.hybrid_order
    oo_.dr = set_state_space(oo_.dr, M_);
    options = options_;
    options.order = pfm.hybrid_order;
    [pfm.dr, M_.params] = resol(0, M_, options, oo_.dr, oo_.steady_state, oo_.exo_steady_state, oo_.exo_det_steady_state);
else
    pfm.dr = [];
end

% number of nonzero derivatives
pfm.nnzA = M_.NNZDerivatives(1);

% setting up integration nodes if order > 0
if ep.stochastic.order > 0
    [nodes,weights,nnodes] = setup_integration_nodes(options_.ep,pfm);
    pfm.nodes = nodes;
    pfm.weights = weights;
    pfm.nnodes = nnodes;
    % compute number of blocks
    [block_nbr,pfm.world_nbr] = get_block_world_nbr(ep.stochastic.algo,nnodes,ep.stochastic.order,ep.periods);
else
    block_nbr = ep.periods;
end

% set boundaries if mcp
[lb,ub,pfm.eq_index] = get_complementarity_conditions(M_, options_.ramsey_policy);
if options_.ep.solve_algo == 10
    options_.lmmcp.lb = repmat(lb,block_nbr,1);
    options_.lmmcp.ub = repmat(ub,block_nbr,1);
elseif options_.ep.solve_algo == 11
    options_.mcppath.lb = repmat(lb,block_nbr,1);
    options_.mcppath.ub = repmat(ub,block_nbr,1);
end
pfm.block_nbr = block_nbr;