markowitz.core.portfolio¶
markowitz.core.portfolio
¶
Immutable :class:Portfolio value object and a performance helper.
A Portfolio bundles weights with their (mean, variance, Sharpe)
performance summary. Instances are frozen and hashable-by-identity so
they can be safely shared across threads or stored in caches.
Portfolio(weights: FloatArray, expected_return: float, volatility: float, sharpe: float | None = None)
dataclass
¶
A snapshot of a portfolio's weights and analytic performance.
Attributes:
| Name | Type | Description |
|---|---|---|
weights |
FloatArray
|
Length- |
expected_return |
float
|
|
volatility |
float
|
|
sharpe |
float | None
|
Sharpe ratio relative to whatever risk-free rate the caller
chose; |
portfolio_performance(weights: npt.ArrayLike, mu: npt.ArrayLike, Sigma: npt.ArrayLike, *, rf: float | None = None) -> Portfolio
¶
Compute analytic performance for a given weight vector.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
weights
|
ArrayLike
|
Length- |
required |
mu
|
ArrayLike
|
Expected returns. |
required |
Sigma
|
ArrayLike
|
Covariance matrix. |
required |
rf
|
float | None
|
Optional risk-free rate. When supplied, |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
A |
class:`Portfolio` instance.
|
|
Raises:
| Type | Description |
|---|---|
NumericalError
|
If shapes are inconsistent or inputs contain non-finite values. |