* Bug fixes.
* Removed local copy of endo_simul. * Cosmetic changes. git-svn-id: https://www.dynare.org/svn/dynare/trunk@3293 ac1d8469-bf42-47a9-8791-bf33cf982152time-shift
parent
e6a1916577
commit
ec6c70443a
|
@ -37,8 +37,8 @@ if isempty(initial_conditions)
|
|||
initial_conditions = repmat(oo_.steady_state,1,M_.maximum_lag);
|
||||
end
|
||||
|
||||
% Copy sample_size to periods.
|
||||
options_.periods = sample_size;
|
||||
% Set the number of periods for the deterministic solver.
|
||||
options_.periods = 100;
|
||||
|
||||
% Initialize the exogenous variables.
|
||||
make_ex_;
|
||||
|
@ -60,7 +60,7 @@ tdx = M_.maximum_lag+1;
|
|||
norme = 0;
|
||||
|
||||
% Set verbose option
|
||||
verbose = 0;
|
||||
verbose = 1;
|
||||
|
||||
for t=1:sample_size
|
||||
shocks = exp(randn(1,number_of_structural_innovations)*covariance_matrix_upper_cholesky-.5*variances(positive_var_indx)');
|
||||
|
@ -72,7 +72,7 @@ for t=1:sample_size
|
|||
info
|
||||
end
|
||||
if ~info.convergence
|
||||
info = homotopic_steps(tdx,positive_var_indx,shocks,norme,.2);
|
||||
info = homotopic_steps(tdx,positive_var_indx,shocks,norme,.5);
|
||||
if verbose
|
||||
norme
|
||||
info
|
||||
|
@ -90,10 +90,11 @@ for t=1:sample_size
|
|||
end
|
||||
|
||||
|
||||
|
||||
function info = homotopic_steps(tdx,positive_var_indx,shocks,init_weight,step)
|
||||
global oo_
|
||||
weight = init_weight;
|
||||
verbose = 0;
|
||||
verbose = 1;
|
||||
iter = 0;
|
||||
time = 0;
|
||||
reduce_step = 0;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
function [info,endo_simul] = perfect_foresight_simulation(endo_simul,exo_simul,compute_linear_solution,steady_state)
|
||||
function info = perfect_foresight_simulation(compute_linear_solution,steady_state)
|
||||
% Performs deterministic simulations with lead or lag on one period
|
||||
%
|
||||
% INPUTS
|
||||
|
@ -18,7 +18,7 @@ function [info,endo_simul] = perfect_foresight_simulation(endo_simul,exo_simul,c
|
|||
% SPECIAL REQUIREMENTS
|
||||
% None.
|
||||
|
||||
% Copyright (C) 1996-2009 Dynare Team
|
||||
% Copyright (C) 2009 Dynare Team
|
||||
%
|
||||
% This file is part of Dynare.
|
||||
%
|
||||
|
@ -35,16 +35,18 @@ function [info,endo_simul] = perfect_foresight_simulation(endo_simul,exo_simul,c
|
|||
% You should have received a copy of the GNU General Public License
|
||||
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
global M_ options_ it_
|
||||
global M_ options_ it_ oo_
|
||||
|
||||
persistent flag_init
|
||||
persistent lead_lag_incidence dynamic_model ny nyp nyf nrs nrc iyf iyp isp is isf isf1 iz icf
|
||||
persistent ghx
|
||||
|
||||
initial_endo_simul = oo_.endo_simul;
|
||||
|
||||
if isempty(flag_init)
|
||||
lead_lag_incidence = M_.lead_lag_incidence;
|
||||
dynamic_model = [M_.fname '_dynamic'];
|
||||
ny = size(endo_simul,1);
|
||||
ny = size(oo_.endo_simul,1);
|
||||
nyp = nnz(lead_lag_incidence(1,:));% number of lagged variables.
|
||||
nyf = nnz(lead_lag_incidence(3,:));% number of leaded variables.
|
||||
nrs = ny+nyp+nyf+1;
|
||||
|
@ -60,10 +62,11 @@ if isempty(flag_init)
|
|||
flag_init = 1;
|
||||
end
|
||||
|
||||
if nargin<3
|
||||
if nargin<1
|
||||
compute_linear_solution = 0;
|
||||
if nargin<4
|
||||
error('The steady state (fourth input argument) is missing!');
|
||||
else
|
||||
if nargin<2
|
||||
error('The steady state (second input argument) is missing!');
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -95,15 +98,15 @@ for iter = 1:options_.maxit_
|
|||
c = zeros(ny*periods,nrc);
|
||||
end
|
||||
it_ = it_init;
|
||||
z = [ endo_simul(iyp,it_-1) ; endo_simul(:,it_) ; endo_simul(iyf,it_+1) ];
|
||||
[d1,jacobian] = feval(dynamic_model,z,exo_simul, M_.params, it_);
|
||||
z = [ oo_.endo_simul(iyp,it_-1) ; oo_.endo_simul(:,it_) ; oo_.endo_simul(iyf,it_+1) ];
|
||||
[d1,jacobian] = feval(dynamic_model,z,oo_.exo_simul, M_.params, it_);
|
||||
jacobian = [jacobian(:,iz) , -d1];
|
||||
ic = 1:ny;
|
||||
icp = iyp;
|
||||
c(ic,:) = jacobian(:,is)\jacobian(:,isf1) ;
|
||||
for it_ = it_init+(1:periods-1)
|
||||
z = [ endo_simul(iyp,it_-1) ; endo_simul(:,it_) ; endo_simul(iyf,it_+1)];
|
||||
[d1,jacobian] = feval(dynamic_model,z,exo_simul, M_.params, it_);
|
||||
z = [ oo_.endo_simul(iyp,it_-1) ; oo_.endo_simul(:,it_) ; oo_.endo_simul(iyf,it_+1)];
|
||||
[d1,jacobian] = feval(dynamic_model,z,oo_.exo_simul, M_.params, it_);
|
||||
jacobian = [jacobian(:,iz) , -d1];
|
||||
jacobian(:,[isf nrs]) = jacobian(:,[isf nrs])-jacobian(:,isp)*c(icp,:);
|
||||
ic = ic + ny;
|
||||
|
@ -116,14 +119,18 @@ for iter = 1:options_.maxit_
|
|||
s(:,isf) = s(:,isf)+c(ic,1:nyf);
|
||||
ic = ic + ny;
|
||||
c(ic,nrc) = s\c(ic,nrc);
|
||||
else% Terminal condition is Y_{T}-Y^{\star} = TransitionMatrix*(Y_{T+1}-Y^{\star})
|
||||
z = [ endo_simul(iyp,it_-1) ; endo_simul(:,it_) ; endo_simul(iyf,it_+1) ] ;
|
||||
[d1,jacobian] = feval(dynamic_model,z,exo_simul, M_.params, it_);
|
||||
else% Terminal condition is Y_{T+1}-Y^{\star} = TransitionMatrix*(Y_{T}-Y^{\star})
|
||||
z = [ oo_.endo_simul(iyp,it_-1) ; oo_.endo_simul(:,it_) ; oo_.endo_simul(iyf,it_+1) ] ;
|
||||
[d1,jacobian] = feval(dynamic_model,z,oo_.exo_simul, M_.params, it_);
|
||||
jacobian = [jacobian(:,iz) -d1];
|
||||
jacobian(:,[isf nrs]) = jacobian(:,[isf nrs])-jacobian(:,isp)*c(icp,:) ;
|
||||
ic = ic + ny;
|
||||
icp = icp + ny;
|
||||
s = jacobian(:,is);
|
||||
iyp
|
||||
nyp
|
||||
isf
|
||||
iyp-nyp
|
||||
s(:,iyp-nyp) = s(:,iyp-nyp)+jacobian(:,isf)*ghx;
|
||||
c (ic,:) = s\jacobian(:,isf1);
|
||||
end
|
||||
|
@ -133,18 +140,18 @@ for iter = 1:options_.maxit_
|
|||
else% Terminal condition is Y_{T}=Y^{\star}
|
||||
c = bksup0(c,ny,nrc,iyf,icf,periods);
|
||||
c = reshape(c,ny,periods);
|
||||
endo_simul(:,it_init+(0:periods-1)) = endo_simul(:,it_init+(0:periods-1))+options_.slowc*c;
|
||||
oo_.endo_simul(:,it_init+(0:periods-1)) = oo_.endo_simul(:,it_init+(0:periods-1))+options_.slowc*c;
|
||||
end
|
||||
err = max(max(abs(c)));
|
||||
info.iterations.time(iter) = etime(clock,h2);
|
||||
info.iterations.error(iter) = err;
|
||||
% if iter>1
|
||||
% error_growth = error_growth + (info.iterations.error(iter)>info.iterations.error(iter-1));
|
||||
% end
|
||||
% if isnan(err) || error_growth>3
|
||||
% last_line = iter;
|
||||
% break
|
||||
% end
|
||||
if iter>1
|
||||
error_growth = error_growth + (info.iterations.error(iter)>info.iterations.error(iter-1));
|
||||
end
|
||||
if isnan(err) || error_growth>3
|
||||
last_line = iter;
|
||||
break
|
||||
end
|
||||
if err < options_.dynatol
|
||||
stop = 1;
|
||||
info.time = etime(clock,h1);
|
||||
|
@ -156,7 +163,7 @@ for iter = 1:options_.maxit_
|
|||
end
|
||||
|
||||
if options_.terminal_condition==2
|
||||
distance_to_steady_state = abs(((endo_simul(:,end-1)-endo_simul(:,end))./endo_simul(:,end)))*100;
|
||||
distance_to_steady_state = abs(((oo_.endo_simul(:,end-1)-oo_.endo_simul(:,end))./oo_.endo_simul(:,end)))*100;
|
||||
disp('Distance to steady state at the end is (in percentage):')
|
||||
distance_to_steady_state
|
||||
end
|
||||
|
@ -167,6 +174,5 @@ if ~stop
|
|||
info.convergence = 0;
|
||||
info.iterations.time = info.iterations.time(1:last_line);
|
||||
info.iterations.error = info.iterations.error(1:last_line);
|
||||
info.iterations.error
|
||||
endo_simul = [ ];
|
||||
oo_.endo_simul = initial_endo_simul;
|
||||
end
|
Loading…
Reference in New Issue