Skip to content

markowitz.core.exceptions

markowitz.core.exceptions

Domain-specific exception hierarchy for the core subpackage.

All numerical and structural failures raised by markowitz.core derive from :class:CoreError, allowing callers to catch the whole family with a single except clause while still permitting fine-grained handling of specific failure modes (e.g. singular covariance, infeasible frontier).

CoreError

Bases: Exception

Base class for all errors raised by markowitz.core.

InfeasibleFrontierError

Bases: CoreError

Raised when the requested frontier point does not exist.

Examples include requesting the tangency portfolio at a risk-free rate that coincides with the GMV expected return, or asking for an efficient portfolio at a return that lies outside the attainable band of a degenerate frontier.

NumericalError

Bases: CoreError

Raised for numerical failures that are not covered by the more specific subclasses (e.g. NaN inputs, non-finite intermediate results, or breakdowns of an iterative solver).

SingularCovarianceError(msg: str = '', *, condition_number: float = float('inf'), min_eigenvalue: float = 0.0)

Bases: CoreError

Raised when a covariance matrix is not positive definite.

The instance attaches diagnostic information that is helpful for downstream regularization heuristics or user-facing error messages.

Parameters:

Name Type Description Default
msg str

Human-readable explanation of the failure.

''
condition_number float

Ratio lambda_max / lambda_min of the offending matrix. Set to float('inf') when the matrix is exactly singular.

float('inf')
min_eigenvalue float

Smallest eigenvalue of the offending matrix (possibly negative).

0.0
Source code in src/markowitz/core/exceptions.py
def __init__(
    self,
    msg: str = "",
    *,
    condition_number: float = float("inf"),
    min_eigenvalue: float = 0.0,
) -> None:
    super().__init__(msg)
    self.condition_number = condition_number
    self.min_eigenvalue = min_eigenvalue