Home > matlab > reversed_extended_path.m

reversed_extended_path

PURPOSE ^

Inversion of the extended path simulation approach. This routine computes the innovations needed to

SYNOPSIS ^

function innovation_paths = reversed_extended_path(controlled_variable_names, control_innovation_names, dataset)

DESCRIPTION ^

 Inversion of the extended path simulation approach. This routine computes the innovations needed to
 reproduce the time path of a subset of endogenous variables. The initial condition is teh deterministic
 steady state.

 INPUTS
  o controlled_variable_names        [string]    n*1 matlab's cell.
  o control_innovation_names         [string]    n*1 matlab's cell.
  o dataset                          [structure]
 OUTPUTS
  o innovations                      [double]  n*T matrix.

 ALGORITHM

 SPECIAL REQUIREMENTS

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function innovation_paths = reversed_extended_path(controlled_variable_names, control_innovation_names, dataset)
0002 % Inversion of the extended path simulation approach. This routine computes the innovations needed to
0003 % reproduce the time path of a subset of endogenous variables. The initial condition is teh deterministic
0004 % steady state.
0005 %
0006 % INPUTS
0007 %  o controlled_variable_names        [string]    n*1 matlab's cell.
0008 %  o control_innovation_names         [string]    n*1 matlab's cell.
0009 %  o dataset                          [structure]
0010 % OUTPUTS
0011 %  o innovations                      [double]  n*T matrix.
0012 %
0013 % ALGORITHM
0014 %
0015 % SPECIAL REQUIREMENTS
0016 
0017 % Copyright (C) 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 global M_ oo_ options_
0035 
0036 %% Initialization
0037 
0038 % Load data.
0039 eval(dataset.name);
0040 dataset.data = [];
0041 for v = 1:dataset.number_of_observed_variables
0042     eval(['dataset.data = [ dataset.data , ' dataset.variables(v,:) ' ];'])
0043 end
0044 data = dataset.data(dataset.first_observation:dataset.first_observation+dataset.number_of_observations,:);
0045 
0046 % Compute the deterministic steady state.
0047 steady_;
0048 
0049 %  Compute the first order perturbation reduced form.
0050 old_options_order = options_.order; options_.order = 1;
0051 [dr,info,M_,options_,oo_] = resol(0,M_,options_,oo_);
0052 oo_.dr = dr;
0053 options_.order = old_options_order;
0054 
0055 % Set various options.
0056 options_.periods = 100;
0057 
0058 % Set-up oo_.exo_simul.
0059 make_ex_;
0060 
0061 % Set-up oo_.endo_simul.
0062 make_y_;
0063 
0064 % Get indices of the controlled endogenous variables in endo_simul.
0065 n  = length(controlled_variable_names);
0066 iy = NaN(n,1);
0067 for k=1:n
0068     iy(k) = strmatch(controlled_variable_names{k},M_.endo_names,'exact');
0069 end
0070 
0071 % Get indices of the controlled endogenous variables in dataset.
0072 iy_ = NaN(n,1);
0073 for k=1:n
0074     iy_(k) = strmatch(controlled_variable_names{k},dataset.variables,'exact');
0075 end
0076 
0077 % Get indices of the control innovations in exo_simul.
0078 ix = NaN(n,1);
0079 for k=1:n
0080     ix(k) = strmatch(control_innovation_names{k},M_.exo_names,'exact');
0081 end
0082 
0083 % Get the length of the sample.
0084 T = size(data,1);
0085 
0086 % Output initialization.
0087 innovation_paths = zeros(n,T);
0088 
0089 % Initialization of the perfect foresight model solver.
0090 perfect_foresight_simulation();
0091 
0092 % Set options for fsolve.
0093 options = optimset('MaxIter',10000,'Display','Iter');
0094 
0095 %% Call fsolve recursively
0096 for t=1:T
0097     x0 = zeros(n,1);
0098     y_target  = transpose(data(t,iy_));
0099     total_variation = y_target-transpose(oo_.endo_simul(t+M_.maximum_lag,iy));
0100     for i=1:100
0101         [t,i]
0102         y = transpose(oo_.endo_simul(t+M_.maximum_lag,iy)) + (i/100)*y_target
0103         [tmp,fval,exitflag] = fsolve('ep_residuals', x0, options, y, ix, iy, oo_.steady_state, oo_.dr, M_.maximum_lag, M_.endo_nbr);
0104     end
0105     if exitflag==1
0106         innovation_paths(:,t) = tmp;
0107     end
0108     % Update endo_simul.
0109     oo_.endo_simul(:,1:end-1) = oo_.endo_simul(:,2:end);
0110     oo_.endo_simul(:,end) = oo_.steady_state;
0111 end

Generated on Tue 22-May-2012 02:40:23 by m2html © 2005