polars-ta 0.5.5__tar.gz → 0.5.7__tar.gz

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.
Files changed (78) hide show
  1. {polars_ta-0.5.5 → polars_ta-0.5.7}/PKG-INFO +1 -1
  2. polars_ta-0.5.7/polars_ta/_version.py +1 -0
  3. {polars_ta-0.5.5 → polars_ta-0.5.7}/polars_ta/prefix/vec.py +1 -0
  4. {polars_ta-0.5.5 → polars_ta-0.5.7}/polars_ta/wq/cross_sectional.py +48 -1
  5. {polars_ta-0.5.5 → polars_ta-0.5.7}/polars_ta/wq/preprocess.py +15 -4
  6. {polars_ta-0.5.5 → polars_ta-0.5.7}/polars_ta/wq/transformational.py +10 -0
  7. {polars_ta-0.5.5 → polars_ta-0.5.7}/polars_ta/wq/vector.py +3 -0
  8. polars_ta-0.5.5/polars_ta/_version.py +0 -1
  9. {polars_ta-0.5.5 → polars_ta-0.5.7}/.gitignore +0 -0
  10. {polars_ta-0.5.5 → polars_ta-0.5.7}/LICENSE +0 -0
  11. {polars_ta-0.5.5 → polars_ta-0.5.7}/README.md +0 -0
  12. {polars_ta-0.5.5 → polars_ta-0.5.7}/polars_ta/__init__.py +0 -0
  13. {polars_ta-0.5.5 → polars_ta-0.5.7}/polars_ta/candles/__init__.py +0 -0
  14. {polars_ta-0.5.5 → polars_ta-0.5.7}/polars_ta/candles/cdl1.py +0 -0
  15. {polars_ta-0.5.5 → polars_ta-0.5.7}/polars_ta/candles/cdl1_limit.py +0 -0
  16. {polars_ta-0.5.5 → polars_ta-0.5.7}/polars_ta/candles/cdl2.py +0 -0
  17. {polars_ta-0.5.5 → polars_ta-0.5.7}/polars_ta/labels/__init__.py +0 -0
  18. {polars_ta-0.5.5 → polars_ta-0.5.7}/polars_ta/labels/_nb.py +0 -0
  19. {polars_ta-0.5.5 → polars_ta-0.5.7}/polars_ta/labels/future.py +0 -0
  20. {polars_ta-0.5.5 → polars_ta-0.5.7}/polars_ta/noise.py +0 -0
  21. {polars_ta-0.5.5 → polars_ta-0.5.7}/polars_ta/performance/__init__.py +0 -0
  22. {polars_ta-0.5.5 → polars_ta-0.5.7}/polars_ta/performance/drawdown.py +0 -0
  23. {polars_ta-0.5.5 → polars_ta-0.5.7}/polars_ta/performance/returns.py +0 -0
  24. {polars_ta-0.5.5 → polars_ta-0.5.7}/polars_ta/prefix/__init__.py +0 -0
  25. {polars_ta-0.5.5 → polars_ta-0.5.7}/polars_ta/prefix/cdl.py +0 -0
  26. {polars_ta-0.5.5 → polars_ta-0.5.7}/polars_ta/prefix/labels.py +0 -0
  27. {polars_ta-0.5.5 → polars_ta-0.5.7}/polars_ta/prefix/reports.py +0 -0
  28. {polars_ta-0.5.5 → polars_ta-0.5.7}/polars_ta/prefix/ta.py +0 -0
  29. {polars_ta-0.5.5 → polars_ta-0.5.7}/polars_ta/prefix/talib.py +0 -0
  30. {polars_ta-0.5.5 → polars_ta-0.5.7}/polars_ta/prefix/tdx.py +0 -0
  31. {polars_ta-0.5.5 → polars_ta-0.5.7}/polars_ta/prefix/wq.py +0 -0
  32. {polars_ta-0.5.5 → polars_ta-0.5.7}/polars_ta/reports/__init__.py +0 -0
  33. {polars_ta-0.5.5 → polars_ta-0.5.7}/polars_ta/reports/cicc.py +0 -0
  34. {polars_ta-0.5.5 → polars_ta-0.5.7}/polars_ta/ta/README.md +0 -0
  35. {polars_ta-0.5.5 → polars_ta-0.5.7}/polars_ta/ta/__init__.py +0 -0
  36. {polars_ta-0.5.5 → polars_ta-0.5.7}/polars_ta/ta/momentum.py +0 -0
  37. {polars_ta-0.5.5 → polars_ta-0.5.7}/polars_ta/ta/operators.py +0 -0
  38. {polars_ta-0.5.5 → polars_ta-0.5.7}/polars_ta/ta/overlap.py +0 -0
  39. {polars_ta-0.5.5 → polars_ta-0.5.7}/polars_ta/ta/price.py +0 -0
  40. {polars_ta-0.5.5 → polars_ta-0.5.7}/polars_ta/ta/statistic.py +0 -0
  41. {polars_ta-0.5.5 → polars_ta-0.5.7}/polars_ta/ta/transform.py +0 -0
  42. {polars_ta-0.5.5 → polars_ta-0.5.7}/polars_ta/ta/volatility.py +0 -0
  43. {polars_ta-0.5.5 → polars_ta-0.5.7}/polars_ta/ta/volume.py +0 -0
  44. {polars_ta-0.5.5 → polars_ta-0.5.7}/polars_ta/talib/README.md +0 -0
  45. {polars_ta-0.5.5 → polars_ta-0.5.7}/polars_ta/talib/__init__.py +0 -0
  46. {polars_ta-0.5.5 → polars_ta-0.5.7}/polars_ta/tdx/README.md +0 -0
  47. {polars_ta-0.5.5 → polars_ta-0.5.7}/polars_ta/tdx/__init__.py +0 -0
  48. {polars_ta-0.5.5 → polars_ta-0.5.7}/polars_ta/tdx/_chip.py +0 -0
  49. {polars_ta-0.5.5 → polars_ta-0.5.7}/polars_ta/tdx/_nb.py +0 -0
  50. {polars_ta-0.5.5 → polars_ta-0.5.7}/polars_ta/tdx/_slow.py +0 -0
  51. {polars_ta-0.5.5 → polars_ta-0.5.7}/polars_ta/tdx/arithmetic.py +0 -0
  52. {polars_ta-0.5.5 → polars_ta-0.5.7}/polars_ta/tdx/choice.py +0 -0
  53. {polars_ta-0.5.5 → polars_ta-0.5.7}/polars_ta/tdx/energy.py +0 -0
  54. {polars_ta-0.5.5 → polars_ta-0.5.7}/polars_ta/tdx/logical.py +0 -0
  55. {polars_ta-0.5.5 → polars_ta-0.5.7}/polars_ta/tdx/moving_average.py +0 -0
  56. {polars_ta-0.5.5 → polars_ta-0.5.7}/polars_ta/tdx/over_bought_over_sold.py +0 -0
  57. {polars_ta-0.5.5 → polars_ta-0.5.7}/polars_ta/tdx/pattern.py +0 -0
  58. {polars_ta-0.5.5 → polars_ta-0.5.7}/polars_ta/tdx/pattern_feature.py +0 -0
  59. {polars_ta-0.5.5 → polars_ta-0.5.7}/polars_ta/tdx/pressure_support.py +0 -0
  60. {polars_ta-0.5.5 → polars_ta-0.5.7}/polars_ta/tdx/reference.py +0 -0
  61. {polars_ta-0.5.5 → polars_ta-0.5.7}/polars_ta/tdx/statistic.py +0 -0
  62. {polars_ta-0.5.5 → polars_ta-0.5.7}/polars_ta/tdx/trend.py +0 -0
  63. {polars_ta-0.5.5 → polars_ta-0.5.7}/polars_ta/tdx/trend_feature.py +0 -0
  64. {polars_ta-0.5.5 → polars_ta-0.5.7}/polars_ta/tdx/volume.py +0 -0
  65. {polars_ta-0.5.5 → polars_ta-0.5.7}/polars_ta/utils/__init__.py +0 -0
  66. {polars_ta-0.5.5 → polars_ta-0.5.7}/polars_ta/utils/helper.py +0 -0
  67. {polars_ta-0.5.5 → polars_ta-0.5.7}/polars_ta/utils/numba_.py +0 -0
  68. {polars_ta-0.5.5 → polars_ta-0.5.7}/polars_ta/utils/pandas_.py +0 -0
  69. {polars_ta-0.5.5 → polars_ta-0.5.7}/polars_ta/utils/pit.py +0 -0
  70. {polars_ta-0.5.5 → polars_ta-0.5.7}/polars_ta/utils/withs.py +0 -0
  71. {polars_ta-0.5.5 → polars_ta-0.5.7}/polars_ta/utils/wrapper.py +0 -0
  72. {polars_ta-0.5.5 → polars_ta-0.5.7}/polars_ta/wq/__init__.py +0 -0
  73. {polars_ta-0.5.5 → polars_ta-0.5.7}/polars_ta/wq/_nb.py +0 -0
  74. {polars_ta-0.5.5 → polars_ta-0.5.7}/polars_ta/wq/_slow.py +0 -0
  75. {polars_ta-0.5.5 → polars_ta-0.5.7}/polars_ta/wq/arithmetic.py +0 -0
  76. {polars_ta-0.5.5 → polars_ta-0.5.7}/polars_ta/wq/logical.py +0 -0
  77. {polars_ta-0.5.5 → polars_ta-0.5.7}/polars_ta/wq/time_series.py +0 -0
  78. {polars_ta-0.5.5 → polars_ta-0.5.7}/pyproject.toml +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: polars_ta
3
- Version: 0.5.5
3
+ Version: 0.5.7
4
4
  Summary: polars expressions
5
5
  Author-email: wukan <wu-kan@163.com>
6
6
  License: MIT License
@@ -0,0 +1 @@
1
+ __version__ = "0.5.7"
@@ -7,6 +7,7 @@ from polars_ta.wq.vector import vec_ir as cs_vec_ir # noqa
7
7
  from polars_ta.wq.vector import vec_kurtosis as cs_vec_kurtosis # noqa
8
8
  from polars_ta.wq.vector import vec_l2_norm as cs_vec_l2_norm # noqa
9
9
  from polars_ta.wq.vector import vec_max as cs_vec_max # noqa
10
+ from polars_ta.wq.vector import vec_median as cs_vec_median # noqa
10
11
  from polars_ta.wq.vector import vec_min as cs_vec_min # noqa
11
12
  from polars_ta.wq.vector import vec_norm as cs_vec_norm # noqa
12
13
  from polars_ta.wq.vector import vec_percentage as cs_vec_percentage # noqa
@@ -252,7 +252,6 @@ def cs_rank(x: Expr, pct: bool = True) -> Expr:
252
252
 
253
253
  Examples
254
254
  --------
255
-
256
255
  ```python
257
256
  df = pl.DataFrame({
258
257
  'a': [None, 1, 1, 1, 2, 2, 3, 10],
@@ -290,6 +289,54 @@ def cs_rank(x: Expr, pct: bool = True) -> Expr:
290
289
  return x.rank(method='dense')
291
290
 
292
291
 
292
+ def cs_rank_if(condition: Expr, x: Expr, pct: bool = True) -> Expr:
293
+ """横截面筛选排名。可实现动态票池
294
+
295
+ Parameters
296
+ ----------
297
+ condition:Expr
298
+ 条件
299
+ x:Expr
300
+ 因子
301
+ pct:bool
302
+ 排名百分比。范围:[0,1]
303
+
304
+ Examples
305
+ --------
306
+ ```python
307
+ df = pl.DataFrame({
308
+ 'a': [None, 1, 1, 1, 2, 2, 3, 10],
309
+ 'b': [1, 2, 3, 4, 5, 6, None, 8],
310
+ }).with_columns(
311
+ out1=cs_rank_if(True, pl.col('a'), True), # 与cs_rank等价
312
+ out2=cs_rank_if(pl.col('b') > 3, -pl.col('a'), False),
313
+ )
314
+
315
+ shape: (8, 4)
316
+ ┌──────┬──────┬──────────┬──────┐
317
+ │ a ┆ b ┆ out1 ┆ out2 │
318
+ │ --- ┆ --- ┆ --- ┆ --- │
319
+ │ i64 ┆ i64 ┆ f64 ┆ u32 │
320
+ ╞══════╪══════╪══════════╪══════╡
321
+ │ null ┆ 1 ┆ null ┆ null │
322
+ │ 1 ┆ 2 ┆ 0.0 ┆ null │
323
+ │ 1 ┆ 3 ┆ 0.0 ┆ null │
324
+ │ 1 ┆ 4 ┆ 0.0 ┆ 3 │
325
+ │ 2 ┆ 5 ┆ 0.333333 ┆ 2 │
326
+ │ 2 ┆ 6 ┆ 0.333333 ┆ 2 │
327
+ │ 3 ┆ null ┆ 0.666667 ┆ null │
328
+ │ 10 ┆ 8 ┆ 1.0 ┆ 1 │
329
+ └──────┴──────┴──────────┴──────┘
330
+ ```
331
+
332
+ Notes
333
+ -----
334
+ 已经产生了新的None,尽量避免之后再进行ts_时序计算
335
+
336
+ """
337
+ return cs_rank(when(condition).then(x).otherwise(None), pct)
338
+
339
+
293
340
  def _cs_qcut_rank(x: Expr, q: int = 10) -> Expr:
294
341
  """横截面上等频分箱
295
342
 
@@ -1,5 +1,6 @@
1
1
  """
2
- 补空值 → 去极值 → 标准化 → 中性化 → 标准化(可选二次标准化)
2
+ 1. 补空值 → 去极值 → 标准化 → 中性化 → 标准化(可选二次标准化)
3
+ 2. 补空值 → 去极值 → 中性化 → 标准化
3
4
 
4
5
  # 对数市值。去极值
5
6
  MC_LOG = cs_quantile(log1p(market_cap), 0.01, 0.99)
@@ -95,16 +96,26 @@ def cs_zscore_resid(y: Expr, *more_x: Expr) -> Expr:
95
96
  return cs_resid(cs_zscore(y), *more_x)
96
97
 
97
98
 
99
+ def cs_resid_zscore(y: Expr, *more_x: Expr) -> Expr:
100
+ """横截面中性化、标准化"""
101
+ return cs_resid(cs_zscore(y), *more_x)
102
+
103
+
98
104
  def cs_mad_zscore(y: Expr) -> Expr:
99
- """横截面去极值、标准化"""
105
+ """横截面MAD去极值、标准化"""
100
106
  return cs_zscore(cs_mad(y))
101
107
 
102
108
 
103
109
  def cs_mad_zscore_resid(y: Expr, *more_x: Expr) -> Expr:
104
- """横截面去极值、标准化、中性化"""
110
+ """横截面MAD去极值、标准化、中性化"""
105
111
  return cs_resid(cs_zscore(cs_mad(y)), *more_x)
106
112
 
107
113
 
108
114
  def cs_mad_zscore_resid_zscore(y: Expr, *more_x: Expr) -> Expr:
109
- """横截面去极值、标准化、中性化、二次标准化"""
115
+ """横截面去MAD极值、标准化、中性化、二次标准化"""
110
116
  return cs_zscore(cs_resid(cs_zscore(cs_mad(y)), *more_x))
117
+
118
+
119
+ def cs_quantile_zscore(y: Expr, low_limit: float = 0.025, up_limit: float = 0.975) -> Expr:
120
+ """横截面分位数去极值、标准化"""
121
+ return cs_zscore(cs_quantile(y, low_limit, up_limit))
@@ -215,6 +215,11 @@ def sigmoid(x: Expr) -> Expr:
215
215
  return 1 / (1 + (-x).exp())
216
216
 
217
217
 
218
+ def logit(x: Expr) -> Expr:
219
+ """对数几率,拉伸中间部分"""
220
+ return (x / (1 + x)).log()
221
+
222
+
218
223
  def tail(x: Expr, lower: float = 0, upper: float = 0, newval: float = 0) -> Expr:
219
224
  """If (x > lower AND x < upper) return newval, else return x. Lower, upper, newval should be constants.
220
225
 
@@ -270,3 +275,8 @@ def bool_(a: Expr) -> Expr:
270
275
  def float_(a: Expr) -> Expr:
271
276
  """int转成float"""
272
277
  return a.cast(Float32)
278
+
279
+
280
+ def nop(x: Expr) -> Expr:
281
+ """空操作"""
282
+ return x
@@ -80,3 +80,6 @@ def vec_stddev(x: Expr) -> Expr:
80
80
  def vec_sum(x: Expr) -> Expr:
81
81
  """Sum of vector field x"""
82
82
  return x.sum()
83
+
84
+ def vec_median(x: Expr) -> Expr:
85
+ return x.median()
@@ -1 +0,0 @@
1
- __version__ = "0.5.5"
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes