Skip to content

ENH: Add VAR-HAC long-run covariance estimation #363

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions arch/conftest.py
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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)
Loading