quantlab.factor.kunquant_ts.EWBeta#
- class quantlab.factor.kunquant_ts.EWBeta(y, x, window, half_life)[source]#
Bases:
_EWWindowOpSlope of the exponentially weighted least-squares fit of
yonx.The fit
y = alpha + beta * xminimizessum(w * residual**2)over the bars where both are valid, with an intercept. In closed formbeta = cov_w(x, y) / var_w(x)(seeEWCovandEWVar). NaN for the firstwindow - 1bars, and NaN or infinite whenxdoes 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 < 1orhalf_life <= 0.
Examples
>>> Output(EWBeta(Input("excess"), Input("market_excess"), 252, 63), "beta")