quantlab.factor.kunquant_ts.EWMean#

class quantlab.factor.kunquant_ts.EWMean(v, window, half_life)[source]#

Bases: _EWWindowOp

Exponentially weighted window mean, sum(w * x) / sum(w) over valid bars.

The weights are those of EWSum; dividing by the sum of the weights of the valid bars normalizes them. The result is NaN for the first window - 1 bars and for a window with no valid value.

Parameters:
vOpBase

The input series.

windowint

Number of trailing bars, the current one included.

half_lifefloat

Age in bars at which the weight is one half.

Raises:
ValueError

If window < 1 or half_life <= 0.

Examples

>>> Output(EWMean(Input("ret"), 252, 63), "ret_ew_mean")
decompose(options)[source]#

Expand into one window loop; KunQuant calls this while compiling.