← 返回 Skills 市场
jiayinian

jy-portfolio-calculation

作者 jiayinian · GitHub ↗ · v1.0.0 · MIT-0
cross-platform ⚠ suspicious
84
总下载
0
收藏
0
当前安装
1
版本数
在 OpenClaw 中安装
/install jy-portfolio-calculation
功能描述
模拟组合试算技能 - 基于恒生聚源 MCP 服务的投资组合构建、调整、成分券查询、交易记录查询及绩效指标获取工具。 **Triggers when user mentions:** - 组合构建:"模拟组合","建仓","创建组合","组合 ID","资产配置","portfolio" - 组合调整:"调仓","...
使用说明 (SKILL.md)

模拟组合试算

基于恒生聚源 (jy-financedata-api) MCP 服务的模拟投资组合试算工具,支持组合构建、调仓、持仓查询、交易流水查询及绩效指标获取。

功能范围

本技能支持以下功能:

功能 说明 工具
模拟组合构建 创建新的模拟投资组合,生成组合 ID PortfolioBuild
模拟组合调整 对已有组合进行权重调整和再平衡 PortfolioRebalance
成分券查询 查询组合在指定日期的持仓明细 PortfolioPositionQuery
交易记录查询 查询组合的交易流水明细 TradeFlowQuery
绩效指标查询 获取组合的收益率、回撤、夏普比率等指标 PortfolioIndicatorQuery
报告生成 生成组合收益报告(Markdown/PDF 格式) scripts/generate_portfolio_report_*.py

查询建议

查询需要具备的要素:

  • 组合构建:建仓日期 (YYYY-MM-DD)、证券代码/名称、数量或权重、业绩基准 (可选)
  • 组合调仓:组合 ID、调仓日期、新权重配置
  • 持仓/交易/指标查询:组合 ID

查询写法:

  • 所有工具调用均使用自然语言字符串作为 query 参数
  • 日期格式必须为 YYYY-MM-DD
  • 证券可用代码或名称表示

查询示例

# 新建组合
mcporter call jy-financedata-api.PortfolioBuild query='2026-03-20 建仓,买入贵州茅台 600519 1000 股,权重 50%,中国平安 601318 2000 股,权重 50%,业绩基准沪深 300'

# 调整组合
mcporter call jy-financedata-api.PortfolioRebalance query='组合 0439d6e585034f46846d0a70b5a967e0 在 2026-03-21 调仓,贵州茅台权重 30%,中国平安权重 70%'

# 查询持仓
mcporter call jy-financedata-api.PortfolioPositionQuery query='查询组合 0439d6e585034f46846d0a70b5a967e0 的持仓'

# 查询交易流水
mcporter call jy-financedata-api.TradeFlowQuery query='查询组合 0439d6e585034f46846d0a70b5a967e0 的交易流水'

# 查询绩效指标
mcporter call jy-financedata-api.PortfolioIndicatorQuery query='查询组合 0439d6e585034f46846d0a70b5a967e0 的绩效指标'

环境检查与配置

每次使用本技能前,必须先检查 mcporter 安装和 MCP 服务配置状态!

步骤 1:检查 mcporter 是否安装

mcporter --version

如未安装,按以下流程安装:

# 1. 通过 npm 全局安装
npm install -g mcporter

# 2. 验证安装
mcporter --version

步骤 2:检查 MCP 服务配置

# 列出所有已配置的 MCP 服务
mcporter list

预期输出(必须包含以下服务):

  • jy-financedata-api

如服务未配置,需要获取 JY_API_KEY 并配置:

  1. 获取 JY_API_KEY:向恒生聚源申请 JY_API_KEY,通过邮箱申请(首次配置需提供,配置一次即可)

    JY_API_KEY 申请路径:

    向恒生聚源官方邮箱发送邮件申请签发 数据地图 JY_API_KEY,用于接口鉴权

    申请通过后,恒生聚源将默认发送【工具版和接口版】KEY

    另外,【Skill】包可通过 https://clawhub.ai/ 自行选择下载,若需要我们通过邮件提供【Skill】,亦可在邮件中注明

    申请邮箱: mailto:[email protected]

    邮件标题: 数据地图 KEY 申请-XX 公司 - 申请人姓名

    正文模板:

    • 姓名:
    • 手机号:
    • 公司/单位全称:
    • 所属部门:
    • 岗位:
    • MCP_KEY 申请用途:
    • Skill 申请列表:
    • 是否需要 Skill 安装包:(是,邮件提供/否,自行下载)
    • 其他补充说明(可选):
  2. 配置 MCP 服务

# 配置 jy-financedata-api 服务
mcporter config add jy-financedata-api --url "https://api.gildata.com/mcp-servers/aidata-assistant-srv-api?token=你的 JY_API_KEY"
  1. 验证配置
mcporter list
  1. 使用方式
# 基础键值对传参
mcporter call 服务名称。工具 参数=值

# 示例,注意:所有服务工具的入参均为 query
mcporter call jy-financedata-api.PortfolioBuild query='2026-03-20 建仓,买入贵州茅台 600519 1000 股,权重 50%'

步骤 3:在 OpenClaw 中启用 mcporter(如未配置)

mcporter 配置文件路径:

  • Windows: C:\Users\你的用户名\config\mcporter.json
  • Linux/MacOS: /root/config/mcporter.json

OpenClaw 配置文件路径:

  • Windows: C:\Users\你的用户名\.openclaw\openclaw.json
  • Linux/MacOS: ~/.openclaw/openclaw.json

编辑 openclaw.json,在 skills 部分添加 mcporter 配置:

{
 "skills": {
 "entries": {
 "mcporter": {
 "enabled": true,
 "env": {
 "MCPORTER_CONFIG": "C:\\Users\\你的用户名\\config\\mcporter.json"
 }
 }
 }
 }
}

重启 OpenClaw 使配置生效

openclaw gateway restart

核心工作流程

流程中的工具调用能够并发调用尽量并发调用提速,但建仓/调仓与查询操作必须串行执行。

步骤 1:组合构建或调仓

根据用户需求调用 PortfolioBuild(新建组合)或 PortfolioRebalance(调整组合)。

注意事项:

  • 建仓/调仓日期不能是当天或未来日期
  • 权重总和必须等于 1,不足时自动用现金补充
  • 保存返回的组合 ID 用于后续查询

步骤 2:成分券查询(串行)

建仓/调仓完成后,调用 PortfolioPositionQuery 查询最新持仓。

步骤 3:交易流水查询(串行)

调用 TradeFlowQuery 查询组合交易记录。

步骤 4:绩效指标查询(串行)

调用 PortfolioIndicatorQuery 获取组合绩效指标。

执行顺序限制:

建仓/调仓 → (等待完成) → 成分券查询/交易记录查询/指标查询 (串行)

快速开始

场景一:新建模拟组合

用户: "我想创建一个模拟组合,2026-03-20 建仓,买入贵州茅台 1000 股,权重 50%,中国平安 2000 股,权重 50%,业绩基准沪深 300"

# Step 1: 调用 PortfolioBuild 建仓
mcporter call jy-financedata-api.PortfolioBuild query='2026-03-20 建仓,买入贵州茅台 600519 1000 股,权重 50%,中国平安 601318 2000 股,权重 50%,业绩基准沪深 300'

# 返回:组合 ID (如 0439d6e585034f46846d0a70b5a967e0)

# Step 2: 串行查询持仓
mcporter call jy-financedata-api.PortfolioPositionQuery query='查询组合 0439d6e585034f46846d0a70b5a967e0 的持仓'

# Step 3: 串行查询交易流水
mcporter call jy-financedata-api.TradeFlowQuery query='查询组合 0439d6e585034f46846d0a70b5a967e0 的交易流水'

# Step 4: 串行查询绩效指标
mcporter call jy-financedata-api.PortfolioIndicatorQuery query='查询组合 0439d6e585034f46846d0a70b5a967e0 的绩效指标'

场景二:调整已有组合

用户: "把组合 0439d6e585034f46846d0a70b5a967e0 调仓一下,2026-03-21 调仓,贵州茅台权重降到 30%,中国平安权重升到 70%"

# Step 1: 调用 PortfolioRebalance 调仓
mcporter call jy-financedata-api.PortfolioRebalance query='组合 0439d6e585034f46846d0a70b5a967e0 在 2026-03-21 调仓,贵州茅台权重 30%,中国平安权重 70%'

# Step 2: 串行查询新持仓
mcporter call jy-financedata-api.PortfolioPositionQuery query='查询组合 0439d6e585034f46846d0a70b5a967e0 的持仓'

# Step 3: 串行查询新交易流水
mcporter call jy-financedata-api.TradeFlowQuery query='查询组合 0439d6e585034f46846d0a70b5a967e0 的交易流水'

场景三:查询组合信息

用户: "查一下组合 0439d6e585034f46846d0a70b5a967e0 的持仓情况"

# 直接查询持仓 (无需先建仓/调仓)
mcporter call jy-financedata-api.PortfolioPositionQuery query='查询组合 0439d6e585034f46846d0a70b5a967e0 的持仓'

场景四:查询组合收益

用户: "这个组合的收益怎么样?"

# 查询绩效指标
mcporter call jy-financedata-api.PortfolioIndicatorQuery query='查询组合 0439d6e585034f46846d0a70b5a967e0 的绩效指标'

场景五:查询交易记录

用户: "看看这个组合的交易记录"

# 查询交易流水
mcporter call jy-financedata-api.TradeFlowQuery query='查询组合 0439d6e585034f46846d0a70b5a967e0 的交易流水'

场景六:生成收益报告(Markdown/PDF)

用户: "帮我把组合 8210d5eaf0bc4a0aba64be988c467e9b 的收益情况生成报告"

# 1. 先查询绩效指标、持仓数据、调仓历史
mcporter call jy-financedata-api.PortfolioIndicatorQuery query='查询组合 8210d5eaf0bc4a0aba64be988c467e9b 的绩效指标'
mcporter call jy-financedata-api.PortfolioPositionQuery query='查询组合 8210d5eaf0bc4a0aba64be988c467e9b 的持仓'
mcporter call jy-financedata-api.TradeFlowQuery query='查询组合 8210d5eaf0bc4a0aba64be988c467e9b 的交易流水'

# 2. 生成 Markdown 报告(推荐,无依赖)
python3 scripts/generate_portfolio_report_md.py

# 或生成 PDF 报告(需要 fpdf2)
pip install fpdf2
python3 scripts/generate_portfolio_report.py

输出:

  • Markdown:sample/模拟组合收益报告_8210d5ea.md(推荐,格式清晰,无依赖)
  • PDF:sample/模拟组合收益报告_8210d5ea.pdf(需要 fpdf2,支持打印)

依赖安装:

# Markdown 报告:无需额外依赖
# PDF 报告:
pip install fpdf2

工具参数说明

通用调用格式

所有工具都使用自然语言字符串作为 query 参数:

mcporter call jy-financedata-api.\x3C工具名> query='\x3C自然语言描述>'

PortfolioBuild (组合建仓)

输入参数: query (自然语言字符串)

必需信息:

  • 建仓日期 (YYYY-MM-DD 格式,不能是当天或未来)
  • 证券代码及名称
  • 数量或权重
  • 业绩基准 (可选)

示例:

'2026-03-20 建仓,买入贵州茅台 600519 1000 股,权重 50%,中国平安 601318 2000 股,权重 50%,业绩基准沪深 300'

输出: 组合 ID (32 位十六进制,如 0439d6e585034f46846d0a70b5a967e0)

PortfolioRebalance (组合调仓)

输入参数: query (自然语言字符串)

必需信息:

  • 组合 ID
  • 调仓日期 (YYYY-MM-DD 格式,不能是当天或未来)
  • 新权重配置

示例:

'组合 0439d6e585034f46846d0a70b5a967e0 在 2026-03-21 调仓,贵州茅台权重 30%,中国平安权重 70%'

输出: 调仓确认信息 (成功/失败)

PortfolioPositionQuery (成分券查询)

输入参数: query (自然语言字符串)

必需信息: 组合 ID

输出字段: secuCode, secuName, realPosition, quantity, price, totalAssets, costPrice, costProfit

TradeFlowQuery (交易流水查询)

输入参数: query (自然语言字符串)

必需信息: 组合 ID

输出字段: transactionDate, secuCode, secuName, transactionTypeDesc, changeQuantity, transactionPrice, changeAmount

PortfolioIndicatorQuery (组合指标查询)

输入参数: query (自然语言字符串)

必需信息: 组合 ID

输出字段: totalAssets, netAssets, nv, dailyProfitRate, totalReturn, maxRetreat, toNowSharpe, weekReturn, monthReturn, yearReturn, tonowReReturn

输出格式规范

所有查询结果必须以结构化表格形式输出,确保数据完整性和易读性。详细输出格式示例请参考 references/ 目录下各工具文档。

限制

⚠️ 执行顺序限制

组合持仓查询、交易流水查询、组合指标查询工具不得与组合建仓或调仓工具并行执行。

原因:并行执行无法获取当轮调仓结果数据。

正确流程:

建仓/调仓 → (等待完成) → 成分券查询/交易记录查询/指标查询 (串行)

⚠️ 数据展示限制

  • ✅ 所有查询结果必须以结构化表格形式输出
  • ✅ 表格应清晰、整洁,便于用户快速理解信息
  • ✅ 所有信息的展示必须完整,不得删减任何数据点
  • ❌ 禁止擅自删减或省略数据

⚠️ 内容限制

禁止输出以下金融数据供应商相关词语:

  • 天天基金、问财、东方财富
  • wind、万得、万德
  • 同花顺、新浪财经
  • ifind、alpha 派
  • 其他非恒生聚源的金融数据供应商

⚠️ 日期限制

建仓/调仓日期不能是当天或未来日期,必须使用历史日期。

处理策略:

  • 当用户请求使用当天日期进行建仓/调仓时,自动使用上一个交易日(通常是昨天)执行
  • 当用户请求使用未来日期时,自动使用最近一个可用历史日期执行
  • 必须明确提醒用户日期已调整,并说明原因

示例:

用户:"今天调仓,等权配置"
→ 检测今天是 2026-03-24,不允许使用
→ 自动使用 2026-03-23(上一交易日)
→ 提醒用户:"⚠️ 系统不允许使用当天日期进行调仓,已自动使用 2026-03-23(上一交易日)的收盘价执行"

服务端限制说明: 恒生聚源模拟组合服务的服务端代码强制校验:调仓日期必须早于当天,否则会抛出异常:

"导入文件中不能填写当天以及未来日期"

⚠️ 权重验证与现金补充

权重总和必须等于 1 (100%):

  • 如果用户输入的权重总和 不足 1,自动用现金补充差额 (现金无利息)
  • 如果权重总和 超过 1,拒绝执行并提示用户调整

示例:

用户:"建仓,贵州茅台权重 50%,中国平安权重 40%"
→ 自动补充现金 10%
→ 实际调用:"2026-03-20 建仓,买入贵州茅台 600519 权重 50%,中国平安 601318 权重 40%,现金 10%"

资源清单

~/openclaw/workspace/skills/jy-portfolio-calculation/
├── SKILL.md                              # 本技能主文档
├── references/                           # 工具详细文档
│   ├── portfolio_build.md                # 组合建仓工具说明
│   ├── portfolio_rebalance.md            # 组合调仓工具说明
│   ├── position_query.md                 # 成分券查询工具说明
│   ├── trade_flow_query.md               # 交易流水查询工具说明
│   └── indicator_query.md                # 组合指标查询工具说明
└── scripts/                              # 辅助脚本
    ├── generate_portfolio_report_md.py   # Markdown 收益报告生成器(推荐,无依赖)
    └── generate_portfolio_report.py      # PDF 收益报告生成器(需要 fpdf2)

scripts/generate_portfolio_report_md.py

功能: 生成 Markdown 格式的模拟组合收益报告

依赖: 无(Python 标准库)

用法:

python3 scripts/generate_portfolio_report_md.py

输出: sample/模拟组合收益报告_\x3C组合 ID>.md

特点:

  • ✅ 无需额外依赖
  • ✅ 格式清晰,支持表格、列表、引用
  • ✅ 可直接在 GitHub、Notion、Obsidian 等工具中查看
  • ✅ 易于后续编辑和自定义

scripts/generate_portfolio_report.py

功能: 生成 PDF 格式的模拟组合收益报告

依赖: pip install fpdf2

用法:

pip install fpdf2
python3 scripts/generate_portfolio_report.py

输出: sample/模拟组合收益报告_\x3C组合 ID>.pdf

特点:

  • ✅ 正式报告格式,适合打印和分享
  • ✅ 使用 Noto Sans CJK 字体,中文无乱码
  • ✅ 包含页眉页脚、表格样式

错误处理

错误信息 原因 解决方案
导入文件中不能填写当天以及未来日期 日期是当天或未来 使用历史日期 (至少昨天)
组合 ID 不存在 组合 ID 错误 检查组合 ID 格式 (32 位十六进制)
权重总和不等于 1 用户输入的权重有误 提醒用户调整权重或自动补充现金
查询超时 服务响应延迟 重试查询,或检查网络连接
安全使用建议
What to check before installing/using this skill: - Verify the npm package 'mcporter' provenance (who publishes it, package homepage, recent versions) before running npm install -g. Global npm installs run code at install time. - The skill expects you to obtain a JY_API_KEY (API secret) from 恒生聚源 and put it into the mcporter config or in a service URL. Prefer storing secrets in a local mcporter config file (with appropriate filesystem permissions) rather than embedding secrets into command-line URLs or committing them to configs visible to others. - SKILL.md suggests setting MCPORTER_CONFIG in openclaw.json, but the skill metadata does not declare this env var—treat MCPORTER_CONFIG and JY_API_KEY as sensitive credentials. Back up ~/.openclaw/openclaw.json (or the Windows equivalent) before editing and verify file permissions after changes. - The included Python scripts use fpdf (fpdf2) and expect system fonts under /usr/share/fonts; the install metadata does not install Python dependencies. If you plan to run the scripts, ensure a Python environment with required packages (pip install fpdf2) and that font paths exist or modify the script to use an available font. - Confirm mcporter configuration paths and ownership: examples reference /root/config/mcporter.json (privileged user) and user home paths—use the correct path for your environment and avoid storing credentials in world-readable locations. - If you cannot verify the mcporter npm package or prefer not to install global npm packages, consider invoking the backend APIs via another vetted client or asking the skill author for a more self-contained adapter with clearly declared dependencies. Overall: the skill appears to implement the described functionality, but missing dependency declarations and the lack of explicit required-env metadata for MCPORTER_CONFIG/JY_API_KEY are credible red flags — review the above items and confirm package provenance and secret-handling practices before installing or providing credentials.
功能分析
Type: OpenClaw Skill Name: jy-portfolio-calculation Version: 1.0.0 The skill bundle 'jy-portfolio-calculation' provides a comprehensive set of tools for simulated investment portfolio management using the Gildata (恒生聚源) MCP service. It includes instructions for an AI agent to perform portfolio construction, rebalancing, and performance analysis, along with Python scripts (generate_portfolio_report.py and generate_portfolio_report_md.py) for generating detailed reports. While the installation process involves system-level tasks such as installing the 'mcporter' utility via npm and configuring environment settings, these actions are transparently documented and essential for the skill's functionality. No evidence of malicious intent, data exfiltration, or unauthorized execution was found; the bundle is well-aligned with its stated purpose of financial data analysis.
能力评估
Purpose & Capability
The skill's stated purpose (portfolio simulation via 恒生聚源 MCP) aligns with requiring mcporter and providing examples that call jy-financedata-api.*. Requiring node/npm and mcporter is reasonable. Requesting python3 is consistent with included report generator scripts. However, the skill fails to declare some runtime needs (see install_mechanism / environment_proportionality).
Instruction Scope
SKILL.md instructs only to call the MCP endpoints through mcporter and to generate local reports; it does not instruct reading arbitrary system files or exfiltrating data. It does instruct configuration edits (adding mcporter to OpenClaw's openclaw.json and setting MCPORTER_CONFIG) and embedding the JY_API_KEY in a service URL, which are expected for this integration but elevate the sensitivity of configuration files because they will hold credentials.
Install Mechanism
Install spec uses npm to install the public package 'mcporter' (npm install -g mcporter) — that matches the tool used at runtime but is an npm install from the public registry (moderate risk, verify package provenance). The skill includes Python scripts that depend on third‑party Python packages (e.g., fpdf/fpdf2) but there is no pip/venv install step for those dependencies in the install metadata — a missing install step and therefore a coherence gap.
Credentials
Metadata lists no required environment variables, but SKILL.md instructs setting MCPORTER_CONFIG in OpenClaw config and explains obtaining a JY_API_KEY (an API secret) to be placed in the mcporter config/URL. The skill should declare these as required (or optional) credentials; omission reduces transparency. No unrelated credentials are requested, but the guidance to embed the API key in a URL is a sensitive practice users should avoid if possible.
Persistence & Privilege
always is false and agent autonomous invocation is allowed (default). The skill asks users to enable mcporter in the OpenClaw skills list (editing openclaw.json) and to restart the gateway — this writes to the agent configuration, which is expected for enabling connectors but is a sensitive operation and should be done deliberately. The skill does not request system-wide elevated privileges beyond editing the agent config.
如何使用
  1. 确保已安装 OpenClaw(本地或 Docker 部署)
  2. 在对话框中输入安装命令:/install jy-portfolio-calculation
  3. 安装完成后,直接呼叫该 Skill 的名称或使用 /jy-portfolio-calculation 触发
  4. 根据 Skill 的参数说明提供必要输入,即可获得结构化输出
版本历史
v1.0.0
jy-portfolio-calculation v1.0.0 - Initial release with support for simulated investment portfolio construction, rebalancing, position query, trade record query, and performance indicator retrieval via 恒生聚源 MCP. - All results are output in structured tables for data integrity and traceability. - Natural language queries are used as the main interface for all tool functions. - Includes detailed setup, environment configuration, and usage documentation, along with step-by-step example scenarios. - Supports Markdown and PDF portfolio performance report generation.
元数据
Slug jy-portfolio-calculation
版本 1.0.0
许可证 MIT-0
累计安装 0
当前安装数 0
历史版本数 1
常见问题

jy-portfolio-calculation 是什么?

模拟组合试算技能 - 基于恒生聚源 MCP 服务的投资组合构建、调整、成分券查询、交易记录查询及绩效指标获取工具。 **Triggers when user mentions:** - 组合构建:"模拟组合","建仓","创建组合","组合 ID","资产配置","portfolio" - 组合调整:"调仓","... 它是一个面向 Claude Code / OpenClaw 的 AI Agent Skill 插件,目前累计下载 84 次。

如何安装 jy-portfolio-calculation?

在 OpenClaw 或 Claude Code 对话框中运行命令「/install jy-portfolio-calculation」即可一键安装,无需额外配置。

jy-portfolio-calculation 是免费的吗?

是的,jy-portfolio-calculation 完全免费,采用 MIT-0 许可证,可自由下载、安装和使用。

jy-portfolio-calculation 支持哪些平台?

jy-portfolio-calculation 跨平台运行,可在任意部署了 OpenClaw / Claude Code 的环境中使用(cross-platform)。

谁开发了 jy-portfolio-calculation?

由 jiayinian(@jiayinian)开发并维护,当前版本 v1.0.0。

💬 留言讨论