Skip to content

相关性矩阵

命名序列的 Pearson 相关性矩阵。作为 portfolio 优化、criticality、cointegration 的输入。与逐标的 transform primitive 不同,correlation_matrix_v1 fan out —— 它将两个及以上所连标的聚合为单个 N×N 矩阵。

做什么(One-liner)

Layer-1 聚合变换:消费两个及以上命名序列,输出单个 N×N Pearson 相关性矩阵。对角线为 1.0;矩阵对称。

输入

  • named_series(object,必填)—— 命名序列字典,{ name: [values] }

输出

  • correlation_matrix —— 命名序列上的 N×N Pearson 相关性(nested dict {name_i: {name_j: ρ}})。

怎么用

  1. 提供 named_series{ name: [values] } 字典),或连两个及以上 Price Factor。
  2. 查看相关性矩阵。
python
from services.analysis.primitives import correlation_matrix
correlation_matrix({
    "SPY": [1, 2, 3, 4, 5],
    "TLT": [5, 4, 3, 2, 1],
})
# → {"SPY": {"SPY": 1.0, "TLT": -1.0}, "TLT": {"SPY": -1.0, "TLT": 1.0}}

核心公式

ρ_{ij} = Cov(X_i, X_j) / (σ_i × σ_j)   # numpy.corrcoef

假设与适用场景

假设:同步 + 同长度 + n≥2。

适用:portfolio 协方差、regime、herd-risk criticality;任意资产类别,任意频率,最少 2 个观测。

不适用:非线性、pairwise 缺失、高维低样本(用 Ledoit-Wolf)。

已知局限

  1. Pearson 线性假设(非单调关系漏)。
  2. 对离群值与回溯窗口敏感。
  3. 无 pairwise complete observations。
  4. 厚尾低估。

参考文献

Pearson (1895) 原始 + Ledoit-Wolf (2004) shrinkage 改进。

Golden Test

tests/golden/fixtures/tier1/correlation_matrix/,1e-12 tolerance,2026-05-25 passing。参考:numpy.corrcoef

Changelog

  • 1.1.0 (2026-05-25) —— 提升为 Active 的 Layer-1 变换;并入已弃用 Layer-0 correlation_matrix 卡片的完整治理字段。
  • 1.0.0 (2026-05-23) —— 初始 edge-first Layer-1 Draft 卡片。

Verifiable intelligence for the decisions that demand scrutiny.