numeraire.core.sorts#

Portfolio sorts — the cross-sectional decile-sort constructor (anomaly / characteristic sorts).

At each date, assets are ranked on a signal into n_bins portfolios and each portfolio’s return is a (value- or equal-) weighted average; the long-short is the extreme-bin spread. The one subtlety that matters for reproducing published anomaly returns is the breakpoint universe: NYSE-style breakpoints are computed on a subset (e.g. NYSE stocks) but applied to the full cross-section, so the many small NASDAQ names don’t drag the cutoffs down. Pass breakpoint_universe to enable this; leave it None for name-count (all-stock) breakpoints.

Formation and holding-period aggregation are deliberately separate. assign_portfolio_bins uses only the formation signal and formation-time masks. aggregate_assigned_portfolios then joins those frozen assignments to realized returns. This boundary makes it impossible for a missing future return to change a historical breakpoint or portfolio membership.

signal and returns must describe the same date and asset labels (their input order may differ): returns.loc[t] is the return earned over the holding period by the position formed from signal.loc[t] (the engine / caller owns the PIT lag).

assign_portfolio_bins

Freeze formation-time portfolio memberships without consulting realized returns.

aggregate_assigned_portfolios

Aggregate frozen memberships into returns and the extreme-bin spread.

sort_portfolios

Cross-sectional n_bins sort of signal with per-period weighted portfolio returns.

SortAssignments

Formation-time bin assignments and the breakpoints that produced them.

SortResult

Per-period sorted-portfolio returns plus the long-short spread.