7
7
from statsmodels .tools import add_constant
8
8
from statsmodels .tsa .tsatools import lagmat
9
9
10
+ from arch .covariance import kernel
10
11
from arch .covariance .kernel import CovarianceEstimate , CovarianceEstimator
11
12
from arch .typing import ArrayLike , NDArray
12
13
@@ -18,6 +19,21 @@ class VARModel(NamedTuple):
18
19
intercept : bool
19
20
20
21
22
+ def _normalize_name (name : str ) -> str :
23
+ name = name .replace ("-" , "" ).replace ("_" , "" )
24
+ name = name .lower ()
25
+ return name
26
+
27
+
28
+ KERNELS = {}
29
+ for name in kernel .__all__ :
30
+ estimator = getattr (kernel , name )
31
+ if issubclass (estimator , kernel .CovarianceEstimator ):
32
+ KERNELS [_normalize_name (name )] = estimator
33
+ KERNELS [name ] = estimator
34
+ print (KERNELS )
35
+
36
+
21
37
class PreWhitenRecoloredCovariance (CovarianceEstimator ):
22
38
"""
23
39
Parameters
@@ -33,6 +49,15 @@ class PreWhitenRecoloredCovariance(CovarianceEstimator):
33
49
df_adjust : int, default 0
34
50
center : bool, default True
35
51
weights : array_like, default None
52
+
53
+ See Also
54
+ --------
55
+
56
+ Notes
57
+ -----
58
+
59
+ Examples
60
+ --------
36
61
"""
37
62
38
63
def __init__ (
@@ -61,12 +86,26 @@ def __init__(
61
86
self ._auto_lag_selection = True
62
87
self ._format_lags (lags )
63
88
self ._sample_autocov = sample_autocov
89
+ original_kernel = kernel
90
+ kernel = _normalize_name (kernel )
91
+ if kernel not in KERNELS :
92
+ import string
93
+
94
+ available = [key for key in KERNELS if key [0 ] in string .ascii_uppercase ]
95
+ available_val = "\n " .join (
96
+ [f"{ knl } { _normalize_name (knl )} " for knl in available ]
97
+ )
98
+ raise ValueError (
99
+ f"kernel { original_kernel } was not found. The available kernels "
100
+ f"are:\n \n { available_val } "
101
+ )
102
+ self ._kernel = KERNELS [kernel ]
64
103
65
104
# Attach for testing only
66
105
self ._ics : Dict [Tuple [int , int ], float ] = {}
67
106
self ._order = (0 , 0 )
68
107
69
- def _format_lags (self , lags ) -> None :
108
+ def _format_lags (self , lags : Optional [ int ] ) -> None :
70
109
"""
71
110
Check lag inputs and standard values for lags and diagonal lags
72
111
"""
@@ -80,7 +119,7 @@ def _format_lags(self, lags) -> None:
80
119
self ._diagonal_lags = self ._lags
81
120
return
82
121
83
- def _ic (self , sigma , nparam , nobs ) :
122
+ def _ic (self , sigma : NDArray , nparam : int , nobs : int ) -> float :
84
123
_ , ld = np .linalg .slogdet (sigma )
85
124
if self ._method == "aic" :
86
125
return ld + 2 * nparam / nobs
@@ -105,7 +144,7 @@ def _setup_model_data(self, max_lag: int) -> Tuple[NDArray, NDArray, NDArray]:
105
144
return lhs , rhs , indiv_lags
106
145
107
146
@staticmethod
108
- def _fit_diagonal (x , diag_lag , lags ) :
147
+ def _fit_diagonal (x : NDArray , diag_lag : int , lags : NDArray ) -> NDArray :
109
148
nvar = x .shape [1 ]
110
149
for i in range (nvar ):
111
150
lhs = lags [i , :, :diag_lag ]
0 commit comments