From c68038dfc894d33c042afa2bbe83baf6893826e8 Mon Sep 17 00:00:00 2001 From: Johannes Pfeifer Date: Sun, 2 Oct 2016 09:26:30 +0200 Subject: [PATCH] imcforecast.m: make sure qz_criterium is properly set --- matlab/dynare_estimation_init.m | 24 +------------ matlab/imcforecast.m | 15 +++++--- matlab/select_qz_criterium_value.m | 56 ++++++++++++++++++++++++++++++ 3 files changed, 68 insertions(+), 27 deletions(-) create mode 100644 matlab/select_qz_criterium_value.m diff --git a/matlab/dynare_estimation_init.m b/matlab/dynare_estimation_init.m index 2d6d4d65a..e9936d75d 100644 --- a/matlab/dynare_estimation_init.m +++ b/matlab/dynare_estimation_init.m @@ -123,29 +123,7 @@ if isequal(options_.diffuse_filter,1) || (options_.kalman_algo>2) end end -% If options_.lik_init == 1 -% set by default options_.qz_criterium to 1-1e-6 -% and check options_.qz_criterium < 1-eps if options_.lik_init == 1 -% Else -% set by default options_.qz_criterium to 1+1e-6 -if isequal(options_.lik_init,1) - if isempty(options_.qz_criterium) - options_.qz_criterium = 1-1e-6; - elseif options_.qz_criterium > 1-eps - error(['Estimation: option qz_criterium is too large for estimating ' ... - 'a stationary model. If your model contains unit roots, use ' ... - 'option diffuse_filter']) - end -else - if isempty(options_.qz_criterium) - options_.qz_criterium = 1+1e-6; - else - if options_.qz_criterium <= 1; - fprintf('\ndynare_estimation_init:: diffuse filter is incompatible with a qz_criterium<=1. Resetting it to 1+1e-6.\n') - options_.qz_criterium = 1+1e-6; - end - end -end +options_=select_qz_criterium_value(options_); % Set options related to filtered variables. if ~isequal(options_.filtered_vars,0) && isempty(options_.filter_step_ahead) diff --git a/matlab/imcforecast.m b/matlab/imcforecast.m index 038da4952..99ee00219 100644 --- a/matlab/imcforecast.m +++ b/matlab/imcforecast.m @@ -119,6 +119,10 @@ if estimated_model data_index = dataset_info.missing.aindex; gend = dataset_.nobs; missing_value = dataset_info.missing.state; + + %store qz_criterium + qz_criterium_old=options_.qz_criterium; + options_=select_qz_criterium_value(options_); [atT,innov,measurement_error,filtered_state_vector,ys,trend_coeff,aK,T,R,P,PK,decomp,trend_addition] = DsgeSmoother(xparam,gend,data,data_index,missing_value); %get constant part if options_.noconstant @@ -146,16 +150,16 @@ if estimated_model trend = constant(oo_.dr.order_var,:); InitState(:,1) = atT(:,end); else + qz_criterium_old=options_.qz_criterium; + if isempty(options_.qz_criterium) + options_.qz_criterium = 1+1e-6; + end graph_title='Calibration'; if ~isfield(oo_.dr,'kstate') error('You need to call stoch_simul before conditional_forecast') end end -if isempty(options_.qz_criterium) - options_.qz_criterium = 1+1e-6; -end - [T,R,ys,info,M_,options_,oo_] = dynare_resolve(M_,options_,oo_); if ~isdiagonal(M_.Sigma_e) @@ -273,4 +277,7 @@ end forecasts.graph.title=graph_title; forecasts.graph.fname=M_.fname; +%reset qz_criterium +options_.qz_criterium=qz_criterium_old; + save('conditional_forecasts.mat','forecasts'); \ No newline at end of file diff --git a/matlab/select_qz_criterium_value.m b/matlab/select_qz_criterium_value.m new file mode 100644 index 000000000..09282747e --- /dev/null +++ b/matlab/select_qz_criterium_value.m @@ -0,0 +1,56 @@ +function options_=select_qz_criterium_value(options_) +% function options_=select_qz_criterium_value(options_) +% set the value of options_.qz_criterium depending on the Kalman filter used +% +% INPUTS +% options_: Dynare options structure +% +% OUTPUTS +% options_: Dynare options structure +% +% SPECIAL REQUIREMENTS +% none + +% Copyright (C) 2016 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 . + + +% If options_.lik_init == 1 +% set by default options_.qz_criterium to 1-1e-6 +% and check options_.qz_criterium < 1-eps if options_.lik_init == 1 +% Else +% set by default options_.qz_criterium to 1+1e-6 +stack = dbstack; + +if isequal(options_.lik_init,1) + if isempty(options_.qz_criterium) + options_.qz_criterium = 1-1e-6; + elseif options_.qz_criterium > 1-eps + error([stack(2).file ': option qz_criterium is too large for estimating/smoothing ' ... + 'a stationary model. If your model contains unit roots, use ' ... + 'option diffuse_filter']) + end +else + if isempty(options_.qz_criterium) + options_.qz_criterium = 1+1e-6; + else + if options_.qz_criterium <= 1 + fprintf('\n%s:: diffuse filter is incompatible with a qz_criterium<=1. Resetting it to 1+1e-6.\n',stack(2).file) + options_.qz_criterium = 1+1e-6; + end + end +end