Page 1 of 1

Real-time performance & updated variables

PostPosted: Tue Aug 30, 2016 1:56 pm
by gin
Dear all,

Consider an unobserved-components model that decomposes a series into cycles and trends. One would like to see its real-time performance compared to the smoothed estimate. The t|t projection can be found in oo_.UpdatedVariables structure, and called by the `smoother' option in estimation. However, I would like to see also the updates in between those two extremes, e.g. how fast the real-time estimate converges to the smoothed one. For that purpose, I'd like to see the `updated' variables after a quarter, year, and so on. It looks like there is no such a built-in feature in Dynare 4.4.3 yet. What would be the easiest way to implement such? I guess, the output should be generated on-demand only, so there should be some option similar to, and ideally, incorporated into filter_step_ahead (but with negative entries).

Re: Real-time performance & updated variables

PostPosted: Wed Aug 31, 2016 7:21 am
by jpfeifer
Dear Ginters,
which information sets exactly are you after? What do you mean with
filter_step_ahead (but with negative entries)
?

Re: Real-time performance & updated variables

PostPosted: Wed Aug 31, 2016 7:47 am
by gin
1) For quarterly data, these would be smoothed endogenous variables at t|t+1, t|t+4, t|t+12, t|t+20 that is, to see not only t|t but also how smoothed variables (e.g. the output gap) evolve when new information comes. This info should be readily available from the smoother.
2) I referred to filter_step_ahead because it produces t|t-k, k>0; thus if k<0 it would give the above without introducing a new option in the estimation command.

Alternatively, I could estimate the model by iteratively increasing the sample size but that is a bit more cumbersome/time consuming.

Re: Real-time performance & updated variables

PostPosted: Wed Aug 31, 2016 10:04 am
by jpfeifer
Are we talking about fixed parameters? Or are parameters updated as well with the information set?

Re: Real-time performance & updated variables

PostPosted: Wed Aug 31, 2016 10:32 am
by gin
Fixed parameters.

Re: Real-time performance & updated variables

PostPosted: Thu Sep 01, 2016 5:08 am
by jpfeifer
In that case, I think looping over the calibrated smoother is the only way to go and it should be relatively quick. The reason is that than information set t|t+k is created in the Kalman smoother via a backward pass where you have to start at the end of the sample.

Re: Real-time performance & updated variables

PostPosted: Mon Sep 05, 2016 11:47 am
by gin
Thanks.
For those interested, below is the code snippet of my interpretation of `looping over a calibrated smoother' in a single mod-file using @#for-loop.

Code: Select all
%
% Observed variables
%

varobs ym1, ym2, ym3;   %  GDP, Credit and Prices series

%----------------------------------------------------------------
% 5. Bayesian estimation
%----------------------------------------------------------------

 verbatim;
% define real-time matrices
% variable 1
trend1=nan(100,100);
slope1=nan(100,100);
cycle1=nan(100,100);
% variable 2
trend2=nan(100,100);
slope2=nan(100,100);
cycle2=nan(100,100);
% variable 3
trend3=nan(100,100);
slope3=nan(100,100);
cycle3=nan(100,100);
 end;

options_.console_mode=1; %(default: 0)
@#for mysample in 21:85
estimation   (
        nobs=[@{mysample}], % 21:85
      datafile = lv_3data_hhloans,
      nodisplay,
        nograph,
      graph_format = pdf,
      nodiagnostic,
      diffuse_filter,
      kalman_algo = 0,
      mh_replic = 0,
      mh_nblocks = 1,
      filtered_vars,
      smoother,
        mode_file=multiv_uoc_lv_hhloans6_mode,
      mode_compute = 0,
      plot_priors = 0,
      forecast = 0
      ) mmu1 mmu2 mmu3 car1 car2 car3;

%----------------------------------------------------------------
% 6. Reporting
%----------------------------------------------------------------
%
% use this for verbatim mode
mynobs=@{mysample};
 verbatim;

for i = 1:3
    %if laplace only
    % get the smoothed trend and cycle
    %eval([ 'ym_   = ym'                 num2str(i) ';' ]);
    eval([ 'trend_    = oo_.SmoothedVariables.mmu'   num2str(i) ';' ]);
    eval([ 'cycle_    = oo_.SmoothedVariables.car'   num2str(i) ';' ]);
 % eval([ 'irreg_    = oo_.SmoothedShocks.e_irr' num2str(i) ';' ]);
   
    % form a matrix of real time estimates
    eval([ 'trend' num2str(i) '(1:mynobs,mynobs-20)= trend_;']);
    eval([ 'slope' num2str(i) '(2:mynobs,mynobs-20)= diff(trend_);' ]);
    eval([ 'cycle' num2str(i) '(1:mynobs,mynobs-20)= cycle_;' ]);
 end;

end;

@#endfor

% plot all real-time cycles for variable 1 (GDP)
figure(1)
plot(cycle1)

% extract only t|t, t|t+4, t|t+12 and t|t+20
verbatim;
% t|t estimate
mystep=0;
cycle1_t_t=nan(100,1);
for ii=21:85-mystep
    cycle1_t_t(ii)=cycle1(ii,ii-20+mystep);
end

% t|t+4 estimate
mystep=4;
cycle1_t_tp4=nan(100,1);
for ii=21:85-mystep
    cycle1_t_tp4(ii)=cycle1(ii,ii-20+mystep);
end

% t|t+12 estimate
mystep=12;
cycle1_t_tp12=nan(100,1);
for ii=21:85-mystep
    cycle1_t_tp12(ii)=cycle1(ii,ii-20+mystep);
end

% t|t+20 estimate
mystep=20;
cycle1_t_tp20=nan(100,1);
for ii=21:85-mystep
    cycle1_t_tp20(ii)=cycle1(ii,ii-20+mystep);
end

figure(2)
plot(cycle1_t_t,':black')
hold on;
plot(cycle1_t_tp4,'-.black')
plot(cycle1_t_tp12,'--red')
plot(cycle1_t_tp20,'red')
hold off;
legend('t|t','t|t+4','t|t+12','t|t+20')

end;


64 iterations plus plots go in 16sec.

Re: Real-time performance & updated variables

PostPosted: Tue Sep 06, 2016 10:54 pm
by jpfeifer
That works, but I was rather thinking about looping over the
Code: Select all
calib_smoother

command. See https://github.com/DynareTeam/dynare/blob/master/tests/fs2000/fs2000_calib.mod