quantlab.factor.kunquant_cs.CrossSectionalSigmaClip#
- class quantlab.factor.kunquant_cs.CrossSectionalSigmaClip(v, universe, data_error=10.0, clip=3.0)[source]#
Bases:
GenericCrossSectionalOpDrop data errors and clip outliers at multiples of a universe’s standard deviation.
On each bar, with
Uthe symbols whereuniverse > 0andvis finite,mandsare the equally weighted mean and sample standard deviation (ddof=1) ofvoverU. Then, for every symbol:out = NaN where |v - m| > data_error * s out = clip(v, m - clip * s, m + clip * s) elsewhere
This is USE4’s outlier step (Methodology Notes §2.2, p.8): a value so extreme it is taken as a data error is removed, a large but legitimate one is trimmed to
clipstandard deviations from the mean, the rest pass unchanged. It runs on a raw descriptor, beforeCapWeightedStandardize, so the bounds sit around the descriptor’s own (equally weighted) centre. NaN and infinite inputs come out NaN; a bar with fewer than two universe values or a zerosis NaN for every symbol.The C++ body cannot read an op parameter (see
_CrossSectionalQuantileBounds), so each(data_error, clip)pair gets a class of its own (CrossSectionalSigmaClip_10p0_3p0) with the thresholds written in;isinstancestill holds. The batch-start and SIMD-width notes ofCrossSectionalZScoreapply.- Parameters:
- vOpBase
The raw values, such as a descriptor.
- universeOpBase
A mask, positive for the symbols the mean and std are taken over.
- data_errorfloat, default 10.0
Standard deviations from the mean beyond which a value is dropped.
- clipfloat, default 3.0
Standard deviations from the mean values are clipped to, at most
data_error.
- Raises:
- ValueError
If
0 < clip <= data_errordoes not hold ordata_erroris not finite.
Examples
>>> estu = CrossSectionalTopN(BackRef(Input("marketcap"), 1), 3000) >>> Output(CrossSectionalSigmaClip(Log(Input("marketcap")), estu, 10.0, 3.0), "lncap")