From e7a6cc155bae033ce3569cecc682af30ea9b02bd Mon Sep 17 00:00:00 2001
From: Johannes Pfeifer <jpfeifer@gmx,de>
Date: Mon, 3 Nov 2014 18:05:15 +0100
Subject: [PATCH] Computation of the loss function in the presence of unit root
 variables was incorrect

Some elements were simply left out. This commit now mimics the computations as in th_autocovariances.m and makes sure the loss function coincides with the one that is obtained by reading out the covariance from oo_.var
(cherry picked from commit cb5d3df6a089de3a033889d2184a2f117abb21a7)
---
 matlab/get_variance_of_endogenous_variables.m | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

diff --git a/matlab/get_variance_of_endogenous_variables.m b/matlab/get_variance_of_endogenous_variables.m
index d97619a1ed..008081922b 100644
--- a/matlab/get_variance_of_endogenous_variables.m
+++ b/matlab/get_variance_of_endogenous_variables.m
@@ -48,16 +48,13 @@ n = length(i_var);
 [vx,u] = lyapunov_symm(A,B*Sigma_e*B',options_.qz_criterium,options_.lyapunov_complex_threshold);
 
 if size(u,2) > 0
-    i_stat_0 = find(any(abs(A*u) < options_.Schur_vec_tol,2));
-    i_stat = find(any(abs(ghx*u) < options_.Schur_vec_tol,2));
-    
+    i_stat = find(any(abs(ghx*u) < options_.Schur_vec_tol,2)); %only set those variances of objective function for which variance is finite     
     ghx = ghx(i_stat,:);
     ghu = ghu(i_stat,:);
 else
-    i_stat_0 = 1:size(ghx,2);
     i_stat = (1:n)';
 end
 
 vx1 = Inf*ones(n,n);
-vx1(i_stat,i_stat) = ghx(:,i_stat_0)*vx(i_stat_0,i_stat_0)*ghx(:,i_stat_0)'+ghu*Sigma_e*ghu';
+vx1(i_stat,i_stat) = ghx*vx*ghx'+ghu*Sigma_e*ghu';
 
-- 
GitLab