backtest_lib.portfolio.PortfolioBase#

class backtest_lib.portfolio.PortfolioBase(universe: Iterable[str], holdings: UniverseMapping[H] | Mapping[str, H], cash: float, total_value: float, constructor_backend: str = 'polars')#

Bases: Generic

Base portfolio representation.

A portfolio records holdings for a fixed universe along with a cash position and the total portfolio value. Subclasses determine the unit for holdings (weights, whole-share quantities, or fractional quantities) and provide conversions across these representations.

holdings#

Mapping from security to holdings in the portfolio’s unit.

Type:

backtest_lib.universe.universe_mapping.UniverseMapping

cash#

Cash balance in portfolio units (value or weight).

Type:

float

total_value#

Total portfolio value in cash units.

Type:

float

universe#

Universe of securities that index the holdings.

Type:

tuple[str, …]