From 2d39991a0ad9e7c731f8dc01abe2486df006ebe5 Mon Sep 17 00:00:00 2001 From: Marco Ratto <marco.ratto@ec.europa.eu> Date: Sat, 1 May 2021 23:48:06 +0200 Subject: [PATCH] allow for a more accurate (and more expensive) fast realtime modality, triggered by fast_realtime=INTEGER_VECTOR and where vector fast_realtime controls periods for which the smoother is run. If max(fast_realtime)<nobs, the smoother is also run for the full sample. Manual updated accordingly. --- doc/manual/source/the-model-file.rst | 8 ++-- matlab/realtime_shock_decomposition.m | 67 +++++++++++++-------------- 2 files changed, 37 insertions(+), 38 deletions(-) diff --git a/doc/manual/source/the-model-file.rst b/doc/manual/source/the-model-file.rst index 48f5be41c4..e194935891 100644 --- a/doc/manual/source/the-model-file.rst +++ b/doc/manual/source/the-model-file.rst @@ -7821,11 +7821,11 @@ Shock Decomposition decomposition. Default: ``0``. .. option:: fast_realtime = INTEGER + fast_realtime = [INTEGER1:INTEGER2] + fast_realtime = [INTEGER1 INTEGER2 ...] - Runs the smoother only twice: once for the last in-sample and - once for the last out-of-sample data point, where the provided - integer defines the last observation (equivalent to - :opt:`nobs`). Default: not enabled. + Runs the smoother only for the data vintages provided + by the specified integer (vector). .. option:: with_epilogue diff --git a/matlab/realtime_shock_decomposition.m b/matlab/realtime_shock_decomposition.m index 6686d5c8e0..ab29c861fe 100644 --- a/matlab/realtime_shock_decomposition.m +++ b/matlab/realtime_shock_decomposition.m @@ -116,56 +116,55 @@ if forecast_ && any(forecast_params) [~,~,~,~,~,~,oo1] = dynare_resolve(M1,options_,oo_); end -if fast_realtime - skipline() - skipline() - running_text = 'Fast realtime shock decomposition '; - newString=sprintf(running_text); - fprintf(['%s'],newString); - options_.nobs=fast_realtime; - [oo0,M_,~,~,Smoothed_Variables_deviation_from_mean0] = evaluate_smoother(parameter_set,varlist,M_,oo_,options_,bayestopt_,estim_params_); - gend0 = size(oo0.SmoothedShocks.(M_.exo_names{1}),1); - prctdone=0.5; - if isoctave - printf([running_text,' %3.f%% done\r'], prctdone*100); - else - s0=repmat('\b',1,length(newString)+1); - newString=sprintf([running_text,' %3.1f%% done'], prctdone*100); - fprintf([s0,'%s'],newString); - end - options_.nobs=nobs; - [oo2,M_,~,~,Smoothed_Variables_deviation_from_mean2] = evaluate_smoother(parameter_set,varlist,M_,oo_,options_,bayestopt_,estim_params_); - prctdone=1; - if isoctave - printf([running_text,' %3.f%% done\r'], prctdone*100); - else - s0=repmat('\b',1,length(newString)+1); - newString=sprintf([running_text,' %3.1f%% done'], prctdone*100); - fprintf([s0,'%s'],newString); - end -end +gend0=0; skipline() skipline() -running_text = 'Realtime shock decomposition '; +if isequal(fast_realtime,0) + running_text = 'Realtime shock decomposition '; +else + running_text = 'Fast realtime shock decomposition '; +end newString=sprintf(running_text); fprintf(['%s'],newString); for j=presample+1:nobs % evalin('base',['options_.nobs=' int2str(j) ';']) options_.nobs=j; - if ~fast_realtime + if isequal(fast_realtime,0) [oo,M_,~,~,Smoothed_Variables_deviation_from_mean] = evaluate_smoother(parameter_set,varlist,M_,oo_,options_,bayestopt_,estim_params_); gend = size(oo.SmoothedShocks.(M_.exo_names{1}),1); else - gend = gend0+j-fast_realtime; - if j>fast_realtime - oo=oo2; - Smoothed_Variables_deviation_from_mean = Smoothed_Variables_deviation_from_mean2(:,1:gend); + if j<min(fast_realtime) && gend0<j + options_.nobs=min(fast_realtime); + [oo0,M_,~,~,Smoothed_Variables_deviation_from_mean0] = evaluate_smoother(parameter_set,varlist,M_,oo_,options_,bayestopt_,estim_params_); + gend0 = size(oo0.SmoothedShocks.(M_.exo_names{1}),1); + options_.nobs=j; + end + + if ismember(j,fast_realtime) && gend0<j + [oo,M_,~,~,Smoothed_Variables_deviation_from_mean] = evaluate_smoother(parameter_set,varlist,M_,oo_,options_,bayestopt_,estim_params_); + gend = size(oo.SmoothedShocks.(M_.exo_names{1}),1); + gend0 = gend; + oo0=oo; + Smoothed_Variables_deviation_from_mean0=Smoothed_Variables_deviation_from_mean; else + if j>gend0 + if j>max(fast_realtime) + options_.nobs = nobs; + else + options_.nobs=min(fast_realtime(fast_realtime>j)); + end + [oo0,M_,~,~,Smoothed_Variables_deviation_from_mean0] = evaluate_smoother(parameter_set,varlist,M_,oo_,options_,bayestopt_,estim_params_); + gend0 = size(oo0.SmoothedShocks.(M_.exo_names{1}),1); + options_.nobs=j; + end + + gend = j; oo=oo0; Smoothed_Variables_deviation_from_mean = Smoothed_Variables_deviation_from_mean0(:,1:gend); end + end % reduced form dr = oo.dr; -- GitLab