2021-11-18 12:24:23 +01:00
function [h, lrcp] = hVectors ( params, H, auxmodel, kind, id)
2018-02-28 14:59:40 +01:00
% INPUTS
% - params [double] (m+1)*1 vector, PAC parameters (lag polynomial coefficients and discount factor).
% - H [double] (np*np) matrix, companion matrix of the VAR(p) model.
2021-11-18 12:24:23 +01:00
% - auxmodel [char] kind of auxiliary model, possible values are: 'var' and 'trend_component'.
% - kind [char] kind of expectation in PAC equation (See FRB/US doc), possible values are 'll', 'dl' and 'dd'.
% - id [integer] scalar, index pointing to the target in the auxiliary model.
2018-02-28 14:59:40 +01:00
%
% OUTPUTS
2021-11-18 12:24:23 +01:00
% - h [double] 1*n vector of weights (used to compute the linear combination of the variables in the companion VAR representation of the auxiliary model).
% - lrcp [double] scalar, parameter for the growth neutrality correction.
2018-08-15 22:03:01 +02:00
%
% REMARKS
% The parameters are ordered as follows in the params vector:
%
% params(1) ⟶ Error correction parameter.
% params(2:end-1) ⟶ Autoregressive parameters.
% params(end) ⟶ Discount factor.
2018-02-28 14:59:40 +01:00
2021-11-18 12:24:23 +01:00
% Copyright © 2018-2021 Dynare Team
2018-08-15 22:05:47 +02:00
%
% This file is part of Dynare.
%
% Dynare is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% Dynare is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
2021-06-09 17:33:48 +02:00
% along with Dynare. If not, see <https://www.gnu.org/licenses/>.
2018-08-15 22:05:47 +02:00
2018-02-28 14:59:40 +01:00
if nargout > 1 && nargin < 4
error ( ' Wrong number of Inputs/Outputs!' )
end
[ G , alpha , beta ] = buildGmatrixWithAlphaAndBeta ( params ) ;
2018-07-04 14:57:54 +02:00
A = [ alpha ; 1 ] ;
A_1 = polyval ( A , 1.0 ) ;
A_b = polyval ( A , beta ) ;
2018-02-28 14:59:40 +01:00
m = length ( alpha ) ;
n = length ( H ) ;
2021-11-18 12:24:23 +01:00
tmp = eye ( n * m ) - kron ( G , transpose ( H ) ) ; % inv(W2)
2018-02-28 14:59:40 +01:00
2021-11-18 12:24:23 +01:00
switch kind
case ' ll'
h = A_1 * A_b * ( ( kron ( iota ( m , m ) , H ) ) ' * ( tmp \ kron ( iota ( m , m ) , iota ( n , id ) ) ) ) ;
case ' dd'
h = A_1 * A_b * ( kron ( iota ( m , m ) ' * inv ( eye ( m ) - G ) , H ' ) * ( tmp \ kron ( iota ( m , m ) , iota ( n , id ) ) ) ) ;
case ' dl'
h = A_1 * A_b * ( kron ( iota ( m , m ) ' * inv ( eye ( m ) - G ) , ( H ' - eye ( length ( H ) ) ) ) * ( tmp \ kron ( iota ( m , m ) , iota ( n , id ) ) ) ) ;
otherwise
error ( ' Unknown kind value in PAC model.' )
2018-04-26 16:35:32 +02:00
end
2018-02-28 14:59:40 +01:00
2021-11-18 12:24:23 +01:00
if nargin > 1
if isequal ( kind , ' ll' )
lrcp = NaN ;
2018-04-26 16:35:32 +02:00
else
2021-11-18 12:24:23 +01:00
d = A_1 * A_b * ( iota ( m , m ) ' * inv ( ( eye ( m ) - G ) * ( eye ( m ) - G ) ) * iota ( m , m ) ) ;
lrcp = ( 1 - sum ( params ( 2 : end - 1 ) ) - d ) ;
2018-04-26 16:35:32 +02:00
end
2018-02-28 14:59:40 +01:00
end