Skip to content

Commit 5ce1633

Browse files
committed
A bit more
1 parent 40dcc2a commit 5ce1633

File tree

1 file changed

+42
-3
lines changed

1 file changed

+42
-3
lines changed

arch/covariance/var.py

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from statsmodels.tools import add_constant
88
from statsmodels.tsa.tsatools import lagmat
99

10+
from arch.covariance import kernel
1011
from arch.covariance.kernel import CovarianceEstimate, CovarianceEstimator
1112
from arch.typing import ArrayLike, NDArray
1213

@@ -18,6 +19,21 @@ class VARModel(NamedTuple):
1819
intercept: bool
1920

2021

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+
2137
class PreWhitenRecoloredCovariance(CovarianceEstimator):
2238
"""
2339
Parameters
@@ -33,6 +49,15 @@ class PreWhitenRecoloredCovariance(CovarianceEstimator):
3349
df_adjust : int, default 0
3450
center : bool, default True
3551
weights : array_like, default None
52+
53+
See Also
54+
--------
55+
56+
Notes
57+
-----
58+
59+
Examples
60+
--------
3661
"""
3762

3863
def __init__(
@@ -61,12 +86,26 @@ def __init__(
6186
self._auto_lag_selection = True
6287
self._format_lags(lags)
6388
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]
64103

65104
# Attach for testing only
66105
self._ics: Dict[Tuple[int, int], float] = {}
67106
self._order = (0, 0)
68107

69-
def _format_lags(self, lags) -> None:
108+
def _format_lags(self, lags: Optional[int]) -> None:
70109
"""
71110
Check lag inputs and standard values for lags and diagonal lags
72111
"""
@@ -80,7 +119,7 @@ def _format_lags(self, lags) -> None:
80119
self._diagonal_lags = self._lags
81120
return
82121

83-
def _ic(self, sigma, nparam, nobs):
122+
def _ic(self, sigma: NDArray, nparam: int, nobs: int) -> float:
84123
_, ld = np.linalg.slogdet(sigma)
85124
if self._method == "aic":
86125
return ld + 2 * nparam / nobs
@@ -105,7 +144,7 @@ def _setup_model_data(self, max_lag: int) -> Tuple[NDArray, NDArray, NDArray]:
105144
return lhs, rhs, indiv_lags
106145

107146
@staticmethod
108-
def _fit_diagonal(x, diag_lag, lags):
147+
def _fit_diagonal(x: NDArray, diag_lag: int, lags: NDArray) -> NDArray:
109148
nvar = x.shape[1]
110149
for i in range(nvar):
111150
lhs = lags[i, :, :diag_lag]

0 commit comments

Comments
 (0)