Skip to content

Preprocess

polars_ta.wq.preprocess

  1. 补空值 → 去极值 → 标准化 → 中性化 → 标准化(可选二次标准化)
  2. 补空值 → 去极值 → 中性化 → 标准化

对数市值。去极值

MC_LOG = cs_quantile(log1p(market_cap), 0.01, 0.99)

对数市值。标准化。供其他因子市值中性化时使用

MC_NORM = cs_zscore(MC_LOG)

对数市值。行业中性化。直接作为因子使用

MC_NEUT = cs_zscore(cs_resid(MC_NORM, CS_SW_L1, ONE))

Functions:

Name Description
cs_3sigma

横截面3倍sigma去极值

cs_demean

横截面去均值化

cs_mad

横截面MAD去极值

cs_mad_zscore

横截面MAD去极值、标准化

cs_mad_zscore_resid

横截面MAD去极值、标准化、中性化

cs_mad_zscore_resid_zscore

横截面去MAD极值、标准化、中性化、二次标准化

cs_minmax

横截面minmax标准化

cs_quantile

横截面分位数去极值

cs_quantile_zscore

横截面分位数去极值、标准化

cs_resid

横截面多元回归取残差

cs_resid_w

横截面加权多元回归取残差

cs_resid_zscore

横截面中性化、标准化

cs_robust_scale

横截面robust scale标准化

cs_zscore

横截面zscore标准化

cs_zscore_resid

横截面标准化、中性化

cs_3sigma(x: Expr, n: float = 3.0) -> Expr

横截面3倍sigma去极值

cs_demean(x: Expr) -> Expr

横截面去均值化

Notes

Slower than multivariate regression. We need to groupby date and industry here, while multivariate regression only needs to add industry dummy variables and then groupby date

Notes

速度没有多元回归快,因为这里需要按日期行业groupby, 而多元回归只要添加行业哑变量,然后按日期groupby即可

cs_mad(x: Expr, n: float = 3.0, k: float = 1.4826) -> Expr

横截面MAD去极值

References

https://en.wikipedia.org/wiki/Median_absolute_deviation

cs_mad_zscore(y: Expr) -> Expr

横截面MAD去极值、标准化

cs_mad_zscore_resid(y: Expr, *more_x: Expr) -> Expr

横截面MAD去极值、标准化、中性化

cs_mad_zscore_resid_zscore(y: Expr, *more_x: Expr) -> Expr

横截面去MAD极值、标准化、中性化、二次标准化

cs_minmax(x: Expr) -> Expr

横截面minmax标准化

cs_quantile(x: Expr, low_limit: float = 0.025, up_limit: float = 0.975) -> Expr

横截面分位数去极值

cs_quantile_zscore(y: Expr, low_limit: float = 0.025, up_limit: float = 0.975) -> Expr

横截面分位数去极值、标准化

cs_resid(y: Expr, *more_x: Expr) -> Expr

横截面多元回归取残差

cs_resid_w(w: Expr, y: Expr, *more_x: Expr) -> Expr

横截面加权多元回归取残差

Barra中权重采用流通市值的平方根

cs_resid_zscore(y: Expr, *more_x: Expr) -> Expr

横截面中性化、标准化

cs_robust_scale(x: Expr) -> Expr

横截面robust scale标准化

cs_zscore(x: Expr, ddof: int = 0) -> Expr

横截面zscore标准化

cs_zscore_resid(y: Expr, *more_x: Expr) -> Expr

横截面标准化、中性化