Skip to content

markowitz.estimators.covariance

markowitz.estimators.covariance

Covariance estimators.

EWMACovariance(*, halflife_years: float | None = None, lam: float | None = None, burn_in: int | Literal['auto'] = 'auto', annualize: bool = True, periods_per_year: int | None = None)

Bases: _BaseCov

Exponentially weighted covariance (RiskMetrics recursion).

Source code in src/markowitz/estimators/covariance.py
def __init__(
    self,
    *,
    halflife_years: float | None = None,
    lam: float | None = None,
    burn_in: int | Literal["auto"] = "auto",
    annualize: bool = True,
    periods_per_year: int | None = None,
) -> None:
    if halflife_years is not None and lam is not None:
        raise EstimatorConfigError("Provide at most one of halflife_years or lam, not both.")
    self.halflife_years = halflife_years
    self.lam = lam
    self.burn_in = burn_in
    self.annualize = bool(annualize)
    self.periods_per_year = periods_per_year

LedoitWolfShrinkage(*, target: Literal['identity', 'constant_corr'] = 'identity', annualize: bool = True, periods_per_year: int | None = None)

Bases: _BaseCov

Ledoit-Wolf shrinkage covariance, sklearn-compatible for the identity target.

Source code in src/markowitz/estimators/covariance.py
def __init__(
    self,
    *,
    target: Literal["identity", "constant_corr"] = "identity",
    annualize: bool = True,
    periods_per_year: int | None = None,
) -> None:
    if target not in ("identity", "constant_corr"):
        raise EstimatorConfigError(
            f"target must be 'identity' or 'constant_corr'; got {target!r}"
        )
    self.target = target
    self.annualize = bool(annualize)
    self.periods_per_year = periods_per_year

SampleCovariance(*, annualize: bool = True, periods_per_year: int | None = None, ddof: int = 1)

Bases: _BaseCov

Plain sample covariance np.cov(returns.T, ddof=ddof).

Source code in src/markowitz/estimators/covariance.py
def __init__(
    self,
    *,
    annualize: bool = True,
    periods_per_year: int | None = None,
    ddof: int = 1,
) -> None:
    if ddof < 0:
        raise EstimatorConfigError(f"ddof must be >= 0; got {ddof}")
    self.annualize = bool(annualize)
    self.periods_per_year = periods_per_year
    self.ddof = int(ddof)