quantlab.factor.kunquant_ts.EWResidualStd#

class quantlab.factor.kunquant_ts.EWResidualStd(y, x, window, half_life)[source]#

Bases: _EWWindowOp

Standard deviation of the residual of EWBeta’s fit of y on x.

With alpha and beta the exponentially weighted least-squares intercept and slope (see EWBeta), the result is sqrt(sum(w * (y - alpha - beta * x)**2) / sum(w)) over the bars where both are valid, computed in closed form as sqrt(var_w(y) - cov_w(x, y)**2 / var_w(x)) and floored at 0 before the root. A weighted population figure, like EWVar; USE4’s HSIGMA with (y, x) the stock’s and the market’s excess returns. NaN for the first window - 1 bars and when x does not vary over the valid bars.

Parameters:
yOpBase

The regressand, such as a stock’s excess return.

xOpBase

The regressor, such as the market’s excess return.

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(EWResidualStd(Input("excess"), Input("market_excess"), 252, 63), "hsigma")
decompose(options)[source]#

Expand into two window loops; KunQuant calls this while compiling.