quantlab.factor.kunquant_cs.CrossSectionalWLSResidual#
- class quantlab.factor.kunquant_cs.CrossSectionalWLSResidual(y, x, w, universe)[source]#
Bases:
GenericCrossSectionalOpResidual of a per-bar weighted least-squares fit of
yonx, with an intercept.On each bar the fit uses the symbols where
universe > 0,yandxare finite andwis finite and positive:b = sum(w (x - mx)(y - my)) / sum(w (x - mx)**2) out = y - my - b (x - mx) for EVERY symbol with a finite y
mxandmybeing the weighted means of the fit sample. The residual has zero weighted covariance withxover the fit sample. This orthogonalizes one style against another, as USE4 orthogonalizes Residual Volatility against Beta and Non-linear Size against Size. A symbol whosexis missing is taken atmxand so keepsy - my. A bar with no fit sample, or wherexdoes not vary over it (its centred spread below 1e-10 of its uncentred one), is NaN for every symbol.The batch-start and SIMD-width notes of
CrossSectionalZScoreapply.- Parameters:
- yOpBase
The values to orthogonalize.
- xOpBase
The regressor.
- wOpBase
The regression weights, such as the square root of market cap.
- universeOpBase
A mask, positive for the symbols the fit uses.
Examples
>>> Output(CrossSectionalWLSResidual(size_cubed, size, Sqrt(cap), estu), "nlsize")