linearmodels.asset_pricing.covariance.KernelCovariance

class linearmodels.asset_pricing.covariance.KernelCovariance(xe: ndarray[tuple[int, ...], dtype[float64]], *, jacobian: ndarray | None = None, inv_jacobian: ndarray | None = None, kernel: str | None = None, bandwidth: float | None = None, center: bool = True, debiased: bool = False, df: int = 0)[source]

Heteroskedasticity-autocorrelation (HAC) robust covariance estimator.

Parameters:
xe: ndarray[tuple[int, ...], dtype[float64]]

The scores (moment) conditions, with shape (nobs, nmoments).

jacobian: ndarray | None = None

Jacobian, with shape (nmoments, nparams). One and only one of jacobian and inv_jacobian must be provided.

inv_jacobian: ndarray | None = None

Inverse jacobian. One and only one of jacobian and inv_jacobian must be provided.

kernel: str | None = None

Name of the kernel. The default is “bartlett”. The names are not case sensitive. Supported kernels are:

  • ”bartlett”, “newey-west” - Bartlett’s kernel

  • ”parzen”, “gallant” - Parzen’s kernel

  • ”qs”, “quadratic-spectral”, “andrews” - Quadratic spectral kernel

bandwidth: float | None = None

Non-negative bandwidth. If None, the optimal bandwidth is estimated. It needs at least 4 observations with the Bartlett kernel, 5 with the Parzen kernel and 6 with the quadratic spectral kernel, and a ValueError is raised for fewer when the bandwidth is first used. See kernel_optimal_bandwidth().

center: bool = True

Flag indicating to center the scores when computing the covariance. The default is True.

debiased: bool = False

Flag indicating to use a debiased estimator. The default is False.

df: int = 0

Degree of freedom value to use if debiasing. The default is 0.

Raises:
  • ValueError – If both or neither of jacobian and inv_jacobian are provided, or if bandwidth is negative.

  • TypeError – If kernel is not a str, or bandwidth is not a number.

  • UnknownOptionError – If kernel is not supported. It is both a KeyError and a ValueError.

See also

linearmodels.iv.covariance.kernel_weight_bartlett

Weights of the Bartlett kernel.

linearmodels.iv.covariance.kernel_weight_parzen

Weights of the Parzen kernel.

linearmodels.iv.covariance.kernel_weight_quadratic_spectral

Weights of the quadratic spectral kernel.

Notes

Changed in version 7.1: The optimal bandwidth raises a ValueError if there are fewer observations than the kernel needs, and if it is not finite. Earlier versions raised “cannot convert float infinity to integer” (an OverflowError) or “cannot convert float NaN to integer” for some data, and used a bandwidth of nobs - 1, or another bandwidth, for other data.

Methods

Properties

bandwidth

Bandwidth used in estimation.

config

Configuration of the covariance estimator.

cov

Compute parameter covariance.

inv_jacobian

Inverse Jacobian.

jacobian

The Jacobian.

kernel

Kernel used in estimation.

s

Score/moment condition covariance.

square

Flag indicating if jacobian is square.