polars-ta 0.5.3__py3-none-any.whl → 0.5.5__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 CHANGED
@@ -1 +1 @@
1
- __version__ = "0.5.3"
1
+ __version__ = "0.5.5"
@@ -0,0 +1 @@
1
+ from polars_ta.labels.future import * # noqa
@@ -0,0 +1,40 @@
1
+ import numpy as np
2
+ from numba import jit
3
+ from numpy import full
4
+
5
+
6
+ @jit(nopython=True, nogil=True, cache=True)
7
+ def _triple_barrier(close: np.ndarray, high: np.ndarray, low: np.ndarray, window: int, take_profit: float, stop_loss: float) -> np.ndarray:
8
+ """三重障碍打标法"""
9
+ out = full(close.shape[0], np.nan, dtype=np.float64)
10
+ for i in range(close.shape[0] - window + 1):
11
+ entry_price = close[i]
12
+ if np.isnan(entry_price):
13
+ # out[i] = 0
14
+ continue
15
+ upper_barrier = entry_price * (1 + take_profit)
16
+ lower_barrier = entry_price * (1 - stop_loss)
17
+ for j in range(i + 1, i + window):
18
+ hit_upper = high[j] >= upper_barrier
19
+ hit_lower = low[j] <= lower_barrier
20
+ if hit_upper and hit_lower:
21
+ # TODO 同一天无法知道是先触发止损还是先触发止盈
22
+ # 1. 假定离收盘价远的先触发
23
+ if high[j] - close[j] > close[j] - low[j]:
24
+ out[i] = 1 # 最高价更远,触发止盈
25
+ else:
26
+ out[i] = -1 # 最低价更远,触发止损
27
+
28
+ # out[i] = -1 # 2. 简化处理认为先触发止损
29
+ break
30
+ if hit_upper:
31
+ out[i] = 1 # 止盈
32
+ break
33
+ if hit_lower:
34
+ out[i] = -1 # 止损
35
+ break
36
+ else:
37
+ # out[i] = 0 # 1. 时间到了触发平仓
38
+ out[i] = np.sign(close[j] / entry_price - 1) # 2. 时间到了触发平仓
39
+
40
+ return out
@@ -0,0 +1,165 @@
1
+ """
2
+
3
+ 由于标签的定义比较灵活,所以以下代码主要用于参考
4
+
5
+ Notes
6
+ -----
7
+ 标签都是未来数据,在机器学习中,只能用于`y`,不能用于`X`。
8
+
9
+ References
10
+ ----------
11
+ https://mp.weixin.qq.com/s/XtgYezFsslOfW-QyIMr0VA
12
+ https://github.com/Rachnog/Advanced-Deep-Trading/blob/master/bars-labels-diff/Labeling.ipynb
13
+
14
+ """
15
+ from polars import Expr, struct
16
+
17
+ from polars_ta.labels._nb import _triple_barrier
18
+ from polars_ta.utils.numba_ import batches_i2_o1, struct_to_numpy
19
+ from polars_ta.wq import cut, ts_delay, ts_log_diff, log
20
+
21
+
22
+ def ts_log_return(close: Expr, n: int = 5) -> Expr:
23
+ """将未来数据当成卖出价后移到买入价位置,计算对数收益率
24
+
25
+ Examples
26
+ --------
27
+ ```python
28
+ df = pl.DataFrame({
29
+ 'a': [None, 10, 11, 12, 9, 12, 13],
30
+ }).with_columns(
31
+ out1=ts_log_return(pl.col('a'), 3),
32
+ out2=_ts_log_return(pl.col('a'), 3),
33
+ )
34
+
35
+ shape: (7, 3)
36
+ ┌──────┬───────────┬───────────┐
37
+ │ a ┆ out1 ┆ out2 │
38
+ │ --- ┆ --- ┆ --- │
39
+ │ i64 ┆ f64 ┆ f64 │
40
+ ╞══════╪═══════════╪═══════════╡
41
+ │ null ┆ null ┆ null │
42
+ │ 10 ┆ -0.105361 ┆ -0.105361 │
43
+ │ 11 ┆ 0.087011 ┆ 0.087011 │
44
+ │ 12 ┆ 0.080043 ┆ 0.080043 │
45
+ │ 9 ┆ null ┆ null │
46
+ │ 12 ┆ null ┆ null │
47
+ │ 13 ┆ null ┆ null │
48
+ └──────┴───────────┴───────────┘
49
+ ```
50
+
51
+ """
52
+ # return (close.shift(-n) / close).log()
53
+ return log(ts_delay(close, -n) / close)
54
+
55
+
56
+ def _ts_log_return(close: Expr, n: int = 5) -> Expr:
57
+ """计算对数收益率,但将结果后移
58
+
59
+ 如果打标签方式复杂,这种最终结果后移的方法更方便
60
+ """
61
+ # return (close / close.shift(n)).log().shift(-n)
62
+ return ts_delay(ts_log_diff(close, n), -n)
63
+
64
+
65
+ def ts_simple_return(close: Expr, n: int = 5, threshold: float = 0.0, *more_threshold) -> Expr:
66
+ """简单收益率标签。支持二分类、三分类等。对收益率使用`cut`进行分类
67
+
68
+ Parameters
69
+ ----------
70
+ close
71
+ n:int
72
+ 未来n天
73
+ threshold:float
74
+ 收益率阈值,小于该值为0,大于等于该值为1
75
+ more_threshold:float
76
+ 更多的阈值,用于三分类等。小于该值为1,大于等于该值为2,以此类推
77
+
78
+ Returns
79
+ -------
80
+ Expr
81
+ 标签列, 类型为UInt32, 取值为0, 1, 2, ...
82
+
83
+ Examples
84
+ --------
85
+ ```python
86
+ df = pl.DataFrame({
87
+ 'a': [None, 10., 9.99, 9., 10., 11., 11.],
88
+ }).with_columns(
89
+ out1=label_simple_return(pl.col('a'), 1, 0),
90
+ out2=label_simple_return(pl.col('a'), 1, -0.001, 0.001),
91
+ )
92
+
93
+ shape: (7, 3)
94
+ ┌──────┬──────┬──────┐
95
+ │ a ┆ out1 ┆ out2 │
96
+ │ --- ┆ --- ┆ --- │
97
+ │ f64 ┆ u32 ┆ u32 │
98
+ ╞══════╪══════╪══════╡
99
+ │ null ┆ null ┆ null │
100
+ │ 10.0 ┆ 0 ┆ 0 │
101
+ │ 9.99 ┆ 0 ┆ 0 │
102
+ │ 9.0 ┆ 1 ┆ 2 │
103
+ │ 10.0 ┆ 1 ┆ 2 │
104
+ │ 11.0 ┆ 0 ┆ 1 │
105
+ │ 11.0 ┆ null ┆ null │
106
+ └──────┴──────┴──────┘
107
+
108
+ """
109
+ return cut(close.pct_change(n).shift(-n), threshold, *more_threshold)
110
+
111
+
112
+ def ts_triple_barrier(close: Expr, high: Expr, low: Expr, d: int = 5, take_profit: float = 0.1, stop_loss: float = 0.05) -> Expr:
113
+ """三重障碍打标法
114
+
115
+ Parameters
116
+ ----------
117
+ close:Expr
118
+ 收盘价
119
+ high:Expr
120
+ 最高价
121
+ low:Expr
122
+ 最低价
123
+ d:int
124
+ 时间窗口
125
+ take_profit:float
126
+ 止盈比例
127
+ stop_loss:float
128
+ 止损比例
129
+
130
+ Returns
131
+ -------
132
+ Expr
133
+ 标签列。取值为-1止损, 1止盈,0时间到期
134
+
135
+ Notes
136
+ -----
137
+ 1. `high`, `low`在粗略情况下可用`close`代替
138
+ 2. 时间到期时,根据盈亏返回不同的标签
139
+
140
+ Examples
141
+ --------
142
+ ```python
143
+ df = pl.DataFrame({
144
+ "close": [np.nan, 1, 1, 1.0],
145
+ "high": [np.nan, 1, 1.1, 1],
146
+ "low": [np.nan, 1, 1, 0.95],
147
+ }).with_columns(
148
+ out=ts_triple_barrier(pl.col("close"), pl.col("high"), pl.col("low"), 2, 0.1, 0.05)
149
+ )
150
+
151
+ shape: (4, 4)
152
+ ┌───────┬──────┬──────┬──────┐
153
+ │ close ┆ high ┆ low ┆ out │
154
+ │ --- ┆ --- ┆ --- ┆ --- │
155
+ │ f64 ┆ f64 ┆ f64 ┆ f64 │
156
+ ╞═══════╪══════╪══════╪══════╡
157
+ │ NaN ┆ NaN ┆ NaN ┆ null │
158
+ │ 1.0 ┆ 1.0 ┆ 1.0 ┆ 1.0 │
159
+ │ 1.0 ┆ 1.1 ┆ 1.0 ┆ -1.0 │
160
+ │ 1.0 ┆ 1.0 ┆ 0.95 ┆ null │
161
+ └───────┴──────┴──────┴──────┘
162
+ ```
163
+
164
+ """
165
+ return struct([close, high, low]).map_batches(lambda xx: batches_i2_o1(struct_to_numpy(xx, 3), _triple_barrier, d, take_profit, stop_loss))
@@ -1,12 +1,6 @@
1
1
  from polars import Expr
2
2
 
3
- from polars_ta.wq.arithmetic import log1p, expm1 # noqa
4
- # log return
5
- # 对数收益
6
- from polars_ta.wq.time_series import ts_log_diff as ts_log_return # noqa
7
- # simple percentage return
8
- # 简单收益
9
- from polars_ta.wq.time_series import ts_returns as ts_percent_return # noqa
3
+ from polars_ta.wq.arithmetic import log1p, expm1
10
4
 
11
5
 
12
6
  def ts_cum_return(close: Expr) -> Expr:
@@ -0,0 +1 @@
1
+ from polars_ta.labels import * # noqa
@@ -0,0 +1,17 @@
1
+ # this code is auto generated by tools/prefix_vec.py
2
+
3
+ from polars_ta.wq.vector import vec_avg as cs_vec_avg # noqa
4
+ from polars_ta.wq.vector import vec_choose as cs_vec_choose # noqa
5
+ from polars_ta.wq.vector import vec_count as cs_vec_count # noqa
6
+ from polars_ta.wq.vector import vec_ir as cs_vec_ir # noqa
7
+ from polars_ta.wq.vector import vec_kurtosis as cs_vec_kurtosis # noqa
8
+ from polars_ta.wq.vector import vec_l2_norm as cs_vec_l2_norm # noqa
9
+ from polars_ta.wq.vector import vec_max as cs_vec_max # noqa
10
+ from polars_ta.wq.vector import vec_min as cs_vec_min # noqa
11
+ from polars_ta.wq.vector import vec_norm as cs_vec_norm # noqa
12
+ from polars_ta.wq.vector import vec_percentage as cs_vec_percentage # noqa
13
+ from polars_ta.wq.vector import vec_powersum as cs_vec_powersum # noqa
14
+ from polars_ta.wq.vector import vec_range as cs_vec_range # noqa
15
+ from polars_ta.wq.vector import vec_skewness as cs_vec_skewness # noqa
16
+ from polars_ta.wq.vector import vec_stddev as cs_vec_stddev # noqa
17
+ from polars_ta.wq.vector import vec_sum as cs_vec_sum # noqa
polars_ta/ta/README.md ADDED
@@ -0,0 +1,12 @@
1
+ # polars_ta.ta
2
+
3
+ 1. Files in this folder mimic `talib`, and implement `polars` versions for the same functions
4
+ 2. Since we reduce the functino calls between `Python` and `C` code, it should be faster than `talib`.
5
+ 3. We first try to import from `ta`, then from `wq`, and only implement the function if it is not available.
6
+ 4. When there is a circular dependency, we use `polars` instead.
7
+
8
+
9
+ 1. 本文件夹中模仿`talib`,实现同名函数的`polars`版
10
+ 2. 由于减少了python与c来回调用,理论上比直接调用`talib`快
11
+ 3. 优先从`ta`中导入,然后从`wq`中导入,没有的才实现
12
+ 4. 出现循环依赖时,使用`polars`
polars_ta/ta/overlap.py CHANGED
@@ -39,7 +39,7 @@ def EMA(close: Expr, timeperiod: int = 30) -> Expr:
39
39
 
40
40
  """
41
41
  # 相当于alpha=2/(1+timeperiod)
42
- return close.ewm_mean(span=timeperiod, adjust=False, min_periods=timeperiod)
42
+ return close.ewm_mean(span=timeperiod, adjust=False, min_samples=timeperiod)
43
43
 
44
44
 
45
45
  def KAMA(close: Expr, timeperiod: int = 30) -> Expr:
@@ -78,7 +78,7 @@ def RMA(close: Expr, timeperiod: int = 30) -> Expr:
78
78
  https://github.com/twopirllc/pandas-ta/blob/main/pandas_ta/overlap/rma.py
79
79
 
80
80
  """
81
- return close.ewm_mean(alpha=1 / timeperiod, adjust=False, min_periods=timeperiod)
81
+ return close.ewm_mean(alpha=1 / timeperiod, adjust=False, min_samples=timeperiod)
82
82
 
83
83
 
84
84
  def TEMA(close: Expr, timeperiod: int = 30) -> Expr:
@@ -0,0 +1,12 @@
1
+ # polars_ta.talib
2
+
3
+ Inside this package, files are generated by `tools.codegen_talib2`.
4
+ It is a wrapper of `talib` functions, with the following features:
5
+
6
+ 1. Input and output are `Expr` instead of `Series`
7
+ 2. ~~Add skipna feature (not efficient, will update when `polars` support backward fill)~~
8
+
9
+ 本包由`tools.codegen_talib2`自动生成,是对`talib`代码的封装。实现了以下功能
10
+ 1. 输入输出由`Series`改`Expr`
11
+ 2. ~~添加跳过空值功能(效率不高,等`polars`支持反向填充,此部分将更新)~~
12
+
@@ -0,0 +1,10 @@
1
+ # polars_ta.tdx
2
+
3
+ 1. Follows the `tdx` naming convention
4
+ 2. Except for some element-wise functions, all functions are time-series functions. Pay special attention to `MAX` and similar functions.
5
+ 3. First import from `tdx`, then from `wq`, and finally from `ta`. Only implement the function if it is not available.
6
+
7
+
8
+ 1. 函数名称按照通达信来
9
+ 2. 除了部分按元素计算的函数,其它都为时序函数,特别注意`MAX`等一类不要混淆
10
+ 3. 优先从`tdx`中导入,然后从`wq`中导入,最后从`ta`,没有的才实现
@@ -85,7 +85,7 @@ def DMA(close: Expr, alpha: float = 0.5) -> Expr:
85
85
 
86
86
  求X的动态移动平均.
87
87
  算法:Y=A*X+(1-A)*Y',其中Y'表示上一周期Y值,A必须大于0且小于1.A支持变量"""
88
- return close.ewm_mean(alpha=alpha, adjust=False, min_periods=1)
88
+ return close.ewm_mean(alpha=alpha, adjust=False, min_samples=1)
89
89
 
90
90
 
91
91
  def EMA(close: Expr, N: int = 30) -> Expr:
@@ -113,7 +113,7 @@ def EXPMEMA(close: Expr, N: int = 30) -> Expr:
113
113
  """
114
114
  sma = MA(close, N)
115
115
  x = when(close.cum_count() < N).then(sma).otherwise(close)
116
- return x.ewm_mean(span=N, adjust=False, min_periods=1)
116
+ return x.ewm_mean(span=N, adjust=False, min_samples=1)
117
117
 
118
118
 
119
119
  def HOD(close: Expr, N: int = 30) -> Expr:
@@ -156,7 +156,7 @@ def SMA_CN(X: Expr, N: int, M: int) -> Expr:
156
156
 
157
157
  !!!为防止与talib版SMA误用,这里去了默认值1
158
158
  """
159
- return X.ewm_mean(alpha=M / N, adjust=False, min_periods=1)
159
+ return X.ewm_mean(alpha=M / N, adjust=False, min_samples=1)
160
160
 
161
161
 
162
162
  def SUMIF(condition: Expr, close: Expr, N: int = 30) -> Expr:
polars_ta/utils/numba_.py CHANGED
@@ -27,6 +27,7 @@ def isnan(x):
27
27
 
28
28
  @jit(nopython=True, nogil=True, cache=True)
29
29
  def full_with_window_size(arr, fill_value, dtype=None, window_size: int = 1):
30
+ """创建一个更大的数组,填充后一截数据"""
30
31
  out = full(arr.shape[0] + window_size - 1, fill_value, dtype=dtype)
31
32
  out[window_size - 1:] = arr
32
33
  return out
@@ -34,6 +35,7 @@ def full_with_window_size(arr, fill_value, dtype=None, window_size: int = 1):
34
35
 
35
36
  @jit(nopython=True, nogil=True, cache=True)
36
37
  def sliding_window_with_min_periods(arr, window_size: int, min_periods: int):
38
+ """为rolling准备的数据,当数据长度不足时,用nan填充"""
37
39
  windows = sliding_window_view(arr, window_size)
38
40
  valid_counts = np.sum(~np.isnan(windows), axis=1)
39
41
  # 修改这一行,使用布尔索引而不是np.where
@@ -0,0 +1,44 @@
1
+ import re
2
+
3
+ import polars as pl
4
+
5
+
6
+ def with_industry(df: pl.DataFrame, industry_name: str, drop_first: bool, keep_col: bool) -> pl.DataFrame:
7
+ """添加行业哑元变量
8
+
9
+ Parameters
10
+ ----------
11
+ df
12
+ industry_name:str
13
+ 行业列名
14
+ drop_first
15
+ 丢弃第一列
16
+ keep_col
17
+ 是否保留源列
18
+
19
+ Returns
20
+ -------
21
+ pl.DataFrame
22
+
23
+ """
24
+ df = df.with_columns([
25
+ # 行业处理,由浮点改成整数
26
+ pl.col(industry_name).cast(pl.UInt32),
27
+ ])
28
+
29
+ # TODO 没有行业的也过滤,这会不会有问题?已经退市了,但引入了未来数据
30
+ df = df.filter(
31
+ pl.col(industry_name).is_not_null(),
32
+ )
33
+
34
+ if keep_col:
35
+ df = df.with_columns(df.to_dummies(industry_name, drop_first=False))
36
+ else:
37
+ df = df.to_dummies(industry_name, drop_first=False)
38
+
39
+ if drop_first:
40
+ # drop_first丢弃哪个字段是随机的,非常不友好,只能在行业中性化时动态修改代码
41
+ industry_columns = sorted(filter(lambda x: re.search(rf"^{industry_name}_\d+$", x), df.columns))
42
+ return df.drop(industry_columns[0])
43
+ else:
44
+ return df
@@ -5,7 +5,7 @@ from polars import max_horizontal, sum_horizontal, min_horizontal, mean_horizont
5
5
 
6
6
 
7
7
  def abs_(x: Expr) -> Expr:
8
- """绝对值
8
+ """求绝对值
9
9
 
10
10
  Examples
11
11
  --------
@@ -39,7 +39,7 @@ def abs_(x: Expr) -> Expr:
39
39
 
40
40
 
41
41
  def add(a: Expr, b: Expr, *args) -> Expr:
42
- """水平多列加
42
+ """水平多列相加
43
43
 
44
44
  Examples
45
45
  --------
@@ -133,12 +133,12 @@ def degrees(x: Expr) -> Expr:
133
133
  return x.degrees()
134
134
 
135
135
 
136
- def densify(x: Expr) -> Expr:
136
+ def _densify(x: Expr) -> Expr:
137
137
  raise
138
138
 
139
139
 
140
140
  def div(x: Expr, y: Expr) -> Expr:
141
- """x/y的整数部分
141
+ """x除以y的整数部分
142
142
 
143
143
  Examples
144
144
  --------
@@ -170,7 +170,9 @@ def div(x: Expr, y: Expr) -> Expr:
170
170
 
171
171
 
172
172
  def divide(x: Expr, y: Expr) -> Expr:
173
- """x/y
173
+ """除法
174
+
175
+ x/y
174
176
 
175
177
  Examples
176
178
  --------
@@ -231,7 +233,9 @@ def exp(x: Expr) -> Expr:
231
233
 
232
234
 
233
235
  def expm1(x: Expr) -> Expr:
234
- """对数收益率 转 简单收益率 convert log return to simple return
236
+ """对数收益率 转 简单收益率
237
+
238
+ convert log return to simple return
235
239
 
236
240
  Examples
237
241
  --------
@@ -266,6 +270,7 @@ def floor(x: Expr) -> Expr:
266
270
 
267
271
  def fraction(x: Expr) -> Expr:
268
272
  """小数部分
273
+
269
274
  This operator removes the whole number part and returns the remaining fraction part with sign.
270
275
 
271
276
  Examples
@@ -306,7 +311,9 @@ def fraction(x: Expr) -> Expr:
306
311
 
307
312
 
308
313
  def inverse(x: Expr) -> Expr:
309
- """1/x
314
+ """倒数
315
+
316
+ 1/x
310
317
 
311
318
  Examples
312
319
  --------
@@ -335,7 +342,7 @@ def inverse(x: Expr) -> Expr:
335
342
 
336
343
 
337
344
  def log(x: Expr) -> Expr:
338
- """e为底的对数
345
+ """e为底的对数
339
346
 
340
347
  Examples
341
348
  --------
@@ -367,7 +374,7 @@ def log(x: Expr) -> Expr:
367
374
 
368
375
 
369
376
  def log10(x: Expr) -> Expr:
370
- """10为底的对数
377
+ """10为底的对数
371
378
 
372
379
  Examples
373
380
  --------
@@ -396,7 +403,9 @@ def log10(x: Expr) -> Expr:
396
403
 
397
404
 
398
405
  def log1p(x: Expr) -> Expr:
399
- """简单收益率 转 对数收益率 convert simple return to log return
406
+ """简单收益率 转 对数收益率
407
+
408
+ convert simple return to log return
400
409
 
401
410
  log(x+1)
402
411
 
@@ -427,7 +436,7 @@ def log1p(x: Expr) -> Expr:
427
436
 
428
437
 
429
438
  def log2(x: Expr) -> Expr:
430
- """2为底的对数
439
+ """2为底的对数
431
440
 
432
441
  Examples
433
442
  --------
@@ -456,12 +465,14 @@ def log2(x: Expr) -> Expr:
456
465
 
457
466
 
458
467
  def max_(a: Expr, b: Expr, *args) -> Expr:
459
- """水平多列最大值 Maximum value of all inputs. At least 2 inputs are required."""
468
+ """水平多列求最大值
469
+
470
+ Maximum value of all inputs. At least 2 inputs are required."""
460
471
  return max_horizontal(a, b, *args)
461
472
 
462
473
 
463
474
  def mean(a: Expr, b: Expr, *args) -> Expr:
464
- """水平多列均值
475
+ """水平多列求均值
465
476
 
466
477
  Examples
467
478
  --------
@@ -492,12 +503,16 @@ def mean(a: Expr, b: Expr, *args) -> Expr:
492
503
 
493
504
 
494
505
  def min_(a: Expr, b: Expr, *args) -> Expr:
495
- """水平多列最小值 Maximum value of all inputs. At least 2 inputs are required."""
506
+ """水平多列求最小值
507
+
508
+ Maximum value of all inputs. At least 2 inputs are required."""
496
509
  return min_horizontal(a, b, *args)
497
510
 
498
511
 
499
512
  def mod(x: Expr, y: Expr) -> Expr:
500
- """x%y
513
+ """求余
514
+
515
+ x%y
501
516
 
502
517
  Examples
503
518
  --------
@@ -528,7 +543,9 @@ def mod(x: Expr, y: Expr) -> Expr:
528
543
 
529
544
 
530
545
  def multiply(a: Expr, b: Expr, *args) -> Expr:
531
- """水平多列乘 Multiply all inputs. At least 2 inputs are required.
546
+ """水平多列相乘
547
+
548
+ Multiply all inputs. At least 2 inputs are required.
532
549
 
533
550
  Examples
534
551
  --------
@@ -569,7 +586,9 @@ def multiply(a: Expr, b: Expr, *args) -> Expr:
569
586
 
570
587
 
571
588
  def power(x: Expr, y: Expr) -> Expr:
572
- """x ** y
589
+ """乘幂
590
+
591
+ x ** y
573
592
 
574
593
  Examples
575
594
  --------
@@ -608,12 +627,14 @@ def radians(x: Expr) -> Expr:
608
627
 
609
628
 
610
629
  def reverse(x: Expr) -> Expr:
611
- """-x"""
630
+ """求相反数"""
612
631
  return -x
613
632
 
614
633
 
615
634
  def round_(x: Expr, decimals: int = 0) -> Expr:
616
- """四舍五入 Round input to closest integer.
635
+ """四舍五入
636
+
637
+ Round input to closest integer.
617
638
 
618
639
  Parameters
619
640
  ----------
@@ -653,7 +674,9 @@ def round_(x: Expr, decimals: int = 0) -> Expr:
653
674
 
654
675
 
655
676
  def round_down(x: Expr, f: int = 1) -> Expr:
656
- """小于输入的f的最大倍数 Round input to greatest multiple of f less than input
677
+ """小于输入的f的最大倍数
678
+
679
+ Round input to greatest multiple of f less than input
657
680
 
658
681
  Parameters
659
682
  ----------
@@ -693,6 +716,8 @@ def round_down(x: Expr, f: int = 1) -> Expr:
693
716
  def s_log_1p(x: Expr) -> Expr:
694
717
  """sign(x) * log10(1 + abs(x))
695
718
 
719
+ 一种结合符号函数和对数变换的复合函数,常用于‌保留数据符号的同时压缩数值范围‌
720
+
696
721
  Examples
697
722
  --------
698
723
  ```python
@@ -729,7 +754,7 @@ def s_log_1p(x: Expr) -> Expr:
729
754
 
730
755
 
731
756
  def sign(x: Expr) -> Expr:
732
- """符号"""
757
+ """符号函数"""
733
758
  if isinstance(x, (Expr, Series)):
734
759
  return x.sign()
735
760
  else:
@@ -737,7 +762,9 @@ def sign(x: Expr) -> Expr:
737
762
 
738
763
 
739
764
  def signed_power(x: Expr, y: Expr) -> Expr:
740
- """x raised to the power of y such that final result preserves sign of x.
765
+ """xy次幂,符号保留
766
+
767
+ x raised to the power of y such that final result preserves sign of x.
741
768
 
742
769
  Examples
743
770
  --------
@@ -793,7 +820,7 @@ def sinh(x: Expr) -> Expr:
793
820
 
794
821
 
795
822
  def softsign(x: Expr) -> Expr:
796
- """softsign是 tanh激活函数的另一个替代选择
823
+ """softsign激活函数
797
824
 
798
825
  Examples
799
826
  --------
@@ -833,7 +860,9 @@ def square(x: Expr) -> Expr:
833
860
 
834
861
 
835
862
  def subtract(x: Expr, y: Expr) -> Expr:
836
- """x-y"""
863
+ """减法
864
+
865
+ x-y"""
837
866
  return x - y
838
867
 
839
868
 
@@ -898,7 +927,7 @@ def tanh(x: Expr) -> Expr:
898
927
 
899
928
 
900
929
  def var(a: Expr, b: Expr, *args) -> Expr:
901
- """水平多列方差
930
+ """水平多列求方差
902
931
 
903
932
  Examples
904
933
  --------
@@ -932,7 +961,7 @@ def var(a: Expr, b: Expr, *args) -> Expr:
932
961
 
933
962
 
934
963
  def std(a: Expr, b: Expr, *args) -> Expr:
935
- """水平多列标准差
964
+ """水平多列求标准差
936
965
 
937
966
  Examples
938
967
  --------