Merge branch 'master' into ecb-master

time-shift
Stéphane Adjemian (Charybdis) 2017-06-30 10:55:31 +02:00
commit cf4579fc61
5 changed files with 123 additions and 92 deletions

View File

@ -750,8 +750,10 @@ by the @code{dynare} command.
@descriptionhead @descriptionhead
This command launches Dynare and executes the instructions included in This command launches Dynare and executes the instructions included in
@file{@var{FILENAME}.mod}. This user-supplied file contains the model @file{@var{FILENAME}.mod}. This user-supplied file contains the model and the
and the processing instructions, as described in @ref{The Model file}. processing instructions, as described in @ref{The Model file}. The options,
listed below, can be passed on the command line, following the name of the
@file{.mod} file or in the first line of the @file{.mod} file itself (see below).
@code{dynare} begins by launching the preprocessor on the @file{.mod} @code{dynare} begins by launching the preprocessor on the @file{.mod}
file. By default (unless @code{use_dll} option has been given to file. By default (unless @code{use_dll} option has been given to
@ -871,9 +873,9 @@ out.
Quit processing once the output requested by @ref{json} has been written. Quit processing once the output requested by @ref{json} has been written.
@item jsonderivsimple @item jsonderivsimple
Print a simplified version of the static and dynamic files in Print a simplified version (excluding variable name(s) and lag information) of the
@file{@var{FILENAME}_static_simple.json} and static and dynamic files in @file{@var{FILENAME}_static.json} and
@file{@var{FILENAME}_dynamic_simple.json}. @file{@var{FILENAME}_dynamic.json}.
@item warn_uninit @item warn_uninit
Display a warning for each variable or parameter which is not Display a warning for each variable or parameter which is not
@ -984,6 +986,16 @@ Tells Dynare to compute the equation cross references, writing them to the
output @file{.m} file. output @file{.m} file.
@end table @end table
These options can be passed to the preprocessor by listing them after the name
of the @code{.mod} file. They can alternatively be defined in the first line of
the @file{.mod} file, this avoids typing them on the command line each time a
@file{.mod} file is to be run. This line must be a Dynare comment (@emph{ie}
must begin with @code{//}) and the options must be comma separated between
@code{--+ options:} and @code{+--}. As in the command line, if an option admits
a value the equal symbol must not be surrounded by spaces. For instance
@code{json = compute} is not correct, and should be written
@code{json=compute}.
@outputhead @outputhead
Depending on the computing tasks requested in the @file{.mod} file, Depending on the computing tasks requested in the @file{.mod} file,
@ -1003,6 +1015,13 @@ dynare ramst
dynare ramst.mod savemacro dynare ramst.mod savemacro
@end example @end example
Alternatively the options can be specified in the first line of @file{ramst.mod}:
@example
// --+ options: savemacro, json=compute +--
@end example
@end deffn @end deffn
The output of Dynare is left into three main variables in the The output of Dynare is left into three main variables in the

View File

@ -33,7 +33,7 @@ function dynare(fname, varargin)
% You should have received a copy of the GNU General Public License % You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <http://www.gnu.org/licenses/>. % along with Dynare. If not, see <http://www.gnu.org/licenses/>.
if strcmpi(fname,'help') if ~nargin || strcmpi(fname,'help')
skipline() skipline()
disp(['This is dynare version ' dynare_version() '.']) disp(['This is dynare version ' dynare_version() '.'])
skipline() skipline()
@ -41,6 +41,7 @@ if strcmpi(fname,'help')
skipline() skipline()
disp('dynare executes instruction included in FILENAME.mod.') disp('dynare executes instruction included in FILENAME.mod.')
disp('See the reference manual for the available options.') disp('See the reference manual for the available options.')
skipline()
return return
end end
@ -64,11 +65,7 @@ dynareroot = dynare_config;
warning_config() warning_config()
if isoctave if ~isoctave
if octave_ver_less_than('3.6.0')
warning('This version of Dynare has only been tested on Octave 3.6.0 and above. Since your Octave version is older than that, Dynare may fail to run, or give unexpected results. Consider upgrading your Octave installation.');
end
else
if matlab_ver_less_than('7.5') if matlab_ver_less_than('7.5')
warning('This version of Dynare has only been tested on MATLAB 7.5 (R2007b) and above. Since your MATLAB version is older than that, Dynare may fail to run, or give unexpected results. Consider upgrading your MATLAB installation, or switch to Octave.'); warning('This version of Dynare has only been tested on MATLAB 7.5 (R2007b) and above. Since your MATLAB version is older than that, Dynare may fail to run, or give unexpected results. Consider upgrading your MATLAB installation, or switch to Octave.');
end end
@ -94,12 +91,17 @@ if ~ischar(fname)
error('DYNARE: argument of dynare must be a text string') error('DYNARE: argument of dynare must be a text string')
end end
% Testing if file have extension % Testing if filename has more than one period (not allowed).
% If no extension default .mod is added
dot_location=(strfind(fname,'.')); dot_location=(strfind(fname,'.'));
if length(dot_location)>1 if length(dot_location)>1
error('DYNARE: Periods in filenames are only allowed for .mod or .dyn extensions') error('DYNARE: Periods in filenames are only allowed for .mod or .dyn extensions')
end end
if dot_location==length(fname)
error('DYNARE: Periods in filenames are only allowed for .mod or .dyn extensions')
end
% Add dyn or mod extension to the file name if not already provided.
if isempty(strfind(fname,'.')) if isempty(strfind(fname,'.'))
fnamelength = length(fname); fnamelength = length(fname);
fname1 = [fname '.dyn']; fname1 = [fname '.dyn'];
@ -108,12 +110,10 @@ if isempty(strfind(fname,'.'))
fname1 = [fname '.mod']; fname1 = [fname '.mod'];
end end
fname = fname1; fname = fname1;
% Checking file extension
else else
if dot_location~=length(fname)-3 ... %if the file name has fewer than 4 characters and there is a period % Check provided file extension.
|| ~strcmp(upper(fname(size(fname,2)-3:size(fname,2))),'.MOD') ... if ~strcmpi(fname(dot_location+1:end), 'mod') && ~strcmpi(fname(dot_location+1:end), 'dyn')
&& ~strcmp(upper(fname(size(fname,2)-3:size(fname,2))),'.DYN') error('DYNARE: argument must be a filename with .mod or .dyn extensions')
error('DYNARE: argument must be a filename with .mod or .dyn extension and must not include any other periods')
end end
fnamelength = length(fname) - 4; fnamelength = length(fname) - 4;
end end
@ -183,6 +183,27 @@ else
disp('Using 64-bit preprocessor'); disp('Using 64-bit preprocessor');
end end
% Read options from the first line in mod/dyn file.
fid = fopen(fname, 'r');
firstline = fgetl(fid);
fclose(fid);
if isequal(regexp(firstline, '\s*\/\/'), 1)
% First line is commented.
firstline = regexprep(firstline, '\s*\/\/', '');
if ~isempty(regexp(firstline, '(^\s+\-\-\+\s+options:)')) % Commented line begins with --+ options:
if ~isempty(regexp(firstline, '(\s+\+\-\-\s*$)')) % Commented line ends with +--
dynoption = strsplit(firstline, {'--+', '+--', 'options:', ' ', ','});
dynoption(find(cellfun( @(x) isempty(x), dynoption))) = [];
if isequal(nargin, 1)
varargin = dynoption;
else
varargin = union(varargin, dynoption);
end
varargin
end
end
end
command = ['"' dynareroot 'preprocessor' arch_ext filesep 'dynare_m" ' fname] ; command = ['"' dynareroot 'preprocessor' arch_ext filesep 'dynare_m" ' fname] ;
for i=1:length(varargin) for i=1:length(varargin)
command = [command ' ' varargin{i}]; command = [command ' ' varargin{i}];

View File

@ -1438,53 +1438,33 @@ ModFile::writeJsonOutputParsingCheck(const string &basename, JsonFileOutputType
void void
ModFile::writeJsonComputingPassOutput(const string &basename, JsonFileOutputType json_output_mode, bool jsonderivsimple) const ModFile::writeJsonComputingPassOutput(const string &basename, JsonFileOutputType json_output_mode, bool jsonderivsimple) const
{ {
ostringstream static_output, static_simple_output; if (basename.empty() && json_output_mode != standardout)
{
cerr << "ERROR: Missing file name" << endl;
exit(EXIT_FAILURE);
}
ostringstream tmp_out, static_output, dynamic_output, static_paramsd_output, dynamic_paramsd_output;
static_output << "{"; static_output << "{";
static_model.writeJsonComputingPassOutput(static_output, true); static_model.writeJsonComputingPassOutput(static_output, !jsonderivsimple);
static_output << "}" << endl; static_output << "}";
ostringstream dynamic_output, dynamic_simple_output;
dynamic_output << "{"; dynamic_output << "{";
dynamic_model.writeJsonComputingPassOutput(dynamic_output, true); dynamic_model.writeJsonComputingPassOutput(dynamic_output, !jsonderivsimple);
dynamic_output << "}" << endl; dynamic_output << "}";
ostringstream tmp_out, static_paramsd_output, static_paramsd_simple_output;
tmp_out << ""; tmp_out << "";
static_paramsd_output << ""; static_paramsd_output << "";
static_paramsd_simple_output << ""; static_model.writeJsonParamsDerivativesFile(tmp_out, !jsonderivsimple);
static_model.writeJsonParamsDerivativesFile(tmp_out, true);
if (!tmp_out.str().empty()) if (!tmp_out.str().empty())
static_paramsd_output << "{" << tmp_out.str() << "}" << endl; static_paramsd_output << "{" << tmp_out.str() << "}" << endl;
ostringstream tmp1_out, dynamic_paramsd_output, dynamic_paramsd_simple_output; tmp_out.str("");
tmp1_out << "";
dynamic_paramsd_output << ""; dynamic_paramsd_output << "";
dynamic_paramsd_simple_output << ""; dynamic_model.writeJsonParamsDerivativesFile(tmp_out, !jsonderivsimple);
dynamic_model.writeJsonParamsDerivativesFile(tmp1_out, true); if (!tmp_out.str().empty())
if (!tmp1_out.str().empty()) dynamic_paramsd_output << "{" << tmp_out.str() << "}" << endl;
dynamic_paramsd_output << "{" << tmp1_out.str() << "}" << endl;
if (jsonderivsimple)
{
static_simple_output << "{";
static_model.writeJsonComputingPassOutput(static_simple_output, false);
static_simple_output << "}";
dynamic_simple_output << "{";
dynamic_model.writeJsonComputingPassOutput(dynamic_simple_output, false);
dynamic_simple_output << "}";
ostringstream tmpd_out, tmpd1_out;
tmpd_out << "";
tmpd1_out << "";
static_model.writeJsonParamsDerivativesFile(tmpd_out, true);
if (!tmpd_out.str().empty())
static_paramsd_simple_output << "{" << tmpd_out.str() << "}" << endl;
dynamic_model.writeJsonParamsDerivativesFile(tmpd1_out, true);
if (!tmpd1_out.str().empty())
dynamic_paramsd_simple_output << "{" << tmpd1_out.str() << "}" << endl;
}
if (json_output_mode == standardout) if (json_output_mode == standardout)
{ {
@ -1495,28 +1475,10 @@ ModFile::writeJsonComputingPassOutput(const string &basename, JsonFileOutputType
cout << ", \"static_params_deriv\": " << static_paramsd_output.str() << endl; cout << ", \"static_params_deriv\": " << static_paramsd_output.str() << endl;
if (!dynamic_paramsd_output.str().empty()) if (!dynamic_paramsd_output.str().empty())
cout << ", \"dynamic_params_deriv\":" << dynamic_paramsd_output.str() << endl; cout << ", \"dynamic_params_deriv\": " << dynamic_paramsd_output.str() << endl;
if (jsonderivsimple)
{
cout << ", \"static_model_simple\": " << static_simple_output.str() << endl
<< ", \"dynamic_model_simple\": " << dynamic_simple_output.str() << endl;
if (!static_paramsd_simple_output.str().empty())
cout << "," << static_paramsd_simple_output.str() << endl;
if (!dynamic_paramsd_simple_output.str().empty())
cout << "," << dynamic_paramsd_simple_output.str() << endl;
}
} }
else else
{ {
if (basename.empty())
{
cerr << "ERROR: Missing file name" << endl;
exit(EXIT_FAILURE);
}
string fname_original, fname_static, fname_dynamic; string fname_original, fname_static, fname_dynamic;
fname_static = basename + "_static.json"; fname_static = basename + "_static.json";
fname_dynamic = basename + "_dynamic.json"; fname_dynamic = basename + "_dynamic.json";
@ -1524,32 +1486,18 @@ ModFile::writeJsonComputingPassOutput(const string &basename, JsonFileOutputType
writeJsonFileHelper(fname_static, static_output); writeJsonFileHelper(fname_static, static_output);
writeJsonFileHelper(fname_dynamic, dynamic_output); writeJsonFileHelper(fname_dynamic, dynamic_output);
if (jsonderivsimple)
{
string fname_static_simple, fname_dynamic_simple;
fname_static_simple = basename + "_static_simple.json";
fname_dynamic_simple = basename + "_dynamic_simple.json";
writeJsonFileHelper(fname_static_simple, static_simple_output);
writeJsonFileHelper(fname_dynamic_simple, dynamic_simple_output);
}
if (!static_paramsd_output.str().empty()) if (!static_paramsd_output.str().empty())
{ {
string fname_static_params, fname_static_params_simple; string fname_static_params;
fname_static_params = basename + "_static_params_derivs.json"; fname_static_params = basename + "_static_params_derivs.json";
fname_static_params_simple = basename + "_static_params_derivs_simple.json";
writeJsonFileHelper(fname_static_params, static_paramsd_output); writeJsonFileHelper(fname_static_params, static_paramsd_output);
writeJsonFileHelper(fname_static_params_simple, static_paramsd_simple_output);
} }
if (!dynamic_paramsd_output.str().empty()) if (!dynamic_paramsd_output.str().empty())
{ {
string fname_dynamic_params, fname_dynamic_params_simple; string fname_dynamic_params;
fname_dynamic_params = basename + "_params_derivs.json"; fname_dynamic_params = basename + "_params_derivs.json";
fname_dynamic_params_simple = basename + "_params_derivs_simple.json";
writeJsonFileHelper(fname_dynamic_params, dynamic_paramsd_output); writeJsonFileHelper(fname_dynamic_params, dynamic_paramsd_output);
writeJsonFileHelper(fname_dynamic_params_simple, dynamic_paramsd_simple_output);
} }
} }
} }
@ -1566,5 +1514,4 @@ ModFile::writeJsonFileHelper(string &fname, ostringstream &output) const
} }
jsonOutput << output.str(); jsonOutput << output.str();
jsonOutput.close(); jsonOutput.close();
} }

View File

@ -340,7 +340,8 @@ MODFILES = \
observation_trends_and_prefiltering/calib_smoother/Tr_no_prefil_f_obs_loglin_cal_smoother.mod \ observation_trends_and_prefiltering/calib_smoother/Tr_no_prefil_f_obs_loglin_cal_smoother.mod \
observation_trends_and_prefiltering/calib_smoother/Tr_prefilter_loglin_calib_smoother.mod \ observation_trends_and_prefiltering/calib_smoother/Tr_prefilter_loglin_calib_smoother.mod \
observation_trends_and_prefiltering/calib_smoother/Tr_prefil_f_obs_loglin_cal_smoother.mod \ observation_trends_and_prefiltering/calib_smoother/Tr_prefil_f_obs_loglin_cal_smoother.mod \
observation_trends_and_prefiltering/ML/Trend_no_prefilter_selected_var.mod observation_trends_and_prefiltering/ML/Trend_no_prefilter_selected_var.mod \
dynare-command-options/ramst.mod
PARTICLEFILES = \ PARTICLEFILES = \
particle/dsge_base2.mod \ particle/dsge_base2.mod \

View File

@ -0,0 +1,43 @@
// --+ options: json=compute, notmpterms, nolog +--
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;
check;
shocks;
var x;
periods 1;
values 1.2;
end;
perfect_foresight_setup(periods=200);
perfect_foresight_solver;
rplot c;
rplot k;
if ~exist('ramst.json') || exist('ramst.log')
error('dynare command did not honour the options provided in the mod file!')
end