Skip to content

Commit

Permalink
Merge 6b1cc78 into e71a2fb
Browse files Browse the repository at this point in the history
  • Loading branch information
bashtage committed Apr 2, 2020
2 parents e71a2fb + 6b1cc78 commit 92b2dbf
Show file tree
Hide file tree
Showing 14 changed files with 2,062 additions and 1,204 deletions.
1 change: 1 addition & 0 deletions arch/conftest.py
Expand Up @@ -2,6 +2,7 @@

pytest_plugins = [
"arch.tests.unitroot.cointegration_data",
"arch.tests.covariance.covariance_data",
]


Expand Down
12 changes: 12 additions & 0 deletions arch/covariance/__init__.py
@@ -0,0 +1,12 @@
from typing import Dict, Type

from . import kernel

KERNEL_ESTIMATORS: Dict[str, Type[kernel.CovarianceEstimator]] = {
est_name.lower(): getattr(kernel, est_name) for est_name in kernel.KERNELS
}
KERNEL_ESTIMATORS.update(
{est_name: getattr(kernel, est_name) for est_name in kernel.KERNELS}
)
KNOWN_KERNELS = "\n".join(sorted([k for k in KERNEL_ESTIMATORS]))
KERNEL_ERR = f"kernel is not a known estimator. Must be one of:\n {KNOWN_KERNELS}"
46 changes: 46 additions & 0 deletions arch/covariance/kernel.py
Expand Up @@ -24,6 +24,8 @@
"Andrews",
"Gallant",
"NeweyWest",
"normalize_kernel_name",
"ZeroLag",
]

KERNELS = [
Expand All @@ -39,9 +41,26 @@
"Andrews",
"Gallant",
"NeweyWest",
"ZeroLag",
]


def normalize_kernel_name(name: str) -> str:
"""
Normalize a Kernel name using standard replacements
Removes - and _ and converts to lower case.
Returns
-------
str
The normalized kernel name.
"""
name = name.replace("-", "").replace("_", "")
name = name.lower()
return name


class CovarianceEstimate(object):
r"""
Covariance estimate using a long-run covariance estimator
Expand Down Expand Up @@ -172,6 +191,7 @@ class CovarianceEstimator(ABC):
def __init__(
self,
x: ArrayLike,
*,
bandwidth: Optional[float] = None,
df_adjust: int = 0,
center: bool = True,
Expand Down Expand Up @@ -699,3 +719,29 @@ class NeweyWest(Bartlett):
--------
Bartlett
"""


zero_lag_name = "Zero-lag (No autocorrelation)"
zero_lag_formula = """\
w= 1 & z=0\\\\ \
\\ 0 & z>0 \
\\end{cases} \
"""


@Substitution(kernel_name=zero_lag_name, formula=zero_lag_formula)
class ZeroLag(CovarianceEstimator, metaclass=AbstractDocStringInheritor):
@property
def kernel_const(self) -> float:
return 1.0

@property
def bandwidth_scale(self) -> float:
return 0.0

@property
def rate(self) -> float:
return 0.0

def _weights(self) -> NDArray:
return np.ones(1)

0 comments on commit 92b2dbf

Please sign in to comment.