Parameter classes¶
Generic parameter class¶
-
class
bekk.param_generic.
ParamGeneric
(nstocks=2, abstart=(0.1, 0.85), target=None)[source]¶ Class to hold parameters of the BEKK model.
Attributes
amat, bmat, cmat Matrix representations of BEKK parameters Methods
from_abc
([amat, bmat, cmat])Initialize from A, B, and C arrays. find_cmat
([amat, bmat, ccmat, target])Find C matrix given A, B, and H. from_target
([amat, bmat, target])Initialize from A, B, and variance target. find_stationary_var
([amat, bmat, cmat])Find fixed point of H = CC’ + AHA’ + BHB’ given A, B, C. get_uvar
()Unconditional variance matrix regardless of the model. constraint
()Compute the largest eigenvalue of BEKK model. -
constraint
()[source]¶ Compute the largest eigenvalue of BEKK model.
Returns: float
Largest eigenvalue
-
static
find_ccmat
(amat=None, bmat=None, target=None)[source]¶ Find CC’ matrix given A, B, and H in H = CC’ + AHA’ + BHB’ given A, B, H.
Parameters: amat, bmat, target : (nstocks, nstocks) arrays
Parameter matrices
Returns: (nstocks, nstocks) array
-
static
find_cmat
(amat=None, bmat=None, ccmat=None, target=None)[source]¶ Find C matrix given A, B, and H. Solve for C in H = CC’ + AHA’ + BHB’ given A, B, H.
Parameters: amat, bmat, target : (nstocks, nstocks) arrays
Parameter matrices
Returns: (nstocks, nstocks) array
Cholesky decomposition of CC’
-
static
find_stationary_var
(amat=None, bmat=None, cmat=None)[source]¶ Find fixed point of H = CC’ + AHA’ + BHB’ given A, B, C.
Parameters: amat, bmat, cmat : (nstocks, nstocks) arrays
Parameter matrices
Returns: (nstocks, nstocks) array
Unconditional variance matrix
-
static
fixed_point
(uvar, amat=None, bmat=None, ccmat=None)[source]¶ Function for finding fixed point of H = CC’ + AHA’ + BHB’ given A, B, C.
Parameters: uvar : 1d array
Lower triangle of symmetric variance matrix
amat, bmat, ccmat : (nstocks, nstocks) arrays
Parameter matrices
Returns: (nstocks, nstocks) array
-
classmethod
from_abc
(amat=None, bmat=None, cmat=None)[source]¶ Initialize from A, B, and C arrays.
Parameters: amat, bmat, cmat : (nstocks, nstocks) arrays
Parameter matrices
Returns: param : BEKKParams instance
BEKK parameters
-
classmethod
from_target
(amat=None, bmat=None, target=None)[source]¶ Initialize from A, B, and variance target.
Parameters: amat, bmat, target : (nstocks, nstocks) arrays
Parameter matrices
Returns: param : BEKKParams instance
BEKK parameters
-
Standadrd parameter class¶
-
class
bekk.param_standard.
ParamStandard
(nstocks=2, abstart=(0.1, 0.6), target=None)[source]¶ Class to hold parameters of the BEKK model.
Attributes
amat, bmat, cmat Matrix representations of BEKK parameters Methods
from_theta
([theta, nstocks, cfree, …])Initialize from theta vector. get_theta
([restriction, use_target, cfree])Convert parameter mratrices to 1-dimensional array. -
classmethod
from_theta
(theta=None, nstocks=None, cfree=True, restriction='scalar', target=None)[source]¶ Initialize from theta vector.
Parameters: theta : 1d array
Length depends on the model restrictions and variance targeting
- If target is not None:
- ‘full’ - 2*n**2
- ‘diagonal’ - 2*n
- ‘scalar’ - 2
- If target is None:
- +(n+1)*n/2 for parameter C
nstocks : int
Number of stocks in the model
restriction : str
- Can be
- ‘full’
- ‘diagonal’
- ‘scalar’
target : (nstocks, nstocks) array
Variance target matrix
Returns: param : BEKKParams instance
BEKK parameters
-
get_theta
(restriction='scalar', use_target=True, cfree=True)[source]¶ Convert parameter mratrices to 1-dimensional array.
Parameters: restriction : str
- Can be
- ‘full’
- ‘diagonal’
- ‘scalar’
use_target : bool
Whether to estimate only A and B (True) or C as well (False)
Returns: theta : 1d array
Length depends on the model restrictions and variance targeting
- If use_target is True:
- ‘full’ - 2*n**2
- ‘diagonal’ - 2*n
- ‘scalar’ - 2
- If use_target is False:
- +(n+1)*n/2 for parameter cmat
-
classmethod
Spatial parameter class¶
-
class
bekk.param_spatial.
ParamSpatial
(nstocks=2)[source]¶ Class to hold parameters of the BEKK model.
Attributes
amat, bmat, cmat, avecs, bvecs, dvecs Matrix representations of BEKK parameters groups List of related items weights Spatial relation matrices Methods
from_theta
([theta, groups, cfree, …])Initialize from theta vector. get_theta
([restriction, use_target, cfree])Convert parameter matrices to 1-dimensional array. get_weight
([groups])Generate weighting matrices given groups. -
classmethod
from_theta
(theta=None, groups=None, cfree=False, restriction='shomo', target=None, solve_dvecs=False)[source]¶ Initialize from theta vector.
Parameters: theta : 1d array
Length depends on the model restrictions and variance targeting
weights : (ncat, nstocks, nstocks) array
Weight matrices
groups : list of lists of tuples
Encoded groups of items
cfree : bool
Whether to leave C matrix free (True) or not (False)
target : (nstocks, nstocks) array
Variance target matrix
restriction : str
- Can be
- ‘hetero’ (heterogeneous)
- ‘ghomo’ (group homogeneous)
- ‘homo’ (homogeneous)
- ‘shomo’ (scalar homogeneous)
Returns: param : BEKKParams instance
BEKK parameters
-
get_theta
(restriction='shomo', use_target=False, cfree=False)[source]¶ Convert parameter matrices to 1-dimensional array.
Parameters: restriction : str
- Can be
- ‘hetero’ (heterogeneous)
- ‘ghomo’ (group homogeneous)
- ‘homo’ (homogeneous)
- ‘shomo’ (scalar homogeneous)
use_target : bool
Whether to estimate only A and B (True) or C as well (False)
cfree : bool
Whether to leave C matrix free (True) or not (False)
Returns: theta : 1d array
Length depends on the model restrictions and variance targeting
- If use_target is True:
- ‘hetero’ - 2*n*(m+1)
- ‘ghomo’ - 2*(n+m*k)
- ‘homo’ - 2*(n+m)
- ‘shomo’ - 2*(m+1)
- If use_target is False and cfree is False:
- ‘hetero’ - +n*(m+1)
- ‘ghomo’ - +(n+m*k)
- ‘homo’ - +(n+m)
- ‘shomo’ - +(n+m)
- If use_target is False and cfree is True:
- +n*(n+1)/2
-
static
get_weight
(groups=None)[source]¶ Generate weighting matrices given groups.
Parameters: groups : list of lists of tuples
Encoded groups of items
Returns: (ngroups, nitems, nitems) array
Spatial weights
Examples
>>> print(ParamSpatial.get_weight(groups=[[(0, 1)]])) [[[ 0. 1.] [ 1. 0.]]] >>> print(ParamSpatial.get_weight(groups=[[(0, 1, 2)]])) [[[ 0. 0.5 0.5] [ 0.5 0. 0.5] [ 0.5 0.5 0. ]]] >>> print(ParamSpatial.get_weight(groups=[[(0, 1), (2, 3)]])) [[[ 0. 1. 0. 0.] [ 1. 0. 0. 0.] [ 0. 0. 0. 1.] [ 0. 0. 1. 0.]]] >>> print(ParamSpatial.get_weight(groups=[[(0, 1), (2, 3, 4)]])) [[[ 0. 1. 0. 0. 0. ] [ 1. 0. 0. 0. 0. ] [ 0. 0. 0. 0.5 0.5] [ 0. 0. 0.5 0. 0.5] [ 0. 0. 0.5 0.5 0. ]]]
-
classmethod