“datafile” option of “perfect_foresight_setup” (and “simul”) now equivalent to “initval_file”
Ref. #1663time-shift
parent
7e07d3e0fc
commit
efa6c6c682
|
@ -2700,10 +2700,8 @@ speed-up on large models.
|
|||
|
||||
.. option:: datafile = FILENAME
|
||||
|
||||
If the variables of the model are not constant over time, their
|
||||
initial values, stored in a text file, could be loaded, using
|
||||
that option, as initial values before a deterministic
|
||||
simulation.
|
||||
Used to specify path for all endogenous and exogenous variables.
|
||||
Strictly equivalent to :comm:`initval_file`.
|
||||
|
||||
*Output*
|
||||
|
||||
|
|
|
@ -65,10 +65,6 @@ if ~isempty(M_.det_shocks) && options_.periods<max([M_.det_shocks.periods])
|
|||
end
|
||||
|
||||
if ~options_.initval_file
|
||||
if isempty(options_.datafile)
|
||||
oo_=make_ex_(M_,options_,oo_);
|
||||
oo_=make_y_(M_,options_,oo_);
|
||||
else
|
||||
read_data_;
|
||||
end
|
||||
oo_ = make_ex_(M_,options_,oo_);
|
||||
oo_ = make_y_(M_,options_,oo_);
|
||||
end
|
||||
|
|
|
@ -1,75 +0,0 @@
|
|||
function read_data_()
|
||||
% function read_data_
|
||||
% reads endogenous and exogenous variables from a text file
|
||||
% Used by datafile option in simulate
|
||||
%
|
||||
% INPUT
|
||||
% none
|
||||
%
|
||||
% OUTPUT
|
||||
% none
|
||||
%
|
||||
% SPECIAL REQUIREMENT
|
||||
% none
|
||||
|
||||
% Copyright (C) 2007-2018 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 <http://www.gnu.org/licenses/>.
|
||||
|
||||
global options_ M_ oo_;
|
||||
dname= options_.datafile;
|
||||
|
||||
if size(oo_.endo_simul,2) < M_.maximum_lag+M_.maximum_lead+options_.periods
|
||||
fid = fopen([dname '_endo.dat'],'r');
|
||||
names_line = fgetl(fid);
|
||||
allVariables = '';
|
||||
positions = ones(0);
|
||||
while (any(names_line))
|
||||
[chopped,names_line] = strtok(names_line);
|
||||
if isempty(allVariables)
|
||||
allVariables = chopped;
|
||||
else
|
||||
allVariables = char(allVariables, chopped);
|
||||
end
|
||||
positions = [positions ; strmatch(chopped,M_.endo_names,'exact')];
|
||||
end
|
||||
Values=fscanf(fid,'%f',inf);
|
||||
Values=reshape(Values,M_.orig_endo_nbr,size(Values,1)/M_.orig_endo_nbr);
|
||||
oo_.endo_simul=[Values(positions,:); kron(oo_.steady_state((M_.orig_endo_nbr+1) : M_.endo_nbr , 1) , ones(1 , size(Values, 2)))];
|
||||
fclose(fid);
|
||||
end
|
||||
|
||||
if size(oo_.exo_simul,1) < M_.maximum_lag+M_.maximum_lead+options_.periods
|
||||
fid = fopen([dname '_exo.dat'],'r');
|
||||
names_line = fgetl(fid);
|
||||
allVariables = '';
|
||||
positions = ones(0);
|
||||
while (any(names_line))
|
||||
[chopped,names_line] = strtok(names_line);
|
||||
if isempty(allVariables)
|
||||
allVariables = chopped;
|
||||
else
|
||||
allVariables = char(allVariables, chopped);
|
||||
end
|
||||
positions = [positions ; strmatch(chopped,M_.exo_names,'exact')];
|
||||
end
|
||||
Values=fscanf(fid,'%f',inf);
|
||||
Values=reshape(Values,M_.exo_nbr,size(Values,1)/M_.exo_nbr);
|
||||
oo_.exo_simul=(Values(positions,:))';
|
||||
fclose(fid);
|
||||
end
|
||||
|
||||
end
|
|
@ -1 +1 @@
|
|||
Subproject commit d1d244086d3beaedf43e880435b50a3ef3052124
|
||||
Subproject commit 044258b0a217bc6e87c08d97b343ed56b7ba9d6e
|
|
@ -102,6 +102,7 @@ MODFILES = \
|
|||
discretionary_policy/dennis_1.mod \
|
||||
discretionary_policy/Gali_discretion.mod \
|
||||
initval_file/ramst_initval_file.mod \
|
||||
initval_file/ramst_datafile.mod \
|
||||
ramst_normcdf_and_friends.mod \
|
||||
ramst_vec.mod \
|
||||
example1_varexo_det.mod \
|
||||
|
@ -490,6 +491,8 @@ deterministic_simulations/rbc_det_stack_solve_algo_7_exo_lag.o.trs: deterministi
|
|||
|
||||
initval_file/ramst_initval_file.m.trs: initval_file/ramst_initval_file_data.m.tls
|
||||
initval_file/ramst_initval_file.o.trs: initval_file/ramst_initval_file_data.o.tls
|
||||
initval_file/ramst_datafile.m.trs: initval_file/ramst_initval_file_data.m.tls
|
||||
initval_file/ramst_datafile.o.trs: initval_file/ramst_initval_file_data.o.tls
|
||||
|
||||
identification/rbc_ident/rbc_ident_varexo_only.m.trs: identification/rbc_ident/rbc_ident_std_as_structural_par.m.trs
|
||||
identification/rbc_ident/rbc_ident_varexo_only.o.trs: identification/rbc_ident/rbc_ident_std_as_structural_par.o.trs
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
/* Verify that the “datafile” option of “perfect_foresight_setup” behaves as
|
||||
“initval_file” (see #1663) */
|
||||
|
||||
var c k;
|
||||
varexo x;
|
||||
|
||||
parameters alph gam delt bet aa;
|
||||
alph=0.5;
|
||||
gam=0.5;
|
||||
delt=0.02;
|
||||
bet=0.05;
|
||||
aa=0.5;
|
||||
|
||||
|
||||
model;
|
||||
c + k - aa*x*k(-1)^alph - (1-delt)*k(-1);
|
||||
c^(-gam) - (1+bet)^(-1)*(aa*alph*x(+1)*k^(alph-1) + 1 - delt)*c(+1)^(-gam);
|
||||
end;
|
||||
|
||||
initval;
|
||||
x = 1;
|
||||
k = ((delt+bet)/(1.0*aa*alph))^(1/(alph-1));
|
||||
c = aa*k^alph-delt*k;
|
||||
end;
|
||||
|
||||
steady;
|
||||
|
||||
perfect_foresight_setup(periods=200, datafile = ramst_initval_file_data_col_vec_mat);
|
||||
if oo_.exo_simul(2) ~= 1.2
|
||||
error('datafile option problem with exogenous variable');
|
||||
end
|
||||
if oo_.endo_simul(2, 2) ~= 13
|
||||
error('datafile option problem with endogenous variable');
|
||||
end
|
||||
|
||||
perfect_foresight_solver;
|
Loading…
Reference in New Issue