Skip to content

做什么(One-liner)

值在参考序列中的百分位排名(离散 ordinal)。库级 primitive。

怎么用

python
from services.algo.statistics import percentile_rank
percentile_rank(70, [10, 20, 30, 40, 50, 60, 70, 80, 90, 100])
# → 0.6(6 个严格小于 70 / 10 总数)

核心公式

filtered = [x for x in series if x is not None]
pct = sum(1 for x in filtered if x < value) / len(filtered)

假设与适用场景

假设:ordinal discrete + tie-lower + 空序列 0.5。

适用:BLCV 同行排名、分位数触发信号、厚尾资产标准化。

不适用:精确 quantile(用 numpy.quantile type-7)、ML 特征工程。

已知局限

  1. Discrete(不插值)
  2. Tie 归 lower
  3. 空序列 0.5 convention

参考文献

Hyndman & Fan (1996) Sample Quantiles 9 种定义中 Type 1。

Golden Test

tests/golden/fixtures/tier1/percentile_rank/,1e-12,2026-04-20 passing。

Changelog

  • 1.0.0 (2026-04-20) — 首次 Active

Verifiable intelligence for the decisions that demand scrutiny.