quantlab.factor.kunquant_cs.CrossSectionalTrim#

class quantlab.factor.kunquant_cs.CrossSectionalTrim(v, lower=0.01, upper=0.99)[source]#

Bases: _CrossSectionalQuantileBounds

Cross-sectional trimming (截尾): drop values outside each bar’s quantile bounds.

The bounds are computed exactly as in CrossSectionalWinsorize. A value strictly below the lower bound or strictly above the upper bound becomes NaN; a value equal to a bound is kept. Unlike winsorizing, trimming removes the outliers from the cross-section altogether, so downstream consumers see fewer valid symbols on each bar.

NaN inputs stay NaN, and an all-NaN bar stays all NaN. A bar with a single valid value returns that value. No fill is applied. The same batch-start, SIMD-width and one-class-per-quantile-pair notes as for CrossSectionalWinsorize apply.

Parameters:
vOpBase

The input series, usually a factor expression.

lowerfloat, default 0.01

Lower quantile, in [0, 1).

upperfloat, default 0.99

Upper quantile, in (lower, 1].

Raises:
ValueError

If 0 <= lower < upper <= 1 does not hold.

Examples

>>> Output(CrossSectionalTrim(alpha(all_data), 0.05, 0.95), "alpha001_trim")