From 0d96dd3d1d1be659f3a28452ce9ad627b101fa93 Mon Sep 17 00:00:00 2001
From: Marco Ratto <marco.ratto@ec.europa.eu>
Date: Tue, 25 Jan 2022 10:31:55 +0100
Subject: [PATCH] Trap the case when Q is null matrix

(cherry picked from commit 48ec0a60e82218bbcc4c989b36bb0704213936e8)
---
 matlab/compute_Pinf_Pstar.m | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/matlab/compute_Pinf_Pstar.m b/matlab/compute_Pinf_Pstar.m
index 4d6d2070e6..90da303d64 100644
--- a/matlab/compute_Pinf_Pstar.m
+++ b/matlab/compute_Pinf_Pstar.m
@@ -48,6 +48,16 @@ function [Pstar,Pinf] = compute_Pinf_Pstar(mf,T,R,Q,qz_criterium, restrict_colum
 % along with Dynare.  If not, see <https://www.gnu.org/licenses/>.
 
 np = size(T,1);
+if iszero(Q)
+    % this may happen if users set Q=0 and use heteroskedastic shocks to set
+    % variances period by period
+    % this in practice triggers a form of conditional filter where states
+    % are initialized at st. state with zero variances
+    Pstar=T*0;
+    Pinf=T*0;
+    return
+end
+
 if nargin == 6
     indx = restrict_columns;
     indx0=find(~ismember([1:np],indx));
-- 
GitLab