polars-ta 0.5.1__py3-none-any.whl → 0.5.3__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- polars_ta/_version.py +1 -1
- polars_ta/wq/_nb.py +8 -6
- polars_ta/wq/arithmetic.py +98 -1
- polars_ta/wq/time_series.py +43 -8
- {polars_ta-0.5.1.dist-info → polars_ta-0.5.3.dist-info}/METADATA +2 -2
- {polars_ta-0.5.1.dist-info → polars_ta-0.5.3.dist-info}/RECORD +9 -9
- {polars_ta-0.5.1.dist-info → polars_ta-0.5.3.dist-info}/WHEEL +1 -1
- {polars_ta-0.5.1.dist-info → polars_ta-0.5.3.dist-info}/licenses/LICENSE +0 -0
- {polars_ta-0.5.1.dist-info → polars_ta-0.5.3.dist-info}/top_level.txt +0 -0
polars_ta/_version.py
CHANGED
@@ -1 +1 @@
|
|
1
|
-
__version__ = "0.5.
|
1
|
+
__version__ = "0.5.3"
|
polars_ta/wq/_nb.py
CHANGED
@@ -181,18 +181,20 @@ def roll_triple_corr(x1, x2, x3, window, min_periods):
|
|
181
181
|
|
182
182
|
@jit(nopython=True, nogil=True, fastmath=True, cache=True)
|
183
183
|
def _cum_prod_by(r, by):
|
184
|
+
out = by.copy()
|
184
185
|
for i in range(1, r.shape[0]):
|
185
|
-
if isnan(
|
186
|
-
|
187
|
-
return
|
186
|
+
if isnan(out[i]):
|
187
|
+
out[i] = r[i] * out[i - 1]
|
188
|
+
return out
|
188
189
|
|
189
190
|
|
190
191
|
@jit(nopython=True, nogil=True, fastmath=True, cache=True)
|
191
192
|
def _cum_sum_by(r, by):
|
193
|
+
out = by.copy()
|
192
194
|
for i in range(1, r.shape[0]):
|
193
|
-
if isnan(
|
194
|
-
|
195
|
-
return
|
195
|
+
if isnan(out[i]):
|
196
|
+
out[i] = r[i] + out[i - 1]
|
197
|
+
return out
|
196
198
|
|
197
199
|
|
198
200
|
@jit(nopython=True, nogil=True, fastmath=True, cache=True)
|
polars_ta/wq/arithmetic.py
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
import numpy as np
|
2
|
-
from polars import Expr, Series, fold, any_horizontal, Float64
|
2
|
+
from polars import Expr, Series, fold, any_horizontal, Float64, Int64
|
3
|
+
from polars import arctan2 as _arctan2
|
3
4
|
from polars import max_horizontal, sum_horizontal, min_horizontal, mean_horizontal
|
4
5
|
|
5
6
|
|
@@ -92,6 +93,16 @@ def arc_tan(x: Expr) -> Expr:
|
|
92
93
|
return x.arctan()
|
93
94
|
|
94
95
|
|
96
|
+
def arc_tan2(y: Expr, x: Expr) -> Expr:
|
97
|
+
"""反正切二值函数"""
|
98
|
+
return _arctan2(y, x)
|
99
|
+
|
100
|
+
|
101
|
+
def cbrt(x: Expr) -> Expr:
|
102
|
+
"""立方根"""
|
103
|
+
return x.cbrt()
|
104
|
+
|
105
|
+
|
95
106
|
def ceiling(x: Expr) -> Expr:
|
96
107
|
"""向上取整"""
|
97
108
|
return x.ceil()
|
@@ -107,10 +118,57 @@ def cosh(x: Expr) -> Expr:
|
|
107
118
|
return x.cosh()
|
108
119
|
|
109
120
|
|
121
|
+
def cot(x: Expr) -> Expr:
|
122
|
+
"""余切"""
|
123
|
+
return x.cot()
|
124
|
+
|
125
|
+
|
126
|
+
def cube(x: Expr) -> Expr:
|
127
|
+
"""立方"""
|
128
|
+
return x.pow(3)
|
129
|
+
|
130
|
+
|
131
|
+
def degrees(x: Expr) -> Expr:
|
132
|
+
"""弧度转角度"""
|
133
|
+
return x.degrees()
|
134
|
+
|
135
|
+
|
110
136
|
def densify(x: Expr) -> Expr:
|
111
137
|
raise
|
112
138
|
|
113
139
|
|
140
|
+
def div(x: Expr, y: Expr) -> Expr:
|
141
|
+
"""x/y的整数部分
|
142
|
+
|
143
|
+
Examples
|
144
|
+
--------
|
145
|
+
```python
|
146
|
+
df = pl.DataFrame({
|
147
|
+
'a': [None, -1.5, 0., 1.5, 2.5],
|
148
|
+
'b': [None, -1, 0, 1, 2],
|
149
|
+
}).with_columns(
|
150
|
+
out1=div(pl.col('a'), 0),
|
151
|
+
out2=div(pl.col('a'), 1),
|
152
|
+
out3=div(pl.col('a'), pl.col('b')),
|
153
|
+
)
|
154
|
+
shape: (5, 5)
|
155
|
+
┌──────┬──────┬──────┬──────┬──────┐
|
156
|
+
│ a ┆ b ┆ out1 ┆ out2 ┆ out3 │
|
157
|
+
│ --- ┆ --- ┆ --- ┆ --- ┆ --- │
|
158
|
+
│ f64 ┆ i64 ┆ i64 ┆ i64 ┆ i64 │
|
159
|
+
╞══════╪══════╪══════╪══════╪══════╡
|
160
|
+
│ null ┆ null ┆ null ┆ null ┆ null │
|
161
|
+
│ -1.5 ┆ -1 ┆ null ┆ -2 ┆ 1 │
|
162
|
+
│ 0.0 ┆ 0 ┆ null ┆ 0 ┆ null │
|
163
|
+
│ 1.5 ┆ 1 ┆ null ┆ 1 ┆ 1 │
|
164
|
+
│ 2.5 ┆ 2 ┆ null ┆ 2 ┆ 1 │
|
165
|
+
└──────┴──────┴──────┴──────┴──────┘
|
166
|
+
```
|
167
|
+
|
168
|
+
"""
|
169
|
+
return x.floordiv(y).cast(Int64, strict=False)
|
170
|
+
|
171
|
+
|
114
172
|
def divide(x: Expr, y: Expr) -> Expr:
|
115
173
|
"""x/y
|
116
174
|
|
@@ -368,6 +426,35 @@ def log1p(x: Expr) -> Expr:
|
|
368
426
|
return x.log1p()
|
369
427
|
|
370
428
|
|
429
|
+
def log2(x: Expr) -> Expr:
|
430
|
+
"""2为底的对数
|
431
|
+
|
432
|
+
Examples
|
433
|
+
--------
|
434
|
+
```python
|
435
|
+
df = pl.DataFrame({
|
436
|
+
'a': [None, -1, 0, 1, 2],
|
437
|
+
}).with_columns(
|
438
|
+
out1=log2(pl.col('a')),
|
439
|
+
)
|
440
|
+
shape: (5, 2)
|
441
|
+
┌──────┬──────┐
|
442
|
+
│ a ┆ out1 │
|
443
|
+
│ --- ┆ --- │
|
444
|
+
│ i64 ┆ f64 │
|
445
|
+
╞══════╪══════╡
|
446
|
+
│ null ┆ null │
|
447
|
+
│ -1 ┆ NaN │
|
448
|
+
│ 0 ┆ -inf │
|
449
|
+
│ 1 ┆ 0.0 │
|
450
|
+
│ 2 ┆ 1.0 │
|
451
|
+
└──────┴──────┘
|
452
|
+
```
|
453
|
+
|
454
|
+
"""
|
455
|
+
return x.log(2)
|
456
|
+
|
457
|
+
|
371
458
|
def max_(a: Expr, b: Expr, *args) -> Expr:
|
372
459
|
"""水平多列最大值 Maximum value of all inputs. At least 2 inputs are required."""
|
373
460
|
return max_horizontal(a, b, *args)
|
@@ -515,6 +602,11 @@ def power(x: Expr, y: Expr) -> Expr:
|
|
515
602
|
return x.pow(y.cast(Float64))
|
516
603
|
|
517
604
|
|
605
|
+
def radians(x: Expr) -> Expr:
|
606
|
+
"""角度转弧度"""
|
607
|
+
return x.radians()
|
608
|
+
|
609
|
+
|
518
610
|
def reverse(x: Expr) -> Expr:
|
519
611
|
"""-x"""
|
520
612
|
return -x
|
@@ -735,6 +827,11 @@ def sqrt(x: Expr) -> Expr:
|
|
735
827
|
return x.sqrt()
|
736
828
|
|
737
829
|
|
830
|
+
def square(x: Expr) -> Expr:
|
831
|
+
"""平方"""
|
832
|
+
return x.pow(2)
|
833
|
+
|
834
|
+
|
738
835
|
def subtract(x: Expr, y: Expr) -> Expr:
|
739
836
|
"""x-y"""
|
740
837
|
return x - y
|
polars_ta/wq/time_series.py
CHANGED
@@ -7,7 +7,7 @@ from polars_ols import RollingKwargs
|
|
7
7
|
|
8
8
|
import polars_ta
|
9
9
|
from polars_ta.utils.numba_ import batches_i1_o1, batches_i2_o1, batches_i2_o2, struct_to_numpy
|
10
|
-
from polars_ta.utils.pandas_ import
|
10
|
+
from polars_ta.utils.pandas_ import roll_rank
|
11
11
|
from polars_ta.wq._nb import roll_argmax, roll_argmin, roll_co_kurtosis, roll_co_skewness, roll_moment, roll_partial_corr, roll_triple_corr, _cum_prod_by, _cum_sum_by, _signals_to_size, _cum_sum_reset, _sum_split_by, roll_decay_linear, roll_decay_exp_window, roll_prod
|
12
12
|
|
13
13
|
|
@@ -555,18 +555,51 @@ def ts_ir(x: Expr, d: int = 1, min_samples: Optional[int] = None) -> Expr:
|
|
555
555
|
return ts_mean(x, d, min_samples) / ts_std_dev(x, d, 0, min_samples)
|
556
556
|
|
557
557
|
|
558
|
-
def ts_kurtosis(x: Expr, d: int = 5, min_samples: Optional[int] = None) -> Expr:
|
558
|
+
def ts_kurtosis(x: Expr, d: int = 5, bias: bool = False, min_samples: Optional[int] = None) -> Expr:
|
559
559
|
"""kurtosis of x for the last d days
|
560
560
|
|
561
561
|
时序滚动峰度
|
562
562
|
|
563
|
-
|
563
|
+
Parameters
|
564
|
+
----------
|
565
|
+
x
|
566
|
+
d
|
567
|
+
bias
|
568
|
+
有偏
|
569
|
+
min_samples
|
570
|
+
|
571
|
+
Notes
|
572
|
+
-----
|
573
|
+
`bias=False`时与`pandas`结果一样
|
574
|
+
|
575
|
+
Examples
|
564
576
|
--------
|
565
|
-
|
577
|
+
```python
|
578
|
+
df = pl.DataFrame({
|
579
|
+
'a': [None, 1, 2, 3, 4, 999],
|
580
|
+
}).with_columns(
|
581
|
+
out1=pl.col('a').map_batches(lambda x: pl.Series(pd.Series(x).rolling(4).kurt())),
|
582
|
+
out2=ts_kurtosis(pl.col('a'), 4),
|
583
|
+
)
|
584
|
+
|
585
|
+
shape: (6, 3)
|
586
|
+
┌──────┬──────────┬──────────┐
|
587
|
+
│ a ┆ out1 ┆ out2 │
|
588
|
+
│ --- ┆ --- ┆ --- │
|
589
|
+
│ i64 ┆ f64 ┆ f64 │
|
590
|
+
╞══════╪══════════╪══════════╡
|
591
|
+
│ null ┆ null ┆ null │
|
592
|
+
│ 1 ┆ null ┆ null │
|
593
|
+
│ 2 ┆ null ┆ null │
|
594
|
+
│ 3 ┆ null ┆ null │
|
595
|
+
│ 4 ┆ -1.2 ┆ -1.2 │
|
596
|
+
│ 999 ┆ 3.999946 ┆ 3.999946 │
|
597
|
+
└──────┴──────────┴──────────┘
|
598
|
+
```
|
566
599
|
|
567
600
|
"""
|
568
|
-
minp = min_samples or polars_ta.MIN_SAMPLES
|
569
|
-
return x.
|
601
|
+
minp = min_samples or polars_ta.MIN_SAMPLES
|
602
|
+
return x.rolling_kurtosis(d, min_samples=minp, bias=bias)
|
570
603
|
|
571
604
|
|
572
605
|
def ts_l2_norm(x: Expr, d: int = 5, min_samples: Optional[int] = None) -> Expr:
|
@@ -705,7 +738,7 @@ def ts_scale(x: Expr, d: int = 5, min_samples: Optional[int] = None) -> Expr:
|
|
705
738
|
return when(a != b).then((x - a) / (b - a)).otherwise(0)
|
706
739
|
|
707
740
|
|
708
|
-
def ts_skewness(x: Expr, d: int = 5, bias: bool = False) -> Expr:
|
741
|
+
def ts_skewness(x: Expr, d: int = 5, bias: bool = False, min_samples: Optional[int] = None) -> Expr:
|
709
742
|
"""Return skewness of x for the past d days
|
710
743
|
|
711
744
|
时序滚动偏度
|
@@ -716,13 +749,15 @@ def ts_skewness(x: Expr, d: int = 5, bias: bool = False) -> Expr:
|
|
716
749
|
d
|
717
750
|
bias
|
718
751
|
有偏
|
752
|
+
min_samples
|
719
753
|
|
720
754
|
Notes
|
721
755
|
-----
|
722
756
|
`bias=False`时与`pandas`结果一样
|
723
757
|
|
724
758
|
"""
|
725
|
-
|
759
|
+
minp = min_samples or polars_ta.MIN_SAMPLES
|
760
|
+
return x.rolling_skew(d, min_samples=minp, bias=bias)
|
726
761
|
|
727
762
|
|
728
763
|
def ts_std_dev(x: Expr, d: int = 5, ddof: int = 0, min_samples: Optional[int] = None) -> Expr:
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: polars_ta
|
3
|
-
Version: 0.5.
|
3
|
+
Version: 0.5.3
|
4
4
|
Summary: polars expressions
|
5
5
|
Author-email: wukan <wu-kan@163.com>
|
6
6
|
License: MIT License
|
@@ -31,7 +31,7 @@ Classifier: Programming Language :: Python
|
|
31
31
|
Requires-Python: >=3.8
|
32
32
|
Description-Content-Type: text/markdown
|
33
33
|
License-File: LICENSE
|
34
|
-
Requires-Dist: polars>=1.
|
34
|
+
Requires-Dist: polars>=1.28.0
|
35
35
|
Requires-Dist: polars-ols>=0.3.0
|
36
36
|
Requires-Dist: numpy
|
37
37
|
Requires-Dist: numba
|
@@ -1,5 +1,5 @@
|
|
1
1
|
polars_ta/__init__.py,sha256=ig6f6c1AMSpntwKjqaX3msBzVIwkI7J776IujEmiuvA,123
|
2
|
-
polars_ta/_version.py,sha256=
|
2
|
+
polars_ta/_version.py,sha256=tgzuqHKcEdKBaP57F5oXxq4XlW2n9J4Fj8ZGu7nGOZg,22
|
3
3
|
polars_ta/noise.py,sha256=LJHubBqnWlU3Bz84z07N1JB-b-hAMW2rgBF1BT4m0FE,1471
|
4
4
|
polars_ta/candles/__init__.py,sha256=AW68IuFC0gD4_OyjwLP3p22WSzSIYqlSrsS9fW_15xw,141
|
5
5
|
polars_ta/candles/cdl1.py,sha256=RnRu1QzpqEt5y0-1hlfZRUvza1no-Gj4x_dx2QWxr5A,3130
|
@@ -52,17 +52,17 @@ polars_ta/utils/pandas_.py,sha256=codb51l45TUMngY55twQaUPUxnffjvj8UEOm35zFpNE,19
|
|
52
52
|
polars_ta/utils/pit.py,sha256=YNgUE6mbwhrtA-7wyOL0PCUDdwfTQouXwage-cK6efY,4312
|
53
53
|
polars_ta/utils/wrapper.py,sha256=jbR-ZQdzBf5iWvtnJ1HsN9HdepmDbU7fUj4w8Bt2BkU,3422
|
54
54
|
polars_ta/wq/__init__.py,sha256=C3YYJc997XCUI7H_afGT_mj2m4UdHMcql4sboCVvrXU,327
|
55
|
-
polars_ta/wq/_nb.py,sha256=
|
55
|
+
polars_ta/wq/_nb.py,sha256=9N7afRiABqdjO1QPnRlP1RIKJ98cQLpv6nF3dsqUA6k,11281
|
56
56
|
polars_ta/wq/_slow.py,sha256=MfWg9FYX8NGNLWN4ezI_awf3pPTqhSq_zo0LOS4nCzw,937
|
57
|
-
polars_ta/wq/arithmetic.py,sha256=
|
57
|
+
polars_ta/wq/arithmetic.py,sha256=LSqlkHKHQGob079VrQYeqWPW9nCChyDzzWLeFUBBz30,26072
|
58
58
|
polars_ta/wq/cross_sectional.py,sha256=mHLwuXu9m4ladb6cUJVnH4OofliBSkpzmIZu6TtBoe4,13697
|
59
59
|
polars_ta/wq/logical.py,sha256=5lttGwQi9oHml7soqmxEwgIVVLpeWO7JSXmQ3-TUqlU,2261
|
60
60
|
polars_ta/wq/preprocess.py,sha256=xbESoAtsbQgXJMhnLzg4r5o2H9uwPyHfySg5skk_DUg,4188
|
61
|
-
polars_ta/wq/time_series.py,sha256=
|
61
|
+
polars_ta/wq/time_series.py,sha256=iVYIGSQxD3xbiwNPHO7w-Yw0eQ-0nDzRtNzpMXwHwQU,32212
|
62
62
|
polars_ta/wq/transformational.py,sha256=ktluqo-lcxWysFL3huNypId0EFR1wn1PmyBGO180UQo,7194
|
63
63
|
polars_ta/wq/vector.py,sha256=Qs-mHC2YsiWXoyMuXZZPzd5W5w_HL1ZgDCj9wRAnqmQ,1902
|
64
|
-
polars_ta-0.5.
|
65
|
-
polars_ta-0.5.
|
66
|
-
polars_ta-0.5.
|
67
|
-
polars_ta-0.5.
|
68
|
-
polars_ta-0.5.
|
64
|
+
polars_ta-0.5.3.dist-info/licenses/LICENSE,sha256=nREFtfwxWCCYD-ZA1jMzhhxMyTz-wGWFlnkpgg0DCtQ,1062
|
65
|
+
polars_ta-0.5.3.dist-info/METADATA,sha256=1Z0TgHnxgqVBsyJZ_qPsutzktCZQo8OBHcpovp8-C4E,8633
|
66
|
+
polars_ta-0.5.3.dist-info/WHEEL,sha256=wXxTzcEDnjrTwFYjLPcsW_7_XihufBwmpiBeiXNBGEA,91
|
67
|
+
polars_ta-0.5.3.dist-info/top_level.txt,sha256=eat2IhP79-dIGA4DAFOz1o-95--UDqfjeIgmU9TBsDQ,10
|
68
|
+
polars_ta-0.5.3.dist-info/RECORD,,
|
File without changes
|
File without changes
|