quantlab.factor.kunquant_ts.EWSum#

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

Bases: _EWWindowOp

Exponentially weighted window sum, sum(w_age * x) over valid bars.

The weights are w_age = 0.5 ** (age / half_life) over the trailing window bars, age 0 being the current bar; they are not normalized. A NaN or infinite value adds nothing. The result is NaN for the first window - 1 bars and 0 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(EWSum(Input("ret"), 252, 63), "ret_ew_sum")
decompose(options)[source]#

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