|
19 | 19 | from polars_ta.prefix.ta import * # noqa |
20 | 20 | from polars_ta.prefix.wq import * # noqa |
21 | 21 | from polars_ta.prefix.cdl import * # noqa |
| 22 | +from polars_ta.prefix.vec import * # noqa |
22 | 23 |
|
23 | 24 | DataFrame = TypeVar("DataFrame", _pl_LazyFrame, _pl_DataFrame) |
24 | 25 | # =================================== |
25 | 26 |
|
26 | | -_ = ["DOJI", "HIGH", "CLOSE", "OPEN", "LOW"] |
27 | | -[DOJI, HIGH, CLOSE, OPEN, LOW] = [pl.col(i) for i in _] |
| 27 | +_ = ["OPEN", "DOJI", "HIGH", "CLOSE", "LOW"] |
| 28 | +[OPEN, DOJI, HIGH, CLOSE, LOW] = [pl.col(i) for i in _] |
28 | 29 |
|
29 | 30 | _ = ["_x_1", "_x_2", "_x_0", "RETURN_CC_1", "_x_3", "RETURN_CO_1", "RETURN_OC_1", "NEXT_DOJI", "RETURN_OO_1", "RETURN_OO_5"] |
30 | 31 | [_x_1, _x_2, _x_0, RETURN_CC_1, _x_3, RETURN_CO_1, RETURN_OC_1, NEXT_DOJI, RETURN_OO_1, RETURN_OO_5] = [pl.col(i) for i in _] |
@@ -118,21 +119,20 @@ def func_1_ts__asset(df: DataFrame) -> DataFrame: |
118 | 119 | """ |
119 | 120 |
|
120 | 121 |
|
121 | | -def filter_last(df: DataFrame) -> DataFrame: |
122 | | - """过滤数据,只取最后一天。实盘时可用于减少计算量 |
123 | | - 前一个调用的ts,这里可以直接调用,可以认为已经排序好 |
124 | | - `df = filter_last(df)` |
125 | | - 反之 |
126 | | - `df = filter_last(df.sort(_DATE_))` |
127 | | - """ |
128 | | - return df.filter(pl.col(_DATE_) >= df.select(pl.last(_DATE_))[0, 0]) |
| 122 | +def _filter_last(df: DataFrame, ge_date_idx: int) -> DataFrame: |
| 123 | + """过滤数据,只取最后几天。实盘时可用于减少计算量""" |
| 124 | + if ge_date_idx == 0: |
| 125 | + return df |
| 126 | + else: |
| 127 | + return df.filter(pl.col(_DATE_) >= df.select(pl.col(_DATE_).unique().sort())[ge_date_idx, 0]) |
129 | 128 |
|
130 | 129 |
|
131 | | -def main(df: DataFrame) -> DataFrame: |
| 130 | +def main(df: DataFrame, ge_date_idx: int) -> DataFrame: |
132 | 131 |
|
133 | 132 | df = func_0_ts__asset(df.sort(_ASSET_, _DATE_)).drop(*[]) |
134 | | - df = func_0_cl(df).drop(*["_x_0", "_x_1", "_x_2"]) |
| 133 | + df = func_0_cl(df).drop(*["_x_2", "_x_0", "_x_1"]) |
135 | 134 | df = func_1_ts__asset(df.sort(_ASSET_, _DATE_)).drop(*["_x_3"]) |
| 135 | + df = _filter_last(df, ge_date_idx) |
136 | 136 |
|
137 | 137 | # drop intermediate columns |
138 | 138 | # df = df.select(pl.exclude(r'^_x_\d+$')) |
|
0 commit comments