-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
29 changed files
with
310 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
直接调用`TA-Lib` | ||
直接调用`TA-Lib`, 多输出时返回`struct`, 可以使用`.struct[0]`取到对应字段的`Series`. | ||
|
||
::: polars_ta.talib |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
::: polars_ta.tdx.choice |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
::: polars_ta.tdx.energy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
::: polars_ta.tdx.logical |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
::: polars_ta.tdx.moving_average |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
::: polars_ta.tdx.over_bought_over_sold |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
::: polars_ta.tdx.pressure_support |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
::: polars_ta.tdx.reference |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
::: polars_ta.tdx.statistic |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
::: polars_ta.tdx.trend |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
::: polars_ta.tdx.volume |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
__version__ = "0.3.1" | ||
__version__ = "0.4.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,61 +1,109 @@ | ||
""" | ||
通过`import`直接导入或更名的函数 | ||
```python | ||
from polars_ta.wq.arithmetic import add as ADD # noqa | ||
from polars_ta.wq.arithmetic import divide as DIV # noqa | ||
from polars_ta.wq.arithmetic import multiply as MUL # noqa | ||
from polars_ta.wq.arithmetic import subtract as SUB # noqa | ||
from polars_ta.wq.time_series import ts_max as MAX # noqa | ||
from polars_ta.wq.time_series import ts_min as MIN # noqa | ||
from polars_ta.wq.time_series import ts_sum as SUM # noqa | ||
``` | ||
""" | ||
from polars import Expr | ||
|
||
from polars_ta.wq.arithmetic import add as ADD # noqa | ||
from polars_ta.wq.arithmetic import divide as DIV # noqa | ||
from polars_ta.wq.arithmetic import multiply as MUL # noqa | ||
from polars_ta.wq.arithmetic import subtract as SUB # noqa | ||
from polars_ta.wq.time_series import ts_arg_max | ||
from polars_ta.wq.time_series import ts_arg_min | ||
from polars_ta.wq.time_series import ts_max | ||
from polars_ta.wq.time_series import ts_min | ||
from polars_ta.wq.time_series import ts_sum | ||
from polars_ta.wq.time_series import ts_max as MAX # noqa | ||
from polars_ta.wq.time_series import ts_min as MIN # noqa | ||
from polars_ta.wq.time_series import ts_sum as SUM # noqa | ||
|
||
|
||
def ADD(high: Expr, low: Expr) -> Expr: | ||
return high + low | ||
|
||
|
||
def DIV(high: Expr, low: Expr) -> Expr: | ||
return high / low | ||
|
||
|
||
def MAX(close: Expr, timeperiod: int = 30) -> Expr: | ||
def MAXINDEX(close: Expr, timeperiod: int = 30) -> Expr: | ||
""" | ||
Notes | ||
----- | ||
It is the maximum value of the time series, not the maximum value of multiple columns (max_horizontal) | ||
时序上窗口最大,不要与多列最大搞混 | ||
""" | ||
return ts_max(close, timeperiod) | ||
|
||
|
||
def MAXINDEX(close: Expr, timeperiod: int = 30) -> Expr: | ||
""" | ||
Comparing to `ts_arg_max` this also marks the abs. position of the max value | ||
与ts_arg_max的区别是,标记了每个区间最大值的绝对位置,可用来画图标记 | ||
Examples | ||
-------- | ||
```python | ||
from polars_ta.ta import MAXINDEX as ta_MAXINDEX | ||
from polars_ta.talib import MAXINDEX as talib_MAXINDEX | ||
from polars_ta.wq import ts_arg_max | ||
df = pl.DataFrame({ | ||
'a': [6, 2, 8, 5, 9, 4], | ||
}).with_columns( | ||
out1=ts_arg_max(pl.col('a'), 3), | ||
out2=ta_MAXINDEX(pl.col('a'), 3), | ||
out3=talib_MAXINDEX(pl.col('a'), 3), | ||
) | ||
shape: (6, 4) | ||
┌─────┬──────┬──────┬──────┐ | ||
│ a ┆ out1 ┆ out2 ┆ out3 │ | ||
│ --- ┆ --- ┆ --- ┆ --- │ | ||
│ i64 ┆ u16 ┆ i64 ┆ i32 │ | ||
╞═════╪══════╪══════╪══════╡ | ||
│ 6 ┆ null ┆ null ┆ 0 │ | ||
│ 2 ┆ null ┆ null ┆ 0 │ | ||
│ 8 ┆ 0 ┆ 2 ┆ 2 │ | ||
│ 5 ┆ 1 ┆ 2 ┆ 2 │ | ||
│ 9 ┆ 0 ┆ 4 ┆ 4 │ | ||
│ 4 ┆ 1 ┆ 4 ┆ 4 │ | ||
└─────┴──────┴──────┴──────┘ | ||
``` | ||
""" | ||
a = close.cum_count() | ||
b = ts_arg_max(close, timeperiod) | ||
return a - b - 1 | ||
|
||
|
||
def MIN(close: Expr, timeperiod: int = 30) -> Expr: | ||
return ts_min(close, timeperiod) | ||
def MININDEX(close: Expr, timeperiod: int = 30) -> Expr: | ||
""" | ||
def MININDEX(close: Expr, timeperiod: int = 30) -> Expr: | ||
Examples | ||
-------- | ||
```python | ||
from polars_ta.ta import MININDEX as ta_MININDEX | ||
from polars_ta.talib import MININDEX as talib_MININDEX | ||
from polars_ta.wq import ts_arg_min | ||
df = pl.DataFrame({ | ||
'a': [6, 2, 8, 5, 9, 4], | ||
}).with_columns( | ||
out1=ts_arg_min(pl.col('a'), 3), | ||
out2=ta_MININDEX(pl.col('a'), 3), | ||
out3=talib_MININDEX(pl.col('a'), 3), | ||
) | ||
shape: (6, 4) | ||
┌─────┬──────┬──────┬──────┐ | ||
│ a ┆ out1 ┆ out2 ┆ out3 │ | ||
│ --- ┆ --- ┆ --- ┆ --- │ | ||
│ i64 ┆ u16 ┆ i64 ┆ i32 │ | ||
╞═════╪══════╪══════╪══════╡ | ||
│ 6 ┆ null ┆ null ┆ 0 │ | ||
│ 2 ┆ null ┆ null ┆ 0 │ | ||
│ 8 ┆ 1 ┆ 1 ┆ 1 │ | ||
│ 5 ┆ 2 ┆ 1 ┆ 1 │ | ||
│ 9 ┆ 1 ┆ 3 ┆ 3 │ | ||
│ 4 ┆ 0 ┆ 5 ┆ 5 │ | ||
└─────┴──────┴──────┴──────┘ | ||
``` | ||
""" | ||
a = close.cum_count() | ||
b = ts_arg_min(close, timeperiod) | ||
return a - b - 1 | ||
|
||
|
||
def MULT(high: Expr, low: Expr) -> Expr: | ||
return high * low | ||
|
||
|
||
def SUB(high: Expr, low: Expr) -> Expr: | ||
return high - low | ||
|
||
|
||
def SUM(close: Expr, timeperiod: int = 30) -> Expr: | ||
return ts_sum(close, timeperiod) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.