quantlab.factor.kunquant_cs.CrossSectionalTopN#
- class quantlab.factor.kunquant_cs.CrossSectionalTopN(v, n)[source]#
Bases:
GenericCrossSectionalOp1 for the
nsymbols with the largestvon each bar, 0 elsewhere.NaN and infinite values are never selected and come out 0; when fewer than
nvalues are valid, all of them are selected. A tie at the boundary is broken by symbol order: the earlier symbol on the axis wins. The output is a 0/1 mask, such as an estimation universe of thenlargest companies by the previous bar’s market cap.The C++ body cannot read an op parameter (see
_CrossSectionalQuantileBounds), so constructingCrossSectionalTopN(v, 3000)returns an instance of a subclass created once pern(CrossSectionalTopN_3000) withnwritten into its code.isinstance(op, CrossSectionalTopN)still holds. The batch-start and SIMD-width notes ofCrossSectionalZScoreapply.- Parameters:
- vOpBase
The values to rank, larger is better.
- nint
How many symbols to select per bar, at least 1.
- Raises:
- ValueError
If
n < 1.
Examples
>>> Output(CrossSectionalTopN(BackRef(Input("marketcap"), 1), 3000), "estu")