Skip to content

Logical

polars_ta.tdx.logical

Functions:

Name Description
CROSS

上穿

DOWNNDAY

返回周期数内是否连跌

EVERY

一直存在

EXIST

是否存在

EXISTR

从前a日到前b日内是否存在

LAST

从前a日到前b日内一直存在

LONGCROSS

两条线维持一定周期后交叉

NDAY

返回是否持续存在X>Y

NOT

求逻辑非

UPNDAY

返回周期数内是否连涨

Attributes:

Name Type Description
ALL
ANY

ALL = EVERY module-attribute

ANY = EXIST module-attribute

CROSS(a: Expr, b: Expr) -> Expr

上穿

Examples:

df = pl.DataFrame({
    'a': [None, -1, 1, 1, 2],
    'b': [None, -1, 0, 1, 2],
    'c': [None, 0, 0, 0, 0],
    'd': [None, False, False, True, True],
}).with_columns(
    out1=CROSS(pl.col('a'), pl.col('c')),
    out2=CROSS(pl.col('b'), pl.col('c')),
    out3=CROSS(0, pl.col('b')),
    out4=CROSS(pl.col('d'), 0.5),
)
shape: (5, 8)
┌──────┬──────┬──────┬───────┬───────┬───────┬───────┬───────┐
│ a    ┆ b    ┆ c    ┆ d     ┆ out1  ┆ out2  ┆ out3  ┆ out4  │
│ ---  ┆ ---  ┆ ---  ┆ ---   ┆ ---   ┆ ---   ┆ ---   ┆ ---   │
│ i64  ┆ i64  ┆ i64  ┆ bool  ┆ bool  ┆ bool  ┆ bool  ┆ bool  │
╞══════╪══════╪══════╪═══════╪═══════╪═══════╪═══════╪═══════╡
│ null ┆ null ┆ null ┆ null  ┆ null  ┆ null  ┆ null  ┆ null  │
│ -1   ┆ -1   ┆ 0    ┆ false ┆ false ┆ false ┆ null  ┆ false │
│ 1    ┆ 0    ┆ 0    ┆ false ┆ true  ┆ false ┆ false ┆ false │
│ 1    ┆ 1    ┆ 0    ┆ true  ┆ false ┆ true  ┆ false ┆ true  │
│ 2    ┆ 2    ┆ 0    ┆ true  ┆ false ┆ false ┆ false ┆ false │
└──────┴──────┴──────┴───────┴───────┴───────┴───────┴───────┘

DOWNNDAY(close: Expr, N: int) -> Expr

返回周期数内是否连跌

EVERY(condition: Expr, N: int) -> Expr

一直存在

EXIST(condition: Expr, N: int) -> Expr

是否存在

EXISTR(condition: Expr, a: int, b: int) -> Expr

从前a日到前b日内是否存在

LAST(condition: Expr, a: int, b: int) -> Expr

从前a日到前b日内一直存在

LONGCROSS(a: Expr, b: Expr, N: int) -> Expr

两条线维持一定周期后交叉

NDAY(close: Expr, open_: Expr, N: int) -> Expr

返回是否持续存在X>Y

NOT(condition: Expr) -> Expr

求逻辑非

UPNDAY(close: Expr, N: int) -> Expr

返回周期数内是否连涨