Skip to content

已弃用 (2026-05-25) —— 该算子是 Layer-1 变换、非 Layer-0 原子输入,已并入 sharpe_ratio_v1。保留作历史。

做什么(One-liner)

年化 Sharpe 比率 —— 风险调整后收益的经典度量。库级 primitive,被 portfolio_risk_metrics 等 Canvas operator 消费,当前不在 Canvas 直接暴露(候选 Canvas 节点之一,待决策)。

怎么用

Python 内部调用:

python
from services.algo.time_series import sharpe_ratio
sharpe = sharpe_ratio(returns, risk_free_rate=0.02)  # 年化 2% rf

核心公式

daily_rf = rf / 252
excess_t = r_t - daily_rf
sharpe = mean(excess) / std(excess, ddof=0) × √252

特殊情况ptp(excess) == 0(恒定收益,无波动)→ 返回 0.0(不是 NaN / inf)。

假设与适用场景

假设:日频 returns + 252 交易日年化 + population std + linear daily rf 日化。

适用:组合 / 策略绩效度量,n ≥ 30 日。

不适用:intraday、厚尾资产、带杠杆的 option portfolio。

已知局限

  1. 正态假设(BTC/crypto 偏差大)
  2. 零波动 clamp 到 0(从 BUG-GOLDEN-001 经验)
  3. 年化因子 252 硬编码(monthly / weekly 需调用方换)

参考文献

Sharpe (1966) + Sharpe (1994) 修订。详见 frontmatter。

Golden Test

tests/golden/fixtures/tier1/sharpe_ratio/,1e-12 tolerance,覆盖正常序列 / 零波动 / 小样本 3 个场景。2026-04-20 passing。

Changelog

  • 1.0.0 (2026-04-20) — BUG-GOLDEN-001 修复后首次 Active(零波动零除换成 ptp-based 守卫)

Verifiable intelligence for the decisions that demand scrutiny.