Skip to content

Commit

Permalink
多元回归注释添加示例
Browse files Browse the repository at this point in the history
  • Loading branch information
wukan1986 committed Mar 3, 2024
1 parent 92b6901 commit 9426286
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
2 changes: 1 addition & 1 deletion polars_ta/wq/cross_sectional.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def cs_one_side(x: Expr, is_long: bool = True) -> Expr:
raise


def cs_rank(x: Expr, rate: int = 2, pct: bool = True) -> Expr:
def cs_rank(x: Expr, pct: bool = True) -> Expr:
"""Ranks the input among all the instruments and returns an equally distributed number between 0.0 and 1.0. For precise sort, use the rate as 0."""
if pct:
return x.rank() / x.count()
Expand Down
20 changes: 13 additions & 7 deletions polars_ta/wq/preprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,16 @@ def residual_multiple(cols: List[Series], add_constant: bool) -> Series:
return Series(out, nan_to_null=True)


def cs_neutralize_residual_multiple(y: Expr, *more_x: Expr, add_constant: bool = False) -> Expr:
"""多元回归"""
(*_x, is_bool) = more_x
if isinstance(is_bool, bool):
return map_batches([y, *_x], lambda xx: residual_multiple(xx, is_bool))
else:
return map_batches([y, *more_x], lambda xx: residual_multiple(xx, add_constant))
def cs_neutralize_residual_multiple(y: Expr, *more_x: Expr) -> Expr:
"""多元回归
Examples
--------
>>> cs_neutralize_residual_multiple(EP, LOG_MKT_CAP, *cs.expand_selector(df, cs.matches(r"^sw_l1_\d+$")), ONE)
Notes
-----
1. 常量1,可以通过多输入1列来完成
2. 正则表达式的用法比较特别,需用`cs.expand_selector`
"""
return map_batches([y, *more_x], lambda xx: residual_multiple(xx, False))

0 comments on commit 9426286

Please sign in to comment.