quantlab.factor.kunquant_cs.CrossSectionalWeightedMean#

class quantlab.factor.kunquant_cs.CrossSectionalWeightedMean(v, w)[source]#

Bases: GenericCrossSectionalOp

Weighted mean of v across symbols per bar, broadcast to every symbol.

sum(w * v) / sum(w) over the symbols whose v is finite and whose weight is finite and positive; any other symbol is left out. A bar with no such symbol is NaN. Give the weight 0 outside a universe to average over the universe only, as the cap-weighted market return of an estimation universe does.

Shares CrossSectionalZScore’s constraints: batch runs start at bar 0 and the symbol count is a multiple of the SIMD block width.

Parameters:
vOpBase

The values to average.

wOpBase

The weights, such as market capitalizations.

Examples

>>> Output(CrossSectionalWeightedMean(Input("ret"), Input("cap")), "market")
generate_body()[source]#

Return the C++ loop that writes the weighted mean of one bar.

generate_head()[source]#

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