From b70d99d1b4af4e6799858902868300a246e3b492 Mon Sep 17 00:00:00 2001 From: Michel Juillard Date: Fri, 27 Dec 2019 18:58:32 +0100 Subject: [PATCH] Refactoring of initval_file and histval_file initval_file and hisvfal_file are now more flexible and have functionalities similar to option datafile in estimation. Closes: #1671 --- doc/manual/source/the-model-file.rst | 531 +++++++++++++++++- matlab/global_initialization.m | 1 + matlab/histvalf.m | 97 ++-- matlab/histvalf_initvalf.m | 223 ++++++++ matlab/initvalf.m | 94 +--- matlab/perfect-foresight-models/make_ex_.m | 34 +- matlab/perfect-foresight-models/make_y_.m | 35 +- .../perfect_foresight_setup.m | 7 +- matlab/perfect-foresight-models/sim1.m | 4 +- matlab/smoother2histval.m | 97 ++-- preprocessor | 2 +- tests/.gitignore | 6 +- tests/Makefile.am | 47 +- tests/histval_initval_file/my_assert.m | 4 + tests/histval_initval_file/ramst_data.mod | 68 +++ tests/histval_initval_file/ramst_data.xls | Bin 0 -> 19968 bytes tests/histval_initval_file/ramst_data.xlsx | Bin 0 -> 8575 bytes .../ramst_datafile.mod | 0 .../ramst_histval_file.mod | 96 ++++ .../ramst_initval_file.mod | 113 ++++ .../ramst_initval_file_data.m | 14 + .../histval_initval_file/sim_exo_lead_lag.mod | 43 ++ .../sim_exo_lead_lag_histvalf.mod | 76 +++ .../sim_exo_lead_lag_initvalf.mod | 56 ++ .../sim_histvalf_stoch_simul.mod | 86 +++ tests/histval_initval_file_unit_tests.m | 220 ++++++++ tests/initval_file/ramst_initval_file.mod | 55 -- tests/smoother2histval/fs2000_simul.mod | 6 +- tests/smoother2histval/fs2000_smooth.mod | 2 +- 29 files changed, 1712 insertions(+), 305 deletions(-) create mode 100644 matlab/histvalf_initvalf.m create mode 100644 tests/histval_initval_file/my_assert.m create mode 100644 tests/histval_initval_file/ramst_data.mod create mode 100644 tests/histval_initval_file/ramst_data.xls create mode 100644 tests/histval_initval_file/ramst_data.xlsx rename tests/{initval_file => histval_initval_file}/ramst_datafile.mod (100%) create mode 100644 tests/histval_initval_file/ramst_histval_file.mod create mode 100644 tests/histval_initval_file/ramst_initval_file.mod create mode 100644 tests/histval_initval_file/ramst_initval_file_data.m create mode 100644 tests/histval_initval_file/sim_exo_lead_lag.mod create mode 100644 tests/histval_initval_file/sim_exo_lead_lag_histvalf.mod create mode 100644 tests/histval_initval_file/sim_exo_lead_lag_initvalf.mod create mode 100644 tests/histval_initval_file/sim_histvalf_stoch_simul.mod create mode 100644 tests/histval_initval_file_unit_tests.m delete mode 100644 tests/initval_file/ramst_initval_file.mod diff --git a/doc/manual/source/the-model-file.rst b/doc/manual/source/the-model-file.rst index 07101fdb6..fb077a848 100644 --- a/doc/manual/source/the-model-file.rst +++ b/doc/manual/source/the-model-file.rst @@ -1769,7 +1769,7 @@ in this case ``initval`` is used to specify the terminal conditions. in the last ``initval`` or ``endval`` block (or the steady state file if you provided one, see :ref:`st-st`). -.. command:: initval_file (filename = FILENAME); +.. command:: initval_file (OPTIONS...); |br| In a deterministic setup, this command is used to specify a path for all endogenous and exogenous variables. The length of @@ -1786,33 +1786,534 @@ in this case ``initval`` is used to specify the terminal conditions. by the path for endogenous variables for the simulation periods (excluding initial and terminal conditions) - The command accepts three file formats: + In perfect foresight and stochastic contexts, ``steady`` uses the + first observation loaded by ``initval_file`` as guess value to + solve for the steady state of the model. This first observation is + determined by the ``first_obs`` option when it is used. + + Don’t mix ``initval_file`` with ``initval`` statements. However, + after ``initval_file``, you can modify the historical initial + values with ``histval`` or ``histval_file`` statement. + + There can be several ``initval_file`` statements in a model + file. Each statement resets ``oo_.initval_series``. + + *Options* + + .. option:: datafile = FILENAME + filename = FILENAME (deprecated) + + The name of the file containing the data. It must be included in quotes if the filename + contains a path or an extension. The command accepts the following file formats: * M-file (extension ``.m``): for each endogenous and exogenous variable, the file must contain a row or column vector of - the same name. Their length must be ``periods + - M_.maximum_lag + M_.maximum_lead`` + the same name. * MAT-file (extension ``.mat``): same as for M-files. * Excel file (extension ``.xls`` or ``.xlsx``): for each - endogenous and exogenous, the file must contain a column of - the same name. NB: Octave only supports the ``.xlsx`` file - extension and must have the `io`_ package installed (easily - done via octave by typing ‘``pkg install -forge io``’). + endogenous and exogenous variable, the file must contain a + column of the same name. NB: Octave only supports the + ``.xlsx`` file extension and must have the `io`_ package + installed (easily done via octave by typing ‘``pkg + install -forge io``’). The first column may contain the date + of each observation. + * CSV files (extension ``.csv``): for each endogenous and + exogenous variable, the file must contain a column of the + same name. The first column may contain the date of each + observation. - .. warning:: The extension must be omitted in the command - argument. Dynare will automatically figure out the - extension and select the appropriate file type. If - there are several files with the same name but different - extensions, then the order of precedence is as follows: - first ``.m``, then ``.mat``, ``.xls`` and finally ``.xlsx``. + .. option:: first_obs = {INTEGER | DATE} + + The observation number or the date (see + :ref:`dates-members`) of the first observation to be used in the file + .. option:: first_simulation_period = {INTEGER | DATE} -.. command:: histval_file (filename = FILENAME); + The observation number in the file or the date (see + :ref:`dates `) at which the simulation (or the forecast) is + starting. This option avoids to have to compute the maximum + number of lags in the model. The observation corresponding to + the first period of simulation doesn’t need to exist in the + file as the only dates necessary for initialization are before + that date. + + .. option:: last_obs = {INTEGER | DATE} + + The observaton number or the date (see + :ref:`dates-members`) of the last observation to be used in + the file. + + .. option:: nobs = INTEGER + + The number of observations to be used in the file (starting + with first of ``first_obs`` observation). + + .. option:: series = DSERIES NAME + + The name of a DSERIES containing the data (see :ref:`dseries-members`) + + *Example 1* + + :: + + var c x; + varexo e; + parameters a b c d; + + a = 1.5; + b = -0,6; + c = 0.5; + d = 0.5; + + model; + x = a*x(-1) + b*x(-2) + e; + log(c) = c*x + d*log(c(+1)); + end; + + initval_file(datafile=mydata.csv); + + perfect_foresight_setup(periods=200); + perfect_foresight_solver; + + The initial and terminal values are taken from file + ``mydata.csv`` (nothing guarantees that these vales are the + steady state of the model). The guess value for the + trajectories are also taken from the file. The file must + contain at least 203 observations of variables ``c``, ``x`` + and ``e``. If there are more than 203 observations available + in the file, the first 203 are used by + ``perfect_foresight_setup(periods=200)``. + Note that the values for the auxiliary variable corresponding + to ``x(-2)`` are automatically computed by ``initval_file``. + + *Example 2* + + :: + + var c x; + varexo e; + parameters a b c d; + + a = 1.5; + b = -0,6; + c = 0.5; + d = 0.5; + + model; + x = a*x(-1) + b*x(-2) + e; + log(c) = c*x + d*log(c(+1)); + end; + + initval_file(datafile=mydata.csv, + first_obs=10); + + perfect_foresight_setup(periods=200); + perfect_foresight_solver; + + The initial and terminal values are taken from file + ``mydata.csv`` starting with the 10th observation in the + file. There must be at least 212 observations in the file. + + *Example 3* + + :: + + var c x; + varexo e; + parameters a b c d; + + a = 1.5; + b = -0,6; + c = 0.5; + d = 0.5; + + model; + x = a*x(-1) + b*x(-2) + e; + log(c) = c*x + d*log(c(+1)); + end; + + ds = dseries(mydata.csv); + lds = log(ds); + + initval_file(series=lds, + first_obs=2010Q1); + + perfect_foresight_setup(periods=200); + perfect_foresight_solver; + + The initial and terminal values are taken from dseries + ``lds``. All observations are loaded starting with the 1st quarter of + 2010 until the end of the file. There must be data available + at least until 2050Q3. + + *Example 4* + + :: + + var c x; + varexo e; + parameters a b c d; + + a = 1.5; + b = -0,6; + c = 0.5; + d = 0.5; + + model; + x = a*x(-1) + b*x(-2) + e; + log(c) = c*x + d*log(c(+1)); + end; + + initval_file(datafile=mydata.csv, + first_simulation_period=2010Q1); + + perfect_foresight_setup(periods=200); + perfect_foresight_solver; + + The initial and terminal values are taken from file + ``mydata.csv``. The observations in the file must have + dates. All observations are loaded from the 3rd quarter of + 2009 until the end of the file. There must be data available + in the file at least until 2050Q1. + + *Example 5* + + :: + + var c x; + varexo e; + parameters a b c d; + + a = 1.5; + b = -0,6; + c = 0.5; + d = 0.5; + + model; + x = a*x(-1) + b*x(-2) + e; + log(c) = c*x + d*log(c(+1)); + end; + + initval_file(datafile=mydata.csv, + last_obs = 212); + + perfect_foresight_setup(periods=200); + perfect_foresight_solver; + + The initial and terminal values are taken from file + ``mydata.csv``. The first 212 observations are loaded and the + first 203 observations will be used by + ``perfect_foresight_setup(periods=200)``. + + *Example 6* + + :: + + var c x; + varexo e; + parameters a b c d; + + a = 1.5; + b = -0,6; + c = 0.5; + d = 0.5; + + model; + x = a*x(-1) + b*x(-2) + e; + log(c) = c*x + d*log(c(+1)); + end; + + initval_file(datafile=mydata.csv, + first_obs = 10, + nobs = 203); + + perfect_foresight_setup(periods=200); + perfect_foresight_solver; + + The initial and terminal values are taken from file + ``mydata.csv``. Observations 10 to 212 are loaded. + + *Example 7* + + :: + + var c x; + varexo e; + parameters a b c d; + + a = 1.5; + b = -0,6; + c = 0.5; + d = 0.5; + + model; + x = a*x(-1) + b*x(-2) + e; + log(c) = c*x + d*log(c(+1)); + end; + + initval_file(datafile=mydata.csv, + first_obs = 10); + + steady; + + The values of the 10th observation of ``mydata.csv`` are used + as guess value to compute the steady state. The exogenous + variables are set to values found in the file or zero if these + variables aren't present. + +.. command:: histval_file (OPTIONS...); |br| This command is equivalent to ``histval``, except that it reads its input from a file, and is typically used in conjunction with ``smoother2histval``. + *Options* + + .. option:: datafile = FILENAME + filename = FILENAME (deprecated) + + The name of the file containing the data. The command accepts + the following file formats: + + * M-file (extension ``.m``): for each endogenous and exogenous + variable, the file must contain a row or column vector of + the same name. + * MAT-file (extension ``.mat``): same as for M-files. + * Excel file (extension ``.xls`` or ``.xlsx``): for each + endogenous and exogenous variable, the file must contain a + column of the same name. NB: Octave only supports the + ``.xlsx`` file extension and must have the `io`_ package + installed (easily done via octave by typing ‘``pkg + install -forge io``’). The first column may contain the + date of each observation. + * CSV files (extension ``.csv``): for each endogenous and + exogenous variable, the file must contain a column of the + same name. The first column may contain the date of each + observation. + + .. option:: first_obs = {INTEGER | DATE} + + The observation number or the date (see :ref:`dates-members`) of + the first observation to be used in the file + + .. option:: first_simulation_period = {INTEGER | DATE} + + The observation number in the file or the date (see + :ref:`dates-members`) at which the simulation (or the forecast) is + starting. This option avoids to have to compute the maximum + number of lags in the model. The observation corresponding to + the first period of simulation doesn’t need to exist in the + file as the only dates necessary for initialization are before + that date. + + .. option:: last_obs = {INTEGER | DATE} + + The observation number or the date (see :ref:`dates-members`) of the + last observation to be used in the file. + + .. option:: nobs = INTEGER + + The number of observations to be used in the file (starting + with first of ``first_obs`` observation). + + .. option:: series = DSERIES NAME + + The name of a DSERIES containing the data (see :ref:`dseries-members`) + + *Example 1* + + :: + + var c x; + varexo e; + parameters a b c d; + + a = 1.5; + b = -0,6; + c = 0.5; + d = 0.5; + + model; + x = a*x(-1) + b*x(-2) + e; + log(c) = c*x + d*log(c(+1)); + end; + + steady_state_model; + x = 0; + c = exp(c*x/(1 - d)); + end; + + histval_file(datafile=mydata.csv); + + stoch_simul(order=1,periods=100); + + The initial values for the stochastic simulation are taken + from the two first rows of file ``mydata.csv``. + + *Example 2* + + :: + + var c x; + varexo e; + parameters a b c d; + + a = 1.5; + b = -0,6; + c = 0.5; + d = 0.5; + + model; + x = a*x(-1) + b*x(-2) + e; + log(c) = c*x + d*log(c(+1)); + end; + + histval_file(datafile=mydata.csv, + first_obs=10); + + stoch_simul(order=1,periods=100); + + The initial values for the stochastic simulation are taken + from rows 10 and 11 of file ``mydata.csv``. + + + *Example 3* + + :: + + var c x; + varexo e; + parameters a b c d; + + a = 1.5; + b = -0,6; + c = 0.5; + d = 0.5; + + model; + x = a*x(-1) + b*x(-2) + e; + log(c) = c*x + d*log(c(+1)); + end; + + histval_file(datafile=mydata.csv, + first_obs=2010Q1); + + stoch_simul(order=1,periods=100); + + The initial values for the stochastic simulation are taken + from observations 2010Q1 and 2010Q2 of file ``mydata.csv``. + + *Example 4* + + :: + + var c x; + varexo e; + parameters a b c d; + + a = 1.5; + b = -0,6; + c = 0.5; + d = 0.5; + + model; + x = a*x(-1) + b*x(-2) + e; + log(c) = c*x + d*log(c(+1)); + end; + + histval_file(datafile=mydata.csv, + first_simulation_period=2010Q1) + + stoch_simul(order=1,periods=100); + + The initial values for the stochastic simulation are taken + from observations 2009Q3 and 2009Q4 of file ``mydata.csv``. + + *Example 5* + + :: + + var c x; + varexo e; + parameters a b c d; + + a = 1.5; + b = -0,6; + c = 0.5; + d = 0.5; + + model; + x = a*x(-1) + b*x(-2) + e; + log(c) = c*x + d*log(c(+1)); + end; + + histval_file(datafile=mydata.csv, + last_obs = 4); + + stoch_simul(order=1,periods=100); + + The initial values for the stochastic simulation are taken + from the two first rows of file ``mydata.csv``. + + *Example 6* + + :: + + var c x; + varexo e; + parameters a b c d; + + a = 1.5; + b = -0,6; + c = 0.5; + d = 0.5; + + model; + x = a*x(-1) + b*x(-2) + e; + log(c) = c*x + d*log(c(+1)); + end; + + initval_file(datafile=mydata.csv, + first_obs = 10, + nobs = 4); + + stoch_simul(order=1,periods=100); + + The initial values for the stochastic simulation are taken + from rows 10 and 11 of file ``mydata.csv``. + + *Example 7* + + :: + + var c x; + varexo e; + parameters a b c d; + + a = 1.5; + b = -0,6; + c = 0.5; + d = 0.5; + + model; + x = a*x(-1) + b*x(-2) + e; + log(c) = c*x + d*log(c(+1)); + end; + + initval_file(datafile=mydata.csv, + first_obs=10); + + histval_file(datafile=myotherdata.csv); + + perfect_foresight_setup(periods=200); + perfect_foresight_solver; + + Historical initial values for the simulation are taken from + the two first rows of file ``myotherdata.csv``. + + Terminal values and guess values for the simulation are taken + from file ``mydata.csv`` starting with the 12th observation in + the file. There must be at least 212 observations in the file. .. _shocks-exo: diff --git a/matlab/global_initialization.m b/matlab/global_initialization.m index 1b35a37e5..8f5f909d5 100644 --- a/matlab/global_initialization.m +++ b/matlab/global_initialization.m @@ -92,6 +92,7 @@ oo_.dr = []; oo_.exo_steady_state = []; oo_.exo_det_steady_state = []; oo_.exo_det_simul = []; +oo_.initval_series = dseries(); oo_.gui.ran_estimation = false; oo_.gui.ran_stoch_simul = false; diff --git a/matlab/histvalf.m b/matlab/histvalf.m index f1f9fb098..f15e72511 100644 --- a/matlab/histvalf.m +++ b/matlab/histvalf.m @@ -1,5 +1,5 @@ -function histvalf(fname) -%function histvalf(fname) +function [endo_histval, exo_histval, exo_det_histval] = histvalf(M, options) +%function [endo_histval, exo_histval, exo_det_histval] = histvalf(M, options) % Sets initial values for simulation using values contained in `fname`, a % file possibly created by a call to `smoother2histval` % @@ -13,7 +13,7 @@ function histvalf(fname) % none -% Copyright (C) 2014-2019 Dynare Team +% Copyright (C) 2014-2020 Dynare Team % % This file is part of Dynare. % @@ -30,72 +30,41 @@ function histvalf(fname) % You should have received a copy of the GNU General Public License % along with Dynare. If not, see . -global M_ oo_ ex0_ - -if ~exist(fname, 'file') - error(['Can''t find datafile: ' fname ]); +if ~isfield(options, 'nobs') || isempty(options.nobs) + options.nobs = M.orig_maximum_lag; end -M_.endo_histval = repmat(oo_.steady_state, 1, M_.maximum_endo_lag); - -% Also fill in oo_.exo_simul: necessary if we are in deterministic context, -% since aux vars for lagged exo are not created in this case -if isempty(oo_.exo_simul) - if isempty(ex0_) - oo_.exo_simul = repmat(oo_.exo_steady_state',M_.maximum_lag,1); +if ~isfield(options, 'first_obs') || isempty(options.first_obs) + if isfield(options, 'first_simulation_period') + options.first_obs = options.first_simulation_period ... + - options.nobs; else - oo_.exo_simul = repmat(ex0_',M_.maximum_lag,1); + options.first_obs = 1; + end +elseif isfield(options, 'first_simulation_period') + nobs = options.first_simulation_period - opions_.first_obs; + if options.nobs ~= nobs + error(sprintf(['HISTVALF: first_obs = %d and', ... + ' first_simulation_period = %d', ... + ' don''t provide for the number of' ... + ' lags in the model.'], ... + options.first_obs, ... + options.first_simulation_period)) end end -S = load(fname); +series = histvalf_initvalf('HISTVAL', M, options); +% capture the difference between stochastic and +% perfect foresight setup +k = M.orig_maximum_lag - M.maximum_lag + 1; +endo_histval = series{M.endo_names{:}}.data(k:end, :)'; -outvars = fieldnames(S); - -for i = 1:length(outvars) - ov_ = outvars{i}; - if ov_(end) == '_' - ov = ov_(1:end-1); - j = strmatch(ov, M_.endo_names, 'exact'); - if isempty(j) - warning(['smoother2histval: output variable ' ov ' does not exist.']) - end - else - % Lagged endogenous or exogenous, search through aux vars - undidx = find(ov_ == '_', 1, 'last'); % Index of last underscore in name - ov = ov_(1:(undidx-1)); - lead_lag = ov_((undidx+1):end); - lead_lag = regexprep(lead_lag,'l','-'); - lead_lag = str2num(lead_lag); - j = []; - for i = 1:length(M_.aux_vars) - if M_.aux_vars(i).type ~= 1 && M_.aux_vars(i).type ~= 3 - continue - end - if M_.aux_vars(i).type == 1 - % Endogenous - orig_var = M_.endo_names{M_.aux_vars(i).orig_index}; - else - % Exogenous - orig_var = M_.exo_names{M_.aux_vars(i).orig_index}; - end - if strcmp(orig_var, ov) && M_.aux_vars(i).orig_lead_lag == lead_lag - j = M_.aux_vars(i).endo_index; - end - end - if isempty(j) - % There is no aux var corresponding to (orig_var, lead_lag). - % If this is an exogenous variable, then it means we should put - % the value in oo_.exo_simul (we are probably in deterministic - % context). - k = strmatch(ov, M_.exo_names); - if isempty(k) - warning(['smoother2histval: output variable ' ov '(' lead_lag ') does not exist.']) - else - oo_.exo_simul((M_.maximum_lag-M_.maximum_endo_lag+1):M_.maximum_lag, k) = S.(ov_); - end - continue - end - end - M_.endo_histval(j, :) = S.(ov_); +exo_histval = []; +if M.exo_nbr + exo_histval = series{M.exo_names{:}}.data(k:end, :)'; end +exo_det_histval = []; +if M.exo_det_nbr + exo_det_histval = series{M.exo_names{:}}.data(k:end, :)'; +end + diff --git a/matlab/histvalf_initvalf.m b/matlab/histvalf_initvalf.m new file mode 100644 index 000000000..e65779c49 --- /dev/null +++ b/matlab/histvalf_initvalf.m @@ -0,0 +1,223 @@ +function series = histvalf_initvalf(caller, M, options) +% function initvalf(M) +% +% handles options for histvalf_initvalf() and initvalf() +% +% INPUTS +% caller: string, name of calling function +% M: model structure +% options: options specific to initivalf +% +% OUTPUTS +% series: dseries containing selected data from a file or a dseries +% + +% Copyright (C) 2003-2020 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 . + + +% dseries +if isfield(options, 'series') + series = options.series; + dseries_ispresent = true; +else + dseries_ispresent = false; +end + +% file +datafile = ''; +if isfield(options, 'filename') + warning([caller, '_FILE: option FILENAME is deprecated, please use', ... + ' option DATAFILE']) + if dseries_ispresent + error([caller, '_FILE: you can''t use option FILENAME and option SERIES', ... + ' at the same time']) + end + if isfield(options, 'datafile') + error([caller, '_FILE: you can''t use option DATAFILE and option FILENAME', ... + ' at the same time']) + end + datafile = options.filename; +end + +if isfield(options, 'datafile') + if dseries_ispresent + error([caller, '_FILE: you can''t use option DATAFILE and option SERIES', ... + ' at the same time']) + end + datafile = options.datafile; +end + +if datafile + [directory,basename,extension] = fileparts(datafile); + % Auto-detect extension if not provided + if isempty(extension) + if exist([basename '.m'],'file') + extension = '.m'; + elseif exist([basename '.mat'],'file') + extension = '.mat'; + elseif exist([basename '.xls'],'file') + extension = '.xls'; + elseif exist([basename '.xlsx'],'file') + extension = '.xlsx'; + else + error([caller, '_FILE: Can''t find datafile: ' basename '.{m,mat,xls,xlsx}']); + end + end + + fullname = [basename extension]; + series = dseries(fullname); +end + +% checking that all variable are present +error_flag = false; +for i = 1:M.orig_endo_nbr + if ~series.exist(M.endo_names{i}) + disp(sprintf('%s_FILE: endogenous variable %s is missing', ... + caller, M.endo_names{i})) + error_flag = true; + end +end + +for i = 1:M.exo_nbr + if ~series.exist(M.exo_names{i}) + disp(sprintf('%s_FILE: exogenous variable %s is missing', ... + caller, M.exo_names{i})) + error_flag = true; + end +end + +for i = 1:M.exo_det_nbr + if ~series.exist(M.exo_det_names{i}) + disp(sprintf('%s_FILE: exo_det variable %s is missing', ... + caller, M.exo_det_names{i})) + error_flag = true; + end +end + +if error_flag + error([caller, '_FILE: some variables are missing']) +end + +if exist(sprintf('+%s/dynamic_set_auxiliary_series', M.fname), 'file') + series = feval(sprintf('%s.dynamic_set_auxiliary_series', M.fname), series, M.params); +end + +% selecting observations +if isfield(options, 'nobs') + nobs = options.nobs; +else + nobs = 0; +end + +periods = series.dates; +nobs0 = series.nobs; + +first_obs_ispresent = false; +last_obs_ispresent = false; +if isfield(options, 'first_obs') + i = options.first_obs; + if i < 1 + error([caller, '_FILE: the first requested period is before available', ... + ' data.']) + elseif i > nobs0 + error([caller, '_FILE: the first requested period is after available', ... + ' data.']) + end + first_obs = periods(i); + if nobs > 0 + last_obs = first_obs + nobs - 1; + last_obs_ispresent = true; + end + first_obs_ispresent = true; +elseif isfield(options, 'firstobs') + first_obs = options.firstobs; + if nobs > 0 + last_obs = first_obs + nobs - 1; + last_obs_ispresent = true; + end + first_obs_ispresent = true; +end + +if last_obs_ispresent + if isfield(options, 'last_obs') + i = options.last_obs; + if i < 1 + error([caller, '_FILE: the last requested period is before available', ... + ' data.']) + elseif i > nobs0 + error([caller, '_FILE: the last requested period is after available', ... + ' data.']) + end + if last_obs ~= periods(i) + error([caller, '_FILE: FIST_OBS, LAST_OBS and NOBS contain', ... + ' inconsistent information. Use only two of these', ... + ' options.']) + end + elseif isfield(options, 'lastobs') + if last_obs ~= options.lastobs + error([caller, '_FILE: FIST_OBS, LAST_OBS and NOBS contain', ... + ' inconsistent information. Use only two of these', ... + ' options.']) + end + end +elseif isfield(options, 'last_obs') + i = options.last_obs; + if i < 1 + error([caller, '_FILE: the last requested period is before available', ... + ' data.']) + elseif i > nobs0 + error([caller, '_FILE: the last requested period is after available', ... + ' data.']) + end + last_obs = periods(i); + if nobs > 0 + first_obs = last_obs - nobs + 1; + first_obs_ispresent = true; + end + last_obs_ispresent = true; +elseif isfield(options, 'lastobs') + last_obs = options.lastobs; + if nobs > 0 + first_obs = last_obs - nobs + 1; + first_obs_ispresent = true; + end + last_obs_ispresent = true; +end + +if ~first_obs_ispresent + first_obs = periods(1); +end + +if ~last_obs_ispresent + if nobs > 0 + last_obs = first_obs + nobs - 1; + else + last_obs = periods(end); + end +end + +if first_obs < series.init + error([caller, '_FILE: the first requested period is before available', ... + ' data.']) +elseif last_obs > series.last + error([caller, '_FILE: the last requested period is after available', ... + ' data.']) +else + series = series(first_obs:last_obs); +end + diff --git a/matlab/initvalf.m b/matlab/initvalf.m index f301e045f..17a5ff54a 100644 --- a/matlab/initvalf.m +++ b/matlab/initvalf.m @@ -1,19 +1,18 @@ -function initvalf(fname_) -% function initvalf(fname_) +function series = initvalf(M, options) +% function initvalf(M) % -% Reads an initial path from the 'fname_' file for exogenous and endogenous variables +% handles options for histvalf() and initvalf() % % INPUTS -% fname_: name of the function or file containing the data +% caller: string, name of calling function +% M: model structure +% options: options specific to initivalf % % OUTPUTS -% none +% series: dseries containing selected data from a file or a dseries % -% SPECIAL REQUIREMENTS -% All variables local to this function have an underscore appended to -% their name, to minimize clashes with model variables loaded by this function. -% Copyright (C) 2003-2018 Dynare Team +% Copyright (C) 2003-2020 Dynare Team % % This file is part of Dynare. % @@ -30,81 +29,6 @@ function initvalf(fname_) % You should have received a copy of the GNU General Public License % along with Dynare. If not, see . -global M_ oo_ options_ +series = histvalf_initvalf('INITVALF', M, options); -series_ = 1; -[directory,basename,extension] = fileparts(fname_); - -% Auto-detect extension if not provided -if isempty(extension) - if exist([basename '.m'],'file') - extension = '.m'; - elseif exist([basename '.mat'],'file') - extension = '.mat'; - elseif exist([basename '.xls'],'file') - extension = '.xls'; - elseif exist([basename '.xlsx'],'file') - extension = '.xlsx'; - else - error(['Can''t find datafile: ' basename '.{m,mat,xls,xlsx}']); - end -end - -fullname = [basename extension]; - -if ~exist(fullname) - error(['Can''t find datafile: ' fullname ]); -end - -switch (extension) - case '.m' - eval(basename); - case '.mat' - load(basename); - case { '.xls', '.xlsx' } - [data_,names_v_]=xlsread(fullname); % Octave needs the extension explicitly - series_=0; - otherwise - error(['Unsupported extension for datafile: ' extension]) -end - -options_.initval_file = true; -oo_.endo_simul = []; -oo_.exo_simul = []; - -for i_=1:length(M_.endo_names) - if series_ == 1 - x_ = eval(M_.endo_names{i_}); - if size(x_,2)>size(x_,1) %oo_.endo_simul must be collection of row vectors - oo_.endo_simul = [oo_.endo_simul; x_]; - else %transpose if column vector - oo_.endo_simul = [oo_.endo_simul; x_']; - end - else - k_ = strmatch(M_.endo_names{i_}, names_v_, 'exact'); - if isempty(k_) - error(['INITVAL_FILE: ' M_.endo_names{i_} ' not found']) - end - x_ = data_(:,k_); - oo_.endo_simul = [oo_.endo_simul; x_']; - end -end - -for i_=1:length(M_.exo_names) - if series_ == 1 - x_ = eval(M_.exo_names{i_}); - if size(x_,2)>size(x_,1) %oo_.endo_simul must be collection of row vectors - oo_.exo_simul = [oo_.exo_simul x_']; - else %if column vector - oo_.exo_simul = [oo_.exo_simul x_]; - end - else - k_ = strmatch(M_.exo_names{i_}, names_v_, 'exact'); - if isempty(k_) - error(['INITVAL_FILE: ' M_.exo_names{i_} ' not found']) - end - x_ = data_(:,k_); - oo_.exo_simul = [oo_.exo_simul x_]; - end -end diff --git a/matlab/perfect-foresight-models/make_ex_.m b/matlab/perfect-foresight-models/make_ex_.m index 4f7259048..909ba238d 100644 --- a/matlab/perfect-foresight-models/make_ex_.m +++ b/matlab/perfect-foresight-models/make_ex_.m @@ -41,17 +41,33 @@ if M_.exo_det_nbr > 1 && isempty(oo_.exo_det_steady_state) end % Initialize oo_.exo_simul -if isempty(M_.exo_histval) - if isempty(ex0_) - oo_.exo_simul = repmat(oo_.exo_steady_state',M_.maximum_lag+options_.periods+M_.maximum_lead,1); +if isempty(oo_.initval_series) + if isempty(M_.exo_histval) + if isempty(ex0_) + oo_.exo_simul = repmat(oo_.exo_steady_state',M_.maximum_lag+options_.periods+M_.maximum_lead,1); + else + oo_.exo_simul = [ repmat(ex0_',M_.maximum_lag,1) ; repmat(oo_.exo_steady_state',options_.periods+M_.maximum_lead,1) ]; + end else - oo_.exo_simul = [ repmat(ex0_',M_.maximum_lag,1) ; repmat(oo_.exo_steady_state',options_.periods+M_.maximum_lead,1) ]; + if isempty(ex0_) + oo_.exo_simul = [M_.exo_histval'; repmat(oo_.exo_steady_state',options_.periods+M_.maximum_lead,1)]; + else + error('histval and endval cannot be used simultaneously') + end end -else - if isempty(ex0_) - oo_.exo_simul = [M_.exo_histval'; repmat(oo_.exo_steady_state',options_.periods+M_.maximum_lead,1)]; - else - error('histval and endval cannot be used simultaneously') +elseif M_.exo_nbr > 0 + x = oo_.initval_series{M_.exo_names{:}}.data; + oo_.exo_simul = x(1:M_.maximum_lag + options_.periods + M_.maximum_lead,:); + if ~isempty(M_.exo_histval) + oo_.exo_simul(1:M_.maximum_lag, :) ... + = M_.exo_histval(:, 1:M_.maximum_lag)'; + end +elseif M_.exo_det_nbr > 0 + x_det = oo_.initval_series{M_.exo_det_names{:}}.data; + oo_.exo_det_simul = x_det(1:M_.maximum_lag + options_.periods + M_.maximum_lead,:); + if ~isempty(M_.exo_det_histval) + oo_.exo_det_simul(1:M_.maximum_lag, :) ... + = M_.exo_det_histval(:, 1:M_.maximum_lag)'; end end diff --git a/matlab/perfect-foresight-models/make_y_.m b/matlab/perfect-foresight-models/make_y_.m index abd48a84f..d36dd746c 100644 --- a/matlab/perfect-foresight-models/make_y_.m +++ b/matlab/perfect-foresight-models/make_y_.m @@ -45,18 +45,31 @@ if isempty(oo_.steady_state) oo_.steady_state = zeros(M_.endo_nbr,1); end -if isempty(M_.endo_histval) - if isempty(ys0_) - oo_.endo_simul = repmat(oo_.steady_state, 1, M_.maximum_lag+options_.periods+M_.maximum_lead); +if isempty(oo_.initval_series) + if isempty(M_.endo_histval) + if isempty(ys0_) + oo_.endo_simul = repmat(oo_.steady_state, 1, M_.maximum_lag+options_.periods+M_.maximum_lead); + else + oo_.endo_simul = [repmat(ys0_, 1, M_.maximum_lag) repmat(oo_.steady_state, 1,options_.periods+M_.maximum_lead)]; + end else - oo_.endo_simul = [repmat(ys0_, 1, M_.maximum_lag) repmat(oo_.steady_state, 1,options_.periods+M_.maximum_lead)]; + if ~isempty(ys0_) + error('histval and endval cannot be used simultaneously') + end + % the first NaNs take care of the case where there are lags > 1 on + % exogenous variables + oo_.endo_simul = [M_.endo_histval ... + repmat(oo_.steady_state, 1, options_.periods+M_.maximum_lead)]; end else - if ~isempty(ys0_) - error('histval and endval cannot be used simultaneously') + y = oo_.initval_series{M_.endo_names{:}}.data; + oo_.endo_simul = y(1:M_.maximum_lag + options_.periods + ... + M_.maximum_lead, :)'; + if ~isempty(M_.endo_histval) + if ~isempty(ys0_) + error('histval and endval cannot be used simultaneously') + end + oo_.endo_simul(:,1:M_.maximum_lag) ... + = M_.endo_histval(:, 1:M_.maximum_lag); end - % the first NaNs take care of the case where there are lags > 1 on - % exogenous variables - oo_.endo_simul = [M_.endo_histval ... - repmat(oo_.steady_state, 1, options_.periods+M_.maximum_lead)]; -end +end \ No newline at end of file diff --git a/matlab/perfect-foresight-models/perfect_foresight_setup.m b/matlab/perfect-foresight-models/perfect_foresight_setup.m index 45f6f2789..98d8e12fc 100644 --- a/matlab/perfect-foresight-models/perfect_foresight_setup.m +++ b/matlab/perfect-foresight-models/perfect_foresight_setup.m @@ -64,7 +64,6 @@ if ~isempty(M_.det_shocks) && options_.periodsf zsIf)sqpC$|dt20PLs9p(>b~z<>m+&4URv$f=X;*sug9}a&iSA7J8Pf4*LwHLiR8me zWp8iDsd$H(UD~n|?3WjItYop=0&dqb-FIZH2HeK%mlrQym}0p3_vJ6N2cD~KEddA6 z3Ys-EJmxmgY@yjfvxim+T4`uypgBO}&|nC#ve2BMm4o&gG-qh#p}h{R0<<@vRfJXv zT4iWepjCxd4VnwI>d=HDEE2v(v#D?dUj0%YMojS? z@G7!+y?B-9|JHN9!$UqBnd z#$j#f5*Qxj@_%*dEVd!g0=FR_PBQJ`mIX_L)Pe05=}~drUQ{1=k|%R%1z+%t^w`2v zZ2LlST|-!T1klfh?SvJql0wvmUK#RhngD zeeE6`85|uLep}SdO!nl33-n^TF>O(xw!+GBp&i}S>Ubp=bPW?Z_ zSsv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i6m*{=W6!xCboY=$C-$kMGUV)>4fAd~waXRf4bHp+V766QV}PxOANo6ddl-x~0d! zz>&e>;lbipE<1;g9^Fbl{f}M4_>-OfF%Dag71a0=IIeFetbg>ceq$WBFR^8Ab@pAy z>N*`77E62_H{1@ICp4^peV~_wps~4`OHK^p6x)QeE{a?GhAhR~hMnF~p8onQFc*a1B+xoH`9xlB6 znScL9^lvtX3Og!xqbAHj|us4Tbu literal 0 HcmV?d00001 diff --git a/tests/histval_initval_file/ramst_data.xlsx b/tests/histval_initval_file/ramst_data.xlsx new file mode 100644 index 0000000000000000000000000000000000000000..849953eacbb225829a8e34b0440042e1e9f7d238 GIT binary patch literal 8575 zcmaJ`2|U#8_E(a9%QCW-Y*`wSBuWt?TQtVLn`GY^Ymy~<){#(%%oy7w+c0GfV<}q_ zvTxa!vHSl<_r7)C`@ioqpU;?c<~iHOnzoK@l0!`6OJ9Zk$gkF006A_}%fY)AHD^uh^GQ%edKl*7FzO;0Mz zd>)5p$BPk!l);i%My;+px{z1wnl%n!?;Sr)3ZZ_Z(jO778I=z((FmNUTvfPRhCI{E z)1pInnMw-fxI=7$#$3B?--pkFw(=y}_sA(=$R`y)fUspxk^uDo0)`RTVeM?C?dI&_ z4z_Z3v$^Es=-~LgL$g7g;pwuR(xl(`DZZ!Ke96~bvd`!gH1>TR>TL=ttI*inx<)Cb zH2Gd~5ALvh6@}3or1X#Pf0rw)mJmFqcekg)dhakn{<-Km$tM@>U-5$|tow$gzW06i z^;z!^R-rr}bz7kKd%1PoteqO^Xb9|e#M5UT8JjOGlIrqfSHbmuCBz&s`%UW2ZT7$ii}9!-%DeBG2ojE#Noh6wMxhWp~{caA6Cx^g(oQ zA4Ucino0LS-5)jIcRgov!KdSf_`5p$S#(7C;}5kSY$`XUkJ#>uz;>-(YLN?!ItlO@ zOiZ#+SH{YIQ)TE%MU?(fYHv`D^;>LvcGnHd%PCL)!L?5QnSRb4GE9Kj(PH)9X(GyE z?a@hsCrC)7{}E+|KT)=D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6~<6{ 1e-8 + error('Simulation with leads and lags doesn''t match the one with auxiliary variables') +end + +data1 = repmat([oo_.steady_state' 1], 6, 1); +ds1 = dseries(data1, '1Y', [M_.endo_names; M_.exo_names]); + +histval_file(series = ds1, first_obs = 3, last_obs = 6, nobs = 4); + +perfect_foresight_setup(periods=200); +perfect_foresight_solver; + +if ~oo_.deterministic_simulation.status + error('Perfect foresight simulation failed'); +end + +if max(max(abs(reference(1:5,:) - oo_.endo_simul(1:5,:)))) > 1e-8 + error('Simulation with leads and lags doesn''t match the one with auxiliary variables') +end diff --git a/tests/histval_initval_file/sim_exo_lead_lag_initvalf.mod b/tests/histval_initval_file/sim_exo_lead_lag_initvalf.mod new file mode 100644 index 000000000..e74b6c9b2 --- /dev/null +++ b/tests/histval_initval_file/sim_exo_lead_lag_initvalf.mod @@ -0,0 +1,56 @@ +// Uses autonomous system from sim_base.mod, but adds separate system where exogenous variables have several leads and lags +// Lags and leads on exogenous variables are substituted out by auxiliary variables + +data1 = repmat([1.2, 1.2, 12, 1, 1, 1], 208, 1); +data1(6, 6) = 0.9; //shock to x in period 2 +ds = dseries(data1, '1Y', {'c', 'cmav', 'k', 'z_backward', 'z_forward', 'x'}); + +var c cmav k z_backward z_forward; +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); + z_backward=0.1*1+0.9*z_backward(-1) + (x(-4) - 1); + z_forward=0.2*1+0.8*z_forward(+1) + (x(+4) - 1); + cmav = 0.2*(c(-2) + c(-1) + c + c(+1) + c(+2)); +end; + +initval_file(series = ds); + +perfect_foresight_setup(periods=200); +perfect_foresight_solver(maxit=100); + +if ~oo_.deterministic_simulation.status + error('Perfect foresight simulation failed'); +end + +base_results=load('sim_exo_lead_lag_results.mat'); +if max(max(abs(base_results.oo_.endo_simul(1:5,:) - oo_.endo_simul(1:5,:)))) > 1e-8 + error('Simulation with leads and lags doesn''t match the one with auxiliary variables') +end + +data1 = repmat([1.2, 1.2, 12, 1, 1, 1], 212, 1); +data1(8, 6) = 0.9; //shock to x in period 2 +ds1 = dseries(data1, '1Y', {'c', 'cmav', 'k', 'z_backward', 'z_forward', 'x'}); + +initval_file(series = ds1, first_obs = 3, last_obs = 210, nobs = 208); + +perfect_foresight_setup(periods=200); +perfect_foresight_solver(maxit=100); + +if ~oo_.deterministic_simulation.status + error('Perfect foresight simulation failed'); +end + +base_results=load('sim_exo_lead_lag_results.mat'); +if max(max(abs(base_results.oo_.endo_simul(1:5,:) - oo_.endo_simul(1:5,:)))) > 1e-8 + error('Simulation with leads and lags doesn''t match the one with auxiliary variables') +end diff --git a/tests/histval_initval_file/sim_histvalf_stoch_simul.mod b/tests/histval_initval_file/sim_histvalf_stoch_simul.mod new file mode 100644 index 000000000..924a5f002 --- /dev/null +++ b/tests/histval_initval_file/sim_histvalf_stoch_simul.mod @@ -0,0 +1,86 @@ +// Uses autonomous system from sim_base.mod, but adds separate system where exogenous variables have several leads and lags +// Lags and leads on exogenous variables are substituted out by auxiliary variables + +var c cmav k z_backward z_forward; +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); + z_backward=0.1*1+0.9*z_backward(-1) + (x(-4) - 1); + z_forward=0.2*1+0.8*z_forward(+1) + (x(+4) - 1); + cmav = 0.2*(c(-2) + c(-1) + c + c(+1) + c(+2)); +end; + +initval; + x = 1; +end; + +steady_state_model; + k = ((bet + delt)/(aa*alph*x))^(1/(alph - 1)); + c = aa*x*k^alph - delt*k; + z_backward = x; + z_forward = x; + cmav = c; +end; + +steady; + +shocks; + var x; + stderr 0.01; +end; + +s = rng; +stoch_simul(periods=20, drop=0, irf=0); + +reference = oo_.endo_simul; + +data1 = repmat([oo_.steady_state' 1], 4, 1); +ds = dseries(data1, '1Y', [M_.endo_names; M_.exo_names]); + +histval_file(series = ds); + +rng(s); +stoch_simul(periods=20, drop=0, irf=0); + +if max(max(abs(reference(1:5,5:end) - oo_.endo_simul(1:5,5:end)))) > 1e-8 + error('Simulation with leads and lags doesn''t match the reference') +end + +data1 = repmat([oo_.steady_state' 1], 6, 1); +ds1 = dseries(data1, '1Y', [M_.endo_names; M_.exo_names]); + +histval_file(series = ds1, first_obs = 6, last_obs = 6, nobs = 1); + +rng(s); +stoch_simul(periods=20, drop=0, irf=0); + +if max(max(abs(reference(1:5,:) - oo_.endo_simul(1:5,:)))) > 1e-8 + error('Simulation with leads and lags doesn''t match the reference') +end + +histval_file(series = ds1, first_simulation_period = 7); + +rng(s); +stoch_simul(periods=20, drop=0, irf=0); + +if max(max(abs(reference(1:5,:) - oo_.endo_simul(1:5,:)))) > 1e-8 + error('Simulation with leads and lags doesn''t match the reference') +end + +histval_file(series = ds1, first_simulation_period = 7Y); + +rng(s); +stoch_simul(periods=20, drop=0, irf=0); + +if max(max(abs(reference(1:5,:) - oo_.endo_simul(1:5,:)))) > 1e-8 + error('Simulation with leads and lags doesn''t match the reference') +end diff --git a/tests/histval_initval_file_unit_tests.m b/tests/histval_initval_file_unit_tests.m new file mode 100644 index 000000000..4b81f71de --- /dev/null +++ b/tests/histval_initval_file_unit_tests.m @@ -0,0 +1,220 @@ +top_test_dir = getenv('TOP_TEST_DIR'); +addpath([top_test_dir filesep '..' filesep 'matlab/']); +dynare_config; + +cd('histval_initval_file'); +num_tests = 0; +failed_tests = {}; + +ds = dseries(randn(10,4)); + +M = struct(); +M.fname = ''; +M.endo_nbr = 3; +M.orig_endo_nbr = 3; +M.endo_names = {'Variable_1','Variable_2','Variable_3'}; +M.exo_nbr = 1; +M.exo_names = {'Variable_4'}; +M.exo_det_nbr = 0; + +caller = 'INITVAL'; + +options = struct(); +options.series = ds; +ds1 = histvalf_initvalf(caller, M, options); + +failed_tests = my_assert(failed_tests, all(all(ds1 == ds)), 'basic test'); +num_tests = num_tests + 1; + +options = struct(); +options.series = ds; +options.first_obs = 2; +ds1 = histvalf_initvalf(caller, M, options); +failed_tests = my_assert(failed_tests, ds1.init == dates('2Y'), ... + 'init test 1'); +num_tests = num_tests + 1; + +options = struct(); +options.series = ds; +options.first_obs = 2; +options.last_obs = 9; +ds1 = histvalf_initvalf(caller, M, options); +failed_tests = my_assert(failed_tests, ds1.init == dates('2Y'), ... + 'first_obs last_obs test 1'); +failed_tests = my_assert(failed_tests, ds1.last == dates('9Y'), ... + 'first_obs last_obs test 2'); +num_tests = num_tests + 2; + +options = struct(); +options.series = ds; +options.last_obs = 9; +ds1 = histvalf_initvalf(caller, M, options); +failed_tests = my_assert(failed_tests, ds1.init == dates('1Y'), ... + 'last_obs test 1'); +failed_tests = my_assert(failed_tests, ds1.last == dates('9Y'), ... + 'last_obs test 2'); +num_tests = num_tests + 2; + +options = struct(); +options.series = ds; +options.first_obs = 2; +options.last_obs = 9; +options.nobs = 8; +ds1 = histvalf_initvalf(caller, M, options); +failed_tests = my_assert(failed_tests, ds1.init == dates('2Y'), ... + 'first_obs, last_obs, nobs test 1'); +failed_tests = my_assert(failed_tests, ds1.last == dates('9Y'), ... + 'first_obs, last_obs, nobs test 2'); +num_tests = num_tests + 2; + +options = struct(); +options.series = ds; +options.last_obs = 9; +options.nobs = 8; +ds1 = histvalf_initvalf(caller, M, options); +failed_tests = my_assert(failed_tests, ds1.init == dates('2Y'), ... + 'last_obs, nobs test 1'); +failed_tests = my_assert(failed_tests, ds1.last == dates('9Y'), ... + 'last_obs, nobs test 2'); +num_tests = num_tests + 2; + +options = struct(); +options.series = ds; +options.first_obs = 2; +options.last_obs = 9; +options.nobs = 7; + +try + ds1 = histvalf_initvalf(caller, M, options); + error('This test didn''t catch the error') +catch me + if strcmp(me.message, ['INITVAL_FILE: FIST_OBS, LAST_OBS and NOBS contain', ... + ' inconsistent information. Use only two of these', ... + ' options.']) == false + failed_tests = cat(1, failed_tests, 'Wrong nobs error message' ); + end +end +num_tests = num_tests + 1; + +options = struct(); +options.series = ds; +options.first_obs = -1; + +try + ds1 = histvalf_initvalf(caller, M, options); + error('This test didn''t catch the error') +catch me + if strcmp(me.message, [caller, '_FILE: the first requested period is', ... + ' before available data.']) == false + failed_tests = cat(1, failed_tests, ... + 'Wrong first period error message'); + end +end +num_tests = num_tests + 1; + +options = struct(); +options.series = ds; +options.last_obs = 11; + +try + ds1 = histvalf_initvalf(caller, M, options); + error('This test didn''t catch the error') +catch me + if strcmp(me.message, [caller, '_FILE: the last requested period is', ... + ' after available data.']) == false + failed_tests = cat(1, failed_tests, ... + 'Wrong last period error message'); + end +end +num_tests = num_tests + 1; + +fh = fopen('data.m', 'w'); +init__ = 'INIT__ = ''1Y'';'; +fprintf(fh, [init__ '\n']); +eval(init__); +names__ = 'NAMES__ = {''x'', ''y''};'; +fprintf(fh, [names__ '\n']); +eval(names__); +tex__ = 'TEX__ = {''x'', ''y''};'; +fprintf(fh, [tex__ '\n']); +eval(tex__); +x = randn(10, 1); +fprintf(fh, 'x = ['); +fprintf(fh, '%f ', x); +fprintf(fh, '];\n'); +y = randn(10, 1); +fprintf(fh, 'y = ['); +fprintf(fh, '%f ', y); +fprintf(fh, '];\n'); +fclose(fh); + +M.endo_nbr = 1; +M.orig_endo_nbr = 1; +M.endo_names = {'y'}; +M.exo_nbr = 1; +M.exo_names = {'x'}; +M.exo_det_nbr = 0; + +options = struct(); +options.datafile = 'data.m'; +series = histvalf_initvalf('INITVAL_FILE', M, options); +failed_tests = my_assert(failed_tests, series.init == dates('1Y'), ... + '*.m file first_obs test'); +failed_tests = my_assert(failed_tests, series.nobs == 10, ... + '*.m file nobs test'); + +save('data.mat', 'INIT__', 'NAMES__', 'TEX__', 'x', 'y'); +options = struct(); +options.datafile = 'data.mat'; +series = histvalf_initvalf('INITVAL_FILE', M, options); +failed_tests = my_assert(failed_tests, series.init == dates('1Y'), ... + '*.mat file first_obs test'); +failed_tests = my_assert(failed_tests, series.nobs == 10, ... + '*.mat file nobs test'); + +fh = fopen('data.csv', 'w'); +fprintf(fh, 'x,y\n'); +for i = 1:size(x,1) + fprintf(fh, '%f,%f\n', x(i), y(i)); +end +fclose(fh); + +if ~verLessThan('matlab', '8.2') + writetable(table(x,y), 'data.xlsx') + options = struct(); + options.datafile = 'data.xlsx'; + series = histvalf_initvalf('INITVAL_FILE', M, options); + failed_tests = my_assert(failed_tests, series.init == dates('1Y'), ... + '*.xlsx file first_obs test'); + failed_tests = my_assert(failed_tests, series.nobs == 10, ... + '*.xlsx file nobs test'); + num_tests = num_tests + 2; + + if ispc + writetable(table(x,y), 'data.xls') + options = struct(); + options.datafile = 'data.xls'; + series = histvalf_initvalf('INITVAL_FILE', M, options); + failed_tests = my_assert(failed_tests, series.init == dates('1Y'), ... + '*.xls file first_obs test'); + failed_tests = my_assert(failed_tests, series.nobs == 10, ... + '*.xls file nobs test'); + num_tests = num_tests + 2; + end +end + +cd(getenv('TOP_TEST_DIR')); +fid = fopen('histval_initval_file_unit_tests.m.trs', 'w+'); +num_failed_tests = length(failed_tests) +if num_failed_tests > 0 + fprintf(fid,':test-result: FAIL\n'); + fprintf(fid,':number-tests: %d\n', num_tests); + fprintf(fid,':number-failed-tests: %d\n', num_failed_tests); + fprintf(fid,':list-of-failed-tests: %s\n', failed_tests{:}); +else + fprintf(fid,':test-result: PASS\n'); + fprintf(fid,':number-tests: %d\n', num_tests); + fprintf(fid,':number-failed-tests: 0\n'); +end +fclose(fid); +exit; diff --git a/tests/initval_file/ramst_initval_file.mod b/tests/initval_file/ramst_initval_file.mod deleted file mode 100644 index 2cc8f91ed..000000000 --- a/tests/initval_file/ramst_initval_file.mod +++ /dev/null @@ -1,55 +0,0 @@ -/* Test for the initval_file() command. This file needs ramst_initval_file_data.m. It should give results similar to those of ramst.mod */ - -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; - -initval_file(filename = ramst_initval_file_data_row_vec_mat); -if oo_.exo_simul(2) ~= 1.2 - error('initval_file problem with exogenous variable'); -end -if oo_.endo_simul(2, 2) ~= 13 - error('initval_file option problem with endogenous variable'); -end -perfect_foresight_setup(periods=200); -perfect_foresight_solver; - -oo_.exo_simul = []; -oo_.endo_simul = []; - -initval_file(filename = ramst_initval_file_data_col_vec_mat); -if oo_.exo_simul(2) ~= 1.2 - error('initval_file problem with exogenous variable'); -end -if oo_.endo_simul(2, 2) ~= 13 - error('initval_file problem with endogenous variable'); -end - -perfect_foresight_setup(periods=200); -perfect_foresight_solver; - -if ispc() - initval_file(filename = ramst_initval_file_excel); - perfect_foresight_setup(periods=200); - perfect_foresight_solver; -end diff --git a/tests/smoother2histval/fs2000_simul.mod b/tests/smoother2histval/fs2000_simul.mod index eb65974e1..a682c76c0 100644 --- a/tests/smoother2histval/fs2000_simul.mod +++ b/tests/smoother2histval/fs2000_simul.mod @@ -66,6 +66,10 @@ results_estimation=load('fs2000_smooth_results'); M_.params=results_estimation.M_.params; steady; +OO = load('fs2000_smooth_results.mat'); +M_.params = OO.M_.params; + histval_file(filename = 'fs2000_histval.mat'); -simul(periods = 30); +perfect_foresight_setup(periods = 100); +perfect_foresight_solver; diff --git a/tests/smoother2histval/fs2000_smooth.mod b/tests/smoother2histval/fs2000_smooth.mod index 89447eb57..65bb15b68 100644 --- a/tests/smoother2histval/fs2000_smooth.mod +++ b/tests/smoother2histval/fs2000_smooth.mod @@ -82,6 +82,6 @@ varobs gp_obs gy_obs; options_.solve_tolf = 1e-12; -estimation(order=1,datafile=fsdat_simul,nobs=192,mh_replic=1500,mh_nblocks=1,mh_jscale=0.8,smoother,consider_all_endogenous); +estimation(order=1,datafile=fsdat_simul,mh_replic=1500,mh_nblocks=1,mh_jscale=0.8,smoother,consider_all_endogenous); smoother2histval(period = 5, outfile = 'fs2000_histval.mat');