Skip to content

Commit

Permalink
0.9.59 新增 min_max_limit
Browse files Browse the repository at this point in the history
  • Loading branch information
zengbin93 committed Sep 8, 2024
1 parent dd65528 commit d20d48a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions czsc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@
cross_sectional_strategy,
judge_factor_direction,
monotonicity,
min_max_limit,
)


Expand Down
12 changes: 12 additions & 0 deletions czsc/eda.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,3 +159,15 @@ def monotonicity(sequence):
"""
from scipy.stats import spearmanr
return spearmanr(sequence, range(len(sequence)))[0]


def min_max_limit(x, min_val, max_val, digits=4):
"""限制 x 的取值范围在 min_val 和 max_val 之间
:param x: float, 输入值
:param min_val: float, 最小值
:param max_val: float, 最大值
:param digits: int, 保留小数位数
:return: float
"""
return round(max(min_val, min(max_val, x)), digits)

0 comments on commit d20d48a

Please sign in to comment.