Available in
Marketplaces, most starred first
Tags
Add to README
Shows its components, always-on context cost and install status, kept current. Add ?tokens=0 to hide the cost.
Marketplaces, most starred first
Shows its components, always-on context cost and install status, kept current. Add ?tokens=0 to hide the cost.
Marketplaces, most starred first
Shows its components, always-on context cost and install status, kept current. Add ?tokens=0 to hide the cost.
By quantskillsGPL-3.0In 1 marketplace
当需要开发、计算、验证风险平价(等风险贡献 ERC)组合时使用。手写 Ledoit-Wolf 收缩协方差稳定相关性,scipy SLSQP 求 ERC 权重,支持指数/期货/ETF 三类资产与月度 rebalance。
Claude loads one when your task matches it, or you run it by name.
Shows its components, always-on context cost and install status, kept current. Add ?tokens=0 to hide the cost.
简体中文 | English
风险平价(ERC)组合优化:手写 Ledoit-Wolf 收缩协方差稳定相关性,scipy SLSQP 求等风险贡献权重,支持指数/期货/ETF 三类资产与月度 rebalance。
skill-portfolio-risk-parity 是一个风险平价组合优化 Skill,基于等风险贡献(ERC, Equal Risk Contribution)方法,
求每类资产对组合风险贡献相等的权重,并完成契约验证、月度 rebalance 回测与离线复现。
这个 Skill 适合用于:
本 Skill 通过 panda_data SDK 拉取指数 / 期货 / ETF 三类资产日线,输出权重表、回测指标(年化波动/夏普/MDD)、
HTML 可视化报告以及离线 fixture,便于 CI 集成。
scipy.optimize.minimize(method="SLSQP") 求解| 文件 | 说明 |
|---|---|
SKILL.md | Skill 契约文档(Agent 内部使用,含完整公式) |
scripts/factor.py | ERC 权重求解入口(收益矩阵 → LW 收缩 → SLSQP → 权重表,可独立运行) |
scripts/data_loader.py | 数据加载层(指数/期货/ETF 日线 + 期货元信息 + parquet 缓存 + 交易日历) |
scripts/validate.py | 权重验证(7 项检查:契约/ERC 相等/贡献守恒/LW/杠杆/无未来函数/切片) |
scripts/backtest.py | 月度 rebalance 回测(年化波动/夏普/MDD + 等权对比) |
scripts/backtest_report_data.py | 回测时序数据包装层(HTML 报告数据源) |
scripts/report.py | HTML 报告生成入口(4 图:净值/风险贡献/权重/相关性热图) |
scripts/analysis_report.py | lookback 扫描 + LW 收缩效果对比 |
scripts/save_fixture.py | 一次性生成离线测试 fixture(联网拉真实样本) |
scripts/_make_synthetic_fixture.py | 生成合成 fixture(RandomState=42,离线基准备用) |
scripts/_edge_test.py | 边界回归测试 |
scripts/fixtures/ | 离线测试数据(Parquet 格式) |
requirements.txt | Python 依赖清单 |
references/data_guide.md | PandaAI 数据接口参考 |
LICENSE | GPLv3 协议 |
README.md / README.en.md | 中英文 README |
skill-portfolio-risk-parity/
├── SKILL.md
├── README.md
├── README.en.md
├── LICENSE
├── requirements.txt
├── notes.md
├── references/
│ └── data_guide.md
├── scripts/
│ ├── factor.py # ERC 权重求解(LW 收缩 + SLSQP + optimize_portfolio + main)
│ ├── data_loader.py # 数据加载层(load_index/fund/future + detail + 缓存 + 交易日历)
│ ├── validate.py # 7 项检查(契约/ERC/守恒/LW/杠杆/无未来/切片)
│ ├── backtest.py # 月度 rebalance 回测(年化波动/夏普/MDD + 等权对比)
│ ├── backtest_report_data.py # 回测时序数据包装层(保留 curve / drawdown / rc 序列)
│ ├── report.py # HTML 报告(4 图 + 指标卡 + 权重明细)
│ ├── analysis_report.py # lookback 扫描 + LW 收缩效果对比
│ ├── save_fixture.py # 联网生成离线 fixture
│ ├── _make_synthetic_fixture.py # 合成 fixture(测试基线)
│ ├── _edge_test.py # 边界回归测试
│ └── fixtures/
│ ├── sample_assets.parquet # 离线资产数据
│ └── sample_future_meta.json # 期货元信息(margin/multiplier)
└── reports/ # 报告产物(.gitignored)
调用 panda_data 的输入契约:
| 资产类 | 接口 | 说明 |
|---|---|---|
| 指数 | get_index_daily | 权益/债券大盘(沪深300/中证500/上证50) |
| 期货 | get_future_daily + get_future_detail | 商品/金融期货主力合约(带 margin_rate / contract_multiplier) |
| ETF | get_fund_daily | 场内 ETF(510300/511260/518880),返回 OHLCV;⚠️日期跨度 ≤1年 |
指数: 000300.SH(沪深300) 000905.SH(中证500) 000016.SH(上证50)
期货: CU_DOMINANT.SHF(铜) RB_DOMINANT.SHF(螺纹钢) AU_DOMINANT.SHF(黄金)
ETF: 510300.SH(沪深300ETF) 511260.SH(国债ETF) 518880.SH(黄金ETF)
输入契约细则:
XXX_DOMINANT.EXCHANGE(如 CU_DOMINANT.SHF)dropna(how="any")),期货夜盘/ETF 不同步会丢少量交易日_normalize_price 防御字段差异:code/ts_code→symbol、trade_date→dateget_fund_daily ≤1年限制);月度 rebalance 协方差窗口默认 60 交易日export PANDA_DATA_USERNAME=your_username
export PANDA_DATA_PASSWORD=your_password
# 可选:控制数据区间
export PANDA_DATA_START_DATE=2025-08-01
export PANDA_DATA_END_DATE=2026-07-20
cd scripts/
# 1. ERC 权重求解(单期)
python factor.py
# 输出:权重表(trade_date, symbol, weight, risk_contribution, risk_contribution_pct, ...)
# 2. 权重验证
python validate.py
# 输出:7 项检查(契约/ERC 相等/贡献守恒/LW 收缩/杠杆/无未来函数/切片)
# 3. 月度 rebalance 回测
python backtest.py
# 输出:RP 年化波动、夏普、MDD、调仓次数,及与等权组合对比
# 4. HTML 报告生成
python report.py
# 输出:reports/report.html(净值/风险贡献/权重/相关性热图 4 图)
# 1. 一次性生成 fixture(需联网 + 凭证)
python save_fixture.py
# 生成 scripts/fixtures/sample_assets.parquet + sample_future_meta.json
Built from public signals: copy clicks on this site, GitHub stars and activity, the README and the manifest. Not a security audit or an endorsement.
portfolio-risk-parity@quantskills is listed by quantskills/registry — review the source before installing
npx claudepluginhub quantskills/registry --plugin portfolio-risk-parityPlugins from other owners that cover similar ground