quantlab.factor.kunquant_cs.CapWeightedStandardize#
- class quantlab.factor.kunquant_cs.CapWeightedStandardize(v, w, universe)[source]#
Bases:
GenericCrossSectionalOpStandardize to a weighted mean of 0 and an equal-weighted std of 1 in a universe.
On each bar, with
Uthe symbols whereuniverse > 0andvis finite:mean = sum(w * v) / sum(w) over U where w is finite and > 0 std = sample std of v (ddof=1) over U, equally weighted out = (v - mean) / std for EVERY symbol with a valid v
This is USE4’s standardization with
wthe market cap: the cap-weighted universe then has zero exposure, and the universe’s exposures have unit spread. Symbols outside the universe are shifted and scaled by the same numbers, so they get exposures too. NaN and infinite inputs come out NaN; a bar whose mean or std is undefined, or whose std is 0, is NaN for every symbol.The batch-start and SIMD-width notes of
CrossSectionalZScoreapply.- Parameters:
- vOpBase
The raw values, such as a descriptor.
- wOpBase
The weights of the mean, such as the previous bar’s market cap.
- universeOpBase
A mask, positive inside the universe (
CrossSectionalTopN’s 1).
Examples
>>> cap = BackRef(Input("marketcap"), 1) >>> estu = CrossSectionalTopN(cap, 3000) >>> Output(CapWeightedStandardize(Log(Input("marketcap")), cap, estu), "size")