Skip to content

做什么(One-liner)

同比 / 环比增长率计算。库级 primitive,None / 0 基线容错。

怎么用

python
from services.algo.time_series import growth_rate_series
growth_rate_series([100, 110, None, 132])
# → [None, 0.10, None, None]   (index 2 None, index 3 分母 None)

核心公式

g_t = (v_t - v_{t-1}) / v_{t-1}   if v_{t-1} not in (None, 0) else None

假设与适用场景

假设:simple pct change + None 容错 + 输出长度等于输入。

适用:YoY / QoQ / MoM 增长率 for 营收 / 利润 / 宏观指标。

不适用:log growth、连续 0 序列。

已知局限

  1. 负基线返回负除("从亏损转正"会失真)
  2. 无 smoothing
  3. 0 基线直接 None(不抛错)

参考文献

pandas.pct_change 定义 + Diebold (2020) 时序预测基础。

Golden Test

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

Changelog

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

Verifiable intelligence for the decisions that demand scrutiny.