quantlab.factor.kunquant_cs.CrossSectionalSigmaClip#

class quantlab.factor.kunquant_cs.CrossSectionalSigmaClip(v, universe, data_error=10.0, clip=3.0)[source]#

Bases: GenericCrossSectionalOp

Drop data errors and clip outliers at multiples of a universe’s standard deviation.

On each bar, with U the symbols where universe > 0 and v is finite, m and s are the equally weighted mean and sample standard deviation (ddof=1) of v over U. 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 clip standard deviations from the mean, the rest pass unchanged. It runs on a raw descriptor, before CapWeightedStandardize, 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 zero s is 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; isinstance still holds. The batch-start and SIMD-width notes of CrossSectionalZScore apply.

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_error does not hold or data_error is not finite.

Examples

>>> estu = CrossSectionalTopN(BackRef(Input("marketcap"), 1), 3000)
>>> Output(CrossSectionalSigmaClip(Log(Input("marketcap")), estu, 10.0, 3.0), "lncap")
generate_body()[source]#

Return the C++ loops that bound one bar.

generate_head()[source]#

Return the C++ preamble for the generated function, which is empty.