From 228b2a532f4bfc06f5eadff801ba966e0f7031d6 Mon Sep 17 00:00:00 2001 From: Johannes Pfeifer Date: Wed, 12 Feb 2020 11:04:46 +0100 Subject: [PATCH] conditional forecasts: add check whether simulation was successful --- matlab/imcforecast.m | 9 +++++---- matlab/mcforecast3.m | 18 ++++++++++-------- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/matlab/imcforecast.m b/matlab/imcforecast.m index ad0af8f82..f7fa72951 100644 --- a/matlab/imcforecast.m +++ b/matlab/imcforecast.m @@ -204,9 +204,6 @@ if ~estimated_model trend = repmat(ys(oo_.dr.order_var,:),1,options_cond_fcst.periods+1); %trend needs to contain correct steady state end - - - NumberOfStates = length(InitState); FORCS1 = zeros(NumberOfStates,options_cond_fcst.periods+1,options_cond_fcst.replic); @@ -252,7 +249,11 @@ for b=1:options_cond_fcst.replic %conditional forecast using cL set to constrain [FORCS1(:,:,b), FORCS1_shocks(:,:,b)] = mcforecast3(cL,options_cond_fcst.periods,constrained_paths,shocks,FORCS1(:,:,b),T,R,mv, mu); FORCS1(:,:,b)=FORCS1(:,:,b)+trend; %add trend end - +if max(max(max(abs(FORCS1(constrained_vars,1:cL,:)-constrained_paths))))>1e-4 + fprintf('\nconditional_forecasts: controlling of variables was not successful.\n') + fprintf('This can be due to numerical imprecision (e.g. explosive simulations)\n') + fprintf('or because the instrument(s) do not allow controlling the variable(s).\n') +end mFORCS1 = mean(FORCS1,3); mFORCS1_shocks = mean(FORCS1_shocks,3); diff --git a/matlab/mcforecast3.m b/matlab/mcforecast3.m index 565dd3a2e..5689ddc8e 100644 --- a/matlab/mcforecast3.m +++ b/matlab/mcforecast3.m @@ -1,5 +1,5 @@ function [forcs, e]= mcforecast3(cL,H,mcValue,shocks,forcs,T,R,mv,mu) -% forcs = mcforecast3(cL,H,mcValue,shocks,forcs,T,R,mv,mu) +% [forcs, e] = mcforecast3(cL,H,mcValue,shocks,forcs,T,R,mv,mu) % Computes the shock values for constrained forecasts necessary to keep % endogenous variables at their constrained paths % @@ -7,13 +7,15 @@ function [forcs, e]= mcforecast3(cL,H,mcValue,shocks,forcs,T,R,mv,mu) % o cL [scalar] number of controlled periods % o H [scalar] number of forecast periods % o mcValue [n_controlled_vars by cL double] paths for constrained variables -% o shocks [nexo by H double] shock values draws (with zeros for controlled_varexo) -% o forcs -% o T [n_endovars by n_endovars double] transition matrix of the state equation. -% o R [n_endovars by n_exo double] matrix relating the endogenous variables to the innovations in the state equation. -% o mv [n_controlled_exo by n_endovars boolean] indicator vector selecting constrained endogenous variables -% o mu [n_controlled_vars by nexo boolean] indicator vector -% selecting controlled exogenous variables +% o shocks [nexo by H double] shock values draws (with zeros for controlled_varexo) +% o forcs [n_endovars by H+1 double] matrix of endogenous variables storing the inital condition +% o T [n_endovars by n_endovars double] transition matrix of the state equation. +% o R [n_endovars by n_exo double] matrix relating the endogenous variables to the innovations in the state equation. +% o mv [n_controlled_exo by n_endovars boolean] indicator vector selecting constrained endogenous variables +% o mu [n_controlled_vars by nexo boolean] indicator vector selecting controlled exogenous variables +% OUTPUTS +% o forcs [n_endovars by H+1 double] matrix of forecasted endogenous variables +% o e [nexo by H double] matrix of exogenous variables % % Algorithm: % Relies on state-space form: