From efa6c6c682b7fbd69bcc4b8daf89800f50eba9e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= Date: Thu, 19 Dec 2019 14:58:54 +0100 Subject: [PATCH] =?UTF-8?q?=E2=80=9Cdatafile=E2=80=9D=20option=20of=20?= =?UTF-8?q?=E2=80=9Cperfect=5Fforesight=5Fsetup=E2=80=9D=20(and=20?= =?UTF-8?q?=E2=80=9Csimul=E2=80=9D)=20now=20equivalent=20to=20=E2=80=9Cini?= =?UTF-8?q?tval=5Ffile=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Ref. #1663 --- doc/manual/source/the-model-file.rst | 6 +- .../perfect_foresight_setup.m | 8 +- matlab/read_data_.m | 75 ------------------- preprocessor | 2 +- tests/Makefile.am | 3 + tests/initval_file/ramst_datafile.mod | 36 +++++++++ 6 files changed, 44 insertions(+), 86 deletions(-) delete mode 100644 matlab/read_data_.m create mode 100644 tests/initval_file/ramst_datafile.mod diff --git a/doc/manual/source/the-model-file.rst b/doc/manual/source/the-model-file.rst index 32f18583c..99bd927f5 100644 --- a/doc/manual/source/the-model-file.rst +++ b/doc/manual/source/the-model-file.rst @@ -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* diff --git a/matlab/perfect-foresight-models/perfect_foresight_setup.m b/matlab/perfect-foresight-models/perfect_foresight_setup.m index b379be4f9..45f6f2789 100644 --- a/matlab/perfect-foresight-models/perfect_foresight_setup.m +++ b/matlab/perfect-foresight-models/perfect_foresight_setup.m @@ -65,10 +65,6 @@ if ~isempty(M_.det_shocks) && options_.periods. - -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 \ No newline at end of file diff --git a/preprocessor b/preprocessor index d1d244086..044258b0a 160000 --- a/preprocessor +++ b/preprocessor @@ -1 +1 @@ -Subproject commit d1d244086d3beaedf43e880435b50a3ef3052124 +Subproject commit 044258b0a217bc6e87c08d97b343ed56b7ba9d6e diff --git a/tests/Makefile.am b/tests/Makefile.am index 27fb98403..c9ae912ac 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -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 diff --git a/tests/initval_file/ramst_datafile.mod b/tests/initval_file/ramst_datafile.mod new file mode 100644 index 000000000..47df52175 --- /dev/null +++ b/tests/initval_file/ramst_datafile.mod @@ -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;