Agent skill

A Share Portfolio Optimize

by aifinlab in aifinlab/FinClaw

A股量化组合优化。当用户说"组合优化"、"portfolio optimization"、"均值方差"、"风险平价"、"最优权重"、"Black-Litterman"、"最小方差"、"最大夏普"、"怎么分配权重"、"等风险贡献"时触发。基于现代投资组合理论,对给定标的池进行量化权重优化,支持均值方差/最小方差/风险平价/等权等多种方法,输出最优配置权重和有效前沿。支持研报风格(formal)和快…

Apache-2.0Auto-check passedBusiness, Finance & HR

Install A Share Portfolio Optimize

skills CLI
$ npx skills add aifinlab/FinClaw --skill a-share-portfolio-optimize -a claude-code

Project install by default; add -g for ~/.claude/skills/.

GitHub CLI
$ gh skill install aifinlab/FinClaw a-share-portfolio-optimize --agent claude-code

Project scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).

Manual copy
$ git clone --depth 1 https://github.com/aifinlab/FinClaw.git skills-src && mkdir -p .claude/skills && cp -r skills-src/skills/a-share-portfolio-optimize .claude/skills/a-share-portfolio-optimize && rm -rf skills-src

Use ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.

Claude Code skills documentation · loads skills from .claude/skills/

Facts

Skill name
a-share-portfolio-optimize
GitHub stars
254
Token cost
~820 tokens
SKILL.md length
233 words
Files
3 (incl. scripts, references)
Skills in repo
74
Repo updated
First seen
Licence
Apache-2.0

At a glance

A股量化组合优化。当用户说"组合优化"、"portfolio optimization"、"均值方差"、"风险平价"、"最优权重"、"Black-Litterman"、"最小方差"、"最大夏普"、"怎么分配权重"、"等风险贡献"时触发。基于现代投资组合理论,对给定标的池进行量化权重优化,支持均值方差/最小方差/风险平价/等权等多种方法,输出最优配置权重和有效前沿。支持研报风格(formal)和快…

  • Works in 4 steps: 通过 cn-stock-data kline 获取各资产日K线 → 计算日收益率序列 -> 年化收益率向量 mu → 计算收益率协方差矩阵 Sigma(默认样本协方差,可选 Ledoit-Wolf… → …
  • Tasks that involve Trading and backtesting
  • Runs Python scripts from its folder; calls python

What it does

A Share Portfolio Optimize is an agent skill from aifinlab/FinClaw. A股量化组合优化。当用户说"组合优化"、"portfolio optimization"、"均值方差"、"风险平价"、"最优权重"、"Black-Litterman"、"最小方差"、"最大夏普"、"怎么分配权重"、"等风险贡献"时触发。基于现代投资组合理论,对给定标的池进行量化权重优化,支持均值方差/最小方差/风险平价/等权等多种方法,输出最优配置权重和有效前沿。支持研报风格(formal)和快速优化风格(brief)。

Its SKILL.md is about 820 tokens, which your agent loads only when the skill is triggered. The skill folder holds 4 other files, including scripts and reference files (for example `references/portfolio-optimize-guide.md` and `scripts/portfolio_optimizer.py`).

It sits in Business, Finance & HR, covering Trading and backtesting. The licence is Apache-2.0.

When your agent uses it

  • Tasks that involve Trading and backtesting

Example prompts

  • “portfolio optimization”
  • “Black-Litterman”
  • “怎么分配权重”
  • “/a-share-portfolio-optimize”

Requirements

  • Python 3

Workflow steps

4 steps, taken from the first numbered list in SKILL.md.

  1. 通过 cn-stock-data kline 获取各资产日K线
  2. 计算日收益率序列 -> 年化收益率向量 mu
  3. 计算收益率协方差矩阵 Sigma(默认样本协方差,可选 Ledoit-Wolf 收缩)
  4. 展示关键统计

What it can do on your machine

Read from SKILL.md and the folder at commit 9e62862. It shows what the files ask for, not the result of running them.

  • Tool permissions

    Pre-approves nothing: there is no allowed-tools line, so your agent's usual permission prompts apply.

    From allowed-tools in the SKILL.md frontmatter.

  • Runs code

    Ships 1 file in scripts/ (Python), which the agent can run.

    Shell commands in SKILL.md call:

    • python

    From the folder's file list and the shell code blocks in SKILL.md.

  • Network

    No URLs in SKILL.md.

    From URLs in SKILL.md, links to its own repository left out.

  • Credentials

    Names no API keys, tokens, secrets or passwords.

    From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.

Context cost

A Share Portfolio Optimize loads about 820 tokens when it runs, and up to ~2.3k if it reads all its reference files. Until then it costs about 60 tokens; SKILL.md has 233 words of instructions outside code blocks.

Always · name and description, kept in context so the agent knows when to use it
~60
When it runs · the whole SKILL.md, loaded when a task matches
~820
With references · SKILL.md plus every file in references/, read only if the agent opens them
~2.3k

Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.

Safety

Auto-check passed

The automated check found no risky patterns in SKILL.md.

Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); the scripts in this folder are not scanned.

SKILL.md

The full file from aifinlab/FinClaw at commit 9e62862, republished under its Apache-2.0 licence (© aifinlab). 233 words, ~820 tokens.

Download SKILL.mdSave it as .claude/skills/a-share-portfolio-optimize/SKILL.md (or your agent's skills folder). This skill also uses 2 other files; get the full folder from GitHub.
name
a-share-portfolio-optimize
description
A股量化组合优化。当用户说"组合优化"、"portfolio optimization"、"均值方差"、"风险平价"、"最优权重"、"Black-Litterman"、"最小方差"、"最大夏普"、"怎么分配权重"、"等风险贡献"时触发。基于现代投资组合理论,对给定标的池进行量化权重优化,支持均值方差/最小方差/风险平价/等权等多种方法,输出最优配置权重和有效前沿。支持研报风格(formal)和快速优化风格(brief)。
数据源
bash
SCRIPTS="$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 [起始日期]
量化优化脚本
bash
OPTIM="$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
Workflow (5 steps):

Step 1: 输入资产池与约束

收集用户信息:

项目说明默认值
资产池股票代码列表用户提供
历史窗口用于估计参数的历史区间近1年(250交易日)
优化方法min_var / max_sharpe / risk_parity / equal_weight / BLmax_sharpe
无风险利率Rf2.5%
约束条件做多约束、个股上限、行业上限long_only, max 40%
预期观点(BL)用户主观收益预期(仅BL模型需要)-

Step 2: 数据获取与收益率/风险估计

  1. 通过 cn-stock-data kline 获取各资产日K线
  2. 计算日收益率序列 -> 年化收益率向量 mu
  3. 计算收益率协方差矩阵 Sigma(默认样本协方差,可选 Ledoit-Wolf 收缩)
  4. 展示关键统计:
代码名称年化收益(%)年化波动(%)夏普比最大回撤(%)

相关系数矩阵热力图描述(哪些资产高度正相关、哪些负相关/低相关提供分散化收益)。

Step 3: 组合优化求解

根据用户选择的方法执行优化:

方法 A: 均值方差 / 最大夏普 (MVO - Max Sharpe)

  • 目标: max (mu^T w - Rf) / sqrt(w^T Sigma w)
  • 约束: sum(w)=1, w>=0 (long_only), w_i<=max_weight

方法 B: 最小方差 (Min Variance)

  • 目标: min w^T Sigma w
  • 约束: sum(w)=1, w>=0

方法 C: 风险平价 (Risk Parity)

  • 目标: 各资产风险贡献相等 RC_i = w_i * (Sigma w)_i / sqrt(w^T Sigma w) = 1/N
  • 数值求解: min sum_i (RC_i - 1/N)^2

方法 D: 等权 (Equal Weight)

  • w_i = 1/N (作为基准参照)

方法 E: Black-Litterman (可选)

  • 均衡收益 pi = delta * Sigma * w_mkt
  • 融合用户观点: mu_BL = [(tauSigma)^-1 + P^T Omega^-1 P]^-1 [(tauSigma)^-1 pi + P^T Omega^-1 Q]
  • 基于 mu_BL 再做 MVO

调用 portfolio_optimizer.py 执行计算,输出最优权重。

Step 4: 结果展示与有效前沿

最优权重:

代码名称权重(%)风险贡献(%)

组合预期指标:

指标最优组合等权组合沪深300
预期年化收益(%)
预期年化波动(%)
夏普比
最大回撤(%)

有效前沿描述:

  • 最小方差组合位置(收益-波动坐标)
  • 最大夏普组合位置(切线组合)
  • 各个股在收益-风险平面上的位置
  • 当前组合相对有效前沿的位置

Step 5: 输出

风格说明
维度formal(量化研报风格)brief(快速优化风格)
篇幅4-6 页1-2 页
统计分析完整收益/风险/相关性矩阵关键指标摘要
优化方法多方法对比 + 有效前沿单一方法结果
权重输出完整表格 + 风险贡献分解权重饼图描述
敏感性参数敏感性分析不含
理论说明含模型原理简述不含
免责声明需要不需要
关键规则
  1. 历史不代表未来:基于历史数据的优化结果仅供参考,必须声明"过去业绩不预测未来收益"
  2. 估计误差:均值估计不稳定,优先推荐最小方差或风险平价等不依赖收益率估计的方法
  3. 协方差稳定性:短期协方差可能不稳定,建议使用至少1年数据,可选 Ledoit-Wolf 收缩估计
  4. 约束合理性:默认做多约束(A股做空受限),个股上限40%防止过度集中
  5. 多方法对比:formal 风格下建议对比多种方法结果,让用户理解不同优化目标的权衡
  6. 与其他 skill 联动:可用 a-share-comps 补充估值视角、a-share-technical 确认技术面、a-share-sector 检查行业暴露
  7. Black-Litterman 谨慎使用:BL 模型需要用户提供主观观点,引导用户合理设定观点及置信度

© aifinlab, Apache-2.0. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file

Files

SKILL.md and 2 other files (scripts, references) in skills/a-share-portfolio-optimize of aifinlab/FinClaw.

  • SKILL.md
  • references/portfolio-optimize-guide.md
  • scripts/portfolio_optimizer.py

Open the folder on GitHubat commit 9e62862

Compare with similar skills

A Share Portfolio Optimize next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.

A Share Portfolio Optimize compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
A Share Portfolio Optimize this skillaifinlab/FinClaw254—~820Automated safety check: PassApache-2.0
Tushare Datazillionare/zillionare3212 repos~2.3kAutomated safety check: PassNone
Tradingview MCPatilaahmettaner/tradingview-mcp5k—~1.3kAutomated safety check: PassMIT
Digital Oraclekomako-workshop/digital-oracle875—~5.9kAutomated safety check: PassMIT
Polyclawchainstacklabs/polyclaw3591 repos~2kAutomated safety check: PassApache-2.0
Markdownfacioquo/stock-indicators-dotnet1.2k—~812Automated safety check: PassApache-2.0

Similar skills

  • Tushare Data

    zillionare/zillionare

    面向中文自然语言的 Tushare 数据研究技能。用于把“看看这只股票最近怎么样”“帮我查财报趋势”“最近哪个板块最强”“北向资金在买什么”“给我导出一份行情数据”这类请求,转成可执行的数据获取、清洗、对比、筛选、导出与简要分析流程。适用于 A 股、指数、ETF/基金、财务、估值、资金流、公告新闻、板块概念与宏观数据等研究场景。

    321 GitHub starsUsed in 2 repos~2.3k tokens
    Business, Finance & HRAuto-check passed
  • Tradingview MCP

    atilaahmettaner/tradingview-mcp

    AI Trading Intelligence — live prices, 30+ technical indicators, backtesting (6 strategies), walk-forward overfitting detection, trade logs, equity curves, licensed news sentiment (Marketaux), and…

    5k GitHub stars~1.3k tokensUpdated 2 days ago
    Business, Finance & HRAuto-check passed
  • Digital Oracle

    komako-workshop/digital-oracle

    Answer prediction questions using market trading data, not opinions.

    875 GitHub stars~5.9k tokensUpdated 2 mo ago
    Business, Finance & HRAuto-check passed
  • Polyclaw

    chainstacklabs/polyclaw

    Trade on Polymarket via split + CLOB execution. An agent skill from chainstacklabs/polyclaw.

    359 GitHub starsUsed in 1 repo~2k tokens
    Business, Finance & HRAuto-check passed
  • Markdown

    facioquo/stock-indicators-dotnet

    Format and lint Markdown in this repository against GitHub Flavored Markdown and its markdownlint-cli2 configuration — headers, lists, code fences, callouts (VitePress containers on docs-site pages…

    1.2k GitHub stars~812 tokensUpdated today
    Business, Finance & HRAuto-check passed
  • Openmobius Skill

    MobiusQuant/OpenMobius-skill

    Provides multi-school trading Q&A, chart/OHLCV analysis, annotation, and fresh-market workflows covering ICT/SMC, ChanLun, Wyckoff, Price Action, Order Flow, VSA, and Elliott Wave.

    695 GitHub stars~7.2k tokensUpdated 1 mo ago
    Business, Finance & HRAuto-check passed

More from aifinlab/FinClaw

All 74 skills in this repo
  • Bank Corporate Credit Dd

    aifinlab/FinClaw

    A skill your agent uses when the user asks for help with corporate credit due diligence, enterprise credit investigation, pre-loan review, borrower analysis, document collection, management…

    254 GitHub stars~952 tokensUpdated 4 mo ago
    Auto-check passed
  • A skill your agent uses when you need a bank corporate-risk monitoring assistant for enterprise litigation/penalty/enforcement scanning (处罚/诉讼/被执行/失信等).

    254 GitHub stars~751 tokensUpdated 4 mo ago
    Auto-check passed
  • A skill your agent uses when you need a bank corporate client operating-volatility monitoring assistant (经营监测/指标波动/预警解释).

    254 GitHub stars~605 tokensUpdated 4 mo ago
    Auto-check passed
  • A skill your agent uses when you need a bank post-loan visit follow-up assistant to turn visit notes/materials into a structured memo (摘要/关键更新/风险观察/用途核验/行动项).

    254 GitHub stars~544 tokensUpdated 4 mo ago
    Auto-check passed
  • A skill your agent uses when you need a bank corporate credit issue-list assistant (问题清单/补件清单/催办台账).

    254 GitHub stars~487 tokensUpdated 4 mo ago
    Auto-check passed
  • A skill your agent uses when you need a bank corporate credit approval-opinion drafting assistant (审批意见/条款建议/有条件同意).

    254 GitHub stars~549 tokensUpdated 4 mo ago
    Auto-check passed

Questions about A Share Portfolio Optimize

What does A Share Portfolio Optimize do?

A股量化组合优化。当用户说"组合优化"、"portfolio optimization"、"均值方差"、"风险平价"、"最优权重"、"Black-Litterman"、"最小方差"、"最大夏普"、"怎么分配权重"、"等风险贡献"时触发。基于现代投资组合理论,对给定标的池进行量化权重优化,支持均值方差/最小方差/风险平价/等权等多种方法,输出最优配置权重和有效前沿。支持研报风格(formal)和快…. A Share Portfolio Optimize is an agent skill from aifinlab/FinClaw.

When should I use A Share Portfolio Optimize?

A Share Portfolio Optimize fits situations like: tasks that involve Trading and backtesting.

How do I install A Share Portfolio Optimize in Claude Code?

Run `npx skills add aifinlab/FinClaw --skill a-share-portfolio-optimize -a claude-code`. Or copy the skill folder (skills/a-share-portfolio-optimize in aifinlab/FinClaw) into .claude/skills/a-share-portfolio-optimize in your project. Claude Code loads it when a task matches its description.

How do I install A Share Portfolio Optimize in Codex?

Run `npx skills add aifinlab/FinClaw --skill a-share-portfolio-optimize -a codex`. Or copy the skill folder (skills/a-share-portfolio-optimize in aifinlab/FinClaw) into .agents/skills/a-share-portfolio-optimize in your project. Codex loads it when a task matches its description.

Can I use A Share Portfolio Optimize in Cursor, Gemini CLI or GitHub Copilot?

Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add aifinlab/FinClaw --skill a-share-portfolio-optimize -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/a-share-portfolio-optimize, .gemini/skills/a-share-portfolio-optimize, .github/skills/a-share-portfolio-optimize and .opencode/skills/a-share-portfolio-optimize in your project.

What does A Share Portfolio Optimize need to run?

Going by SKILL.md and its folder, A Share Portfolio Optimize needs Python for the scripts in its folder and the command-line tools its instructions call (python). Our summary lists: Python 3.

Does A Share Portfolio Optimize access the network?

SKILL.md contains no URLs. Any network use would come from the scripts or tools the agent runs. This is read from the text; nothing was executed.

Is A Share Portfolio Optimize safe to install?

Our automated static check of SKILL.md found no risky patterns, such as piping downloads into a shell, reading credential files or hidden Unicode. It is not a guarantee. The check reads SKILL.md only: the scripts in the folder are not scanned, so read them before running anything.

What licence does A Share Portfolio Optimize use?

A Share Portfolio Optimize is published under the Apache-2.0 licence (the repository's licence). It allows redistribution, so the full SKILL.md is shown on this page.

How many tokens does A Share Portfolio Optimize use?

About 820 tokens (SKILL.md is roughly 3.3k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full. Its references folder adds about 1.5k tokens, read only when the agent opens those files.

What are the alternatives to A Share Portfolio Optimize?

Skills that share tags, products or a category with A Share Portfolio Optimize: Tushare Data (zillionare/zillionare, 321 stars), Tradingview MCP (atilaahmettaner/tradingview-mcp, 5k stars), Digital Oracle (komako-workshop/digital-oracle, 875 stars) and Polyclaw (chainstacklabs/polyclaw, 359 stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains A Share Portfolio Optimize?

aifinlab (a GitHub user) maintains it in aifinlab/FinClaw, which has 254 GitHub stars. The repository holds 74 skills in this directory. The repository was last updated on May 13, 2026.

Source: aifinlab/FinClaw on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.