Assign stocks to portfolios using group-specific breakpoints.
Parameters
Name
Type
Description
Default
data
polars.DataFrame or polars.LazyFrame
Stocks to sort.
required
variable
str
Column containing the sort values.
required
bins
int or polars.DataFrame
Number of equally spaced quantile portfolios, or a table with one row per group. Supply the group keys and the interior breakpoint columns in ascending order.
required
group
str or list[str]
Columns identifying the cross-section.
required
nyse
bool
Use only observations with exchcd == 1 to calculate quantiles. Applies when bins is an integer.
False
label
str
Name of the portfolio column.
'portfolio'
assign_ties
str
Where to place a stock exactly on a breakpoint. Use “lower” (the default), “upper”, or “both”. With repeated breakpoints, “both” assigns the stock to every interval that contains it.
'lower'
quantile_method
str
How to calculate breakpoints when bins is an integer. Defaults to "linear" (R type 7). See EAPExprNamespace.quantile() for the StatsPAI and NumPy method names.
'linear'
Returns
Name
Type
Description
polars.DataFrame or polars.LazyFrame
Input rows with 1-based portfolio numbers. Missing sort values or breakpoints give a null assignment. With “both”, a stock may produce several rows.