Install any skill in seconds. Free to start, no credit card required.
Get Started Free →A股量化组合优化。当用户说"组合优化"、"portfolio optimization"、"均值方差"、"风险平价"、"最优权重"、"Black-Litterman"、"最小方差"、"最大夏普"、"怎么分配权重"、"等风险贡献"时触发。基于现代投资组合理论,对给定标的池进行量化权重优化,支持均值方差/最小方差/风险平价/等权等多种方法,输出最优配置权重和有效前沿。支持研报风格(formal)和快速优化风格(brief)。
.claude/skills/aifinlab-a-share-portfolio-optimize/SKILL.md| Test case | Without → With | Effect | Δ tokens | Δ turns |
|---|---|---|---|---|
| case-01 | ✗→✓ | ▲ Improved | 34% | 0% |
| case-05 | ✗→✓ | ▲ Improved | 0% | 0% |
| case-06 | ✗→✓ | ▲ Improved | 13% | 0% |
| case-15 | ✗→✓ | ▲ Improved | 14% | 0% |
| case-16 | ✗→✓ | ▲ Improved | 23% | 0% |
bashSCRIPTS="$SKILLS_ROOT/cn-stock-data/scripts" # 各资产日K线(用于计算收益率序列和协方差矩阵) python "$SCRIPTS/cn_stock_data.py" kline --code [CODE] --freq daily --start [起始日期] # 各资产最新行情 python "$SCRIPTS/cn_stock_data.py" quote --code [CODE1],[CODE2],[CODE3],... # 无风险利率参照(十年期国债收益率,可手动指定,默认2.5%) # 大盘基准(有效前沿对比) python "$SCRIPTS/cn_stock_data.py" kline --code SH000300 --freq daily --start [起始日期]
bashOPTIM="$SKILLS_ROOT/a-share-portfolio-optimize/scripts" # 给定资产收益率矩阵,运行组合优化 python "$OPTIM/portfolio_optimizer.py" \ --returns_csv [收益率CSV路径] \ --method [min_var|max_sharpe|risk_parity|equal_weight] \ --rf 0.025 \ --long_only \ --max_weight 0.40
Step 1: 输入资产池与约束
收集用户信息: | 项目 | 说明 | 默认值 | |------|------|--------| | 资产池 | 股票代码列表 | 用户提供 | | 历史窗口 | 用于估计参数的历史区间 | 近1年(250交易日) | | 优化方法 | min_var / max_sharpe / risk_parity / equal_weight / BL | max_sharpe | | 无风险利率 | Rf | 2.5% | | 约束条件 | 做多约束、个股上限、行业上限 | long_only, max 40% | | 预期观点(BL) | 用户主观收益预期(仅BL模型需要) | - |
Step 2: 数据获取与收益率/风险估计
| 代码 | 名称 | 年化收益(%) | 年化波动(%) | 夏普比 | 最大回撤(%) | |------|------|-----------|-----------|-------|-----------|
相关系数矩阵热力图描述(哪些资产高度正相关、哪些负相关/低相关提供分散化收益)。
Step 3: 组合优化求解
根据用户选择的方法执行优化:
方法 A: 均值方差 / 最大夏普 (MVO - Max Sharpe)
方法 B: 最小方差 (Min Variance)
方法 C: 风险平价 (Risk Parity)
方法 D: 等权 (Equal Weight)
方法 E: Black-Litterman (可选)
调用 portfolio_optimizer.py 执行计算,输出最优权重。
Step 4: 结果展示与有效前沿
最优权重: | 代码 | 名称 | 权重(%) | 风险贡献(%) | |------|------|---------|-----------|
组合预期指标: | 指标 | 最优组合 | 等权组合 | 沪深300 | |------|---------|---------|---------| | 预期年化收益(%) | | | | | 预期年化波动(%) | | | | | 夏普比 | | | | | 最大回撤(%) | | | |
有效前沿描述:
Step 5: 输出
| 维度 | formal(量化研报风格) | brief(快速优化风格) | |------|---------------------|---------------------| | 篇幅 | 4-6 页 | 1-2 页 | | 统计分析 | 完整收益/风险/相关性矩阵 | 关键指标摘要 | | 优化方法 | 多方法对比 + 有效前沿 | 单一方法结果 | | 权重输出 | 完整表格 + 风险贡献分解 | 权重饼图描述 | | 敏感性 | 参数敏感性分析 | 不含 | | 理论说明 | 含模型原理简述 | 不含 | | 免责声明 | 需要 | 不需要 |
| Case | Status | Duration (ms) | Turns | Tokens | Tool calls | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Without | With | Δ | Without | With | Δ | Without | With | Δ | Without | With | Δ | ||
case-14 | fail→fail | 10,372 | 11,854 | +14% | 1 | 1 | 0% | 1,497 | 3,817 | +155% | 0 | 0 | — |
case-20 | pass→fail | 37,876 | 10,564 | -72% | 1 | 1 | 0% | 5,648 | 2,148 | -62% | 0 | 0 | — |
case-21 | pass→fail | 18,487 | 9,329 | -50% | 1 | 1 | 0% | 2,957 | 2,207 | -25% | 0 | 0 | — |
case-01 | fail→pass | 38,285 | 42,733 | +12% | 1 | 1 | 0% | 7,117 | 9,516 | +34% | 0 | 0 | — |
case-02 | fail→fail | 21,914 | 79,023 | +261% | 1 | 1 | 0% | 4,039 | 9,829 | +143% | 0 | 0 | — |
case-03 | fail→fail | 28,618 | 11,181 | -61% | 1 | 1 | 0% | 5,358 | 2,251 | -58% | 0 | 0 | — |
case-04 | fail→fail | 30,223 | 13,227 | -56% | 1 | 1 | 0% | 4,550 | 2,240 | -51% | 0 | 0 | — |
case-05 | fail→pass | 20,149 | 15,903 | -21% | 1 | 1 | 0% | 3,285 | 3,280 | -0% | 0 | 0 | — |
case-06 | fail→pass | 14,108 | 5,544 | -61% | 1 | 1 | 0% | 2,163 | 2,446 | +13% | 0 | 0 | — |
case-07 | pass→pass | 18,760 | 20,324 | +8% | 1 | 1 | 0% | 3,005 | 4,924 | +64% | 0 | 0 | — |
case-08 | pass→pass | 18,061 | 18,452 | +2% | 1 | 1 | 0% | 2,934 | 4,200 | +43% | 0 | 0 | — |
case-09 | pass→pass | 21,074 | 35,590 | +69% | 1 | 1 | 0% | 3,149 | 7,141 | +127% | 0 | 0 | — |
case-10 | pass→fail | 21,699 | 14,090 | -35% | 1 | 1 | 0% | 3,015 | 3,738 | +24% | 0 | 0 | — |
case-11 | pass→pass | 14,401 | 9,298 | -35% | 1 | 1 | 0% | 2,270 | 2,995 | +32% | 0 | 0 | — |
case-12 | pass→pass | 18,056 | 10,927 | -39% | 1 | 1 | 0% | 2,472 | 3,610 | +46% | 0 | 0 | — |
case-13 | pass→pass | 11,772 | 13,379 | +14% | 1 | 1 | 0% | 1,707 | 3,887 | +128% | 0 | 0 | — |
case-15 | fail→pass | 18,110 | 10,982 | -39% | 1 | 1 | 0% | 2,689 | 3,056 | +14% | 0 | 0 | — |
case-16 | fail→pass | 16,258 | 9,634 | -41% | 1 | 1 | 0% | 2,294 | 2,818 | +23% | 0 | 0 | — |
case-17 | fail→fail | 7,583 | 3,577 | -53% | 1 | 1 | 0% | 1,194 | 2,059 | +72% | 0 | 0 | — |
case-18 | pass→pass | 10,942 | 4,392 | -60% | 1 | 1 | 0% | 1,777 | 2,291 | +29% | 0 | 0 | — |
case-19 | pass→pass | 8,084 | 7,408 | -8% | 1 | 1 | 0% | 1,278 | 2,569 | +101% | 0 | 0 | — |
case-22 | pass→pass | 22,129 | 36,914 | +67% | 1 | 1 | 0% | 3,599 | 6,750 | +88% | 0 | 0 | — |
case-23 | fail→pass | 12,717 | 7,542 | -41% | 1 | 1 | 0% | 1,900 | 2,475 | +30% | 0 | 0 | — |
DecimalAI ran this skill against gemini-3.6-flash twice over the same eval suite — once with the skill loaded and once without — and compared the two runs case by case. 23 cases were attempted, and 19 counted toward the lift figure. The other 4 produced results that are not comparable between the two arms, so they are excluded from the headline rather than averaged into it. The headline lift of +13 percentage points is the difference between those two pass rates over the 19 comparable cases. 3 cases got worse with the skill loaded, and they are included in that figure.
Without the skill loaded, the model failed this case. With it loaded, the same prompt on the same model passed. This is one improved case from the latest verified run; every case, including any that regressed, is in the table above.
| Model | Method | Date | Lift |
|---|---|---|---|
| gemini-3.6-flash | verified | 8/28/2026 | +21% |
Other measured skills in the registry, with their headline benchmark lift.