private-fund-portfolio-analysis

私募基金持仓结构分析脚本构建方法。支持市场中性(期货空头对冲)和指数增强(持仓 vs 对标指数超配/低配)两种产品类型。当需要从私募基金估值表(XLS/XLSX)解析持仓,分析行业分布/市值分布/指数成分/期货对冲,并生成可视化报告时触发。也用于:生成持仓分析脚本、重构脚本、添加新数据源、修复脚本Bug、生成分析报告。

Safety Notice

This listing is from the official public ClawHub registry. Review SKILL.md and referenced scripts before running.

Copy this and send it to your AI assistant to learn

Install skill "private-fund-portfolio-analysis" with this command: npx skills add xiaoerdata/private-fund-portfolio-analysis

私募基金持仓结构分析脚本构建

两种产品类型

类型命令说明
市场中性--type market_neutral期货空头,分析对冲端
指数增强--type index_enhanced --benchmark 中证500持仓 vs 对标指数超配/低配

脚本位置

  • 市场中性版/workspace/analyze_portfolio.py
  • 指数增强版/workspace/analyze_portfolio_enhanced.py

使用方式

# 市场中性
python3 analyze_portfolio_enhanced.py --xls <估值表路径> --type market_neutral

# 指数增强(指定对标指数)
python3 analyze_portfolio_enhanced.py --xls <估值表路径> --type index_enhanced --benchmark 中证500
python3 analyze_portfolio_enhanced.py --xls <估值表路径> --type index_enhanced --benchmark 沪深300
python3 analyze_portfolio_enhanced.py --xls <估值表路径> --type index_enhanced --benchmark 中证1000
python3 analyze_portfolio_enhanced.py --xls <估值表路径> --type index_enhanced --benchmark 中证2000
python3 analyze_portfolio_enhanced.py --xls <估值表路径> --type index_enhanced --benchmark 空气指增

XLS 解析要点

估值表结构(以 xlrd 读取,行65+有股票数据):

col0: 科目代码(层级结构,如 "1102.01.01.600519 SH")
col1: 名称
col4: 数量(股数)
col5: 单位成本
col6: 累计成本
col8: 行情/结算价
col9: 市值 ← 持仓市值
col11: 估值增值/PnL

提取6位股票代码:从层级代码中用正则提取,如 1102.01.01.600519 SH600519

期货行(账户代码含 3102.03.01.):

  • col4 = 手数
  • col5 = 昨日结算价
  • col9 = 今日结算价
  • 名义本金 = 今日结算价 × 乘数 × 手数

乘数:IF/IH = 300;IC/IM = 200

指数增强核心功能

超配/低配计算

超配(%) = 持仓行业市值占比 - 对标指数行业市值占比
正数 = 超配(相对于指数);负数 = 低配

只显示 |差值| > 0.5% 的行业(过滤噪音)

对标指数数据来源

对标指数代码数据源
沪深300000300ak.index_stock_cons("000300")
中证500000905ak.index_stock_cons("000905")
中证1000000852ak.index_stock_cons("000852")
中证2000932000ak.index_stock_cons_csindex("932000")

数据 Enrichment

  • 市值ak.stock_zh_a_spot_em() → 市场数据缓存 CSV
  • 行业:MySQL 股票申万行业分类(charset=utf8mb4)
  • 指数成分:AKShare

MySQL 连接(占位符)

conn = pymysql.connect(
    host=os.environ.get("MYSQL_HOST", "43.138.222.153"),
    port=int(os.environ.get("MYSQL_PORT", "3306")),
    user=os.environ.get("MYSQL_USER", "readonly_user"),
    password=os.environ.get("MYSQL_PASSWORD", "w6w%vkXENC82PGZo"),
    database=os.environ.get("MYSQL_DATABASE", "指数行情数据库"),
    connect_timeout=8, charset="utf8mb4"
)

输出文件

文件说明
portfolio_analysis.csv持仓明细(355只股票)
portfolio_summary.json汇总统计
portfolio_report.png可视化报告

参考文档

  • references/xls_structure.md — XLS 行列结构详解
  • references/data_sources.md — AKShare/MySQL 数据源配置
  • scripts/generate_analysis_script_prompt.py — 可直接粘贴给 Claude Code 的提示词

注意

  • XLS 列位因模板不同可能有差异,建议用 print(row[:12]) 验证
  • MySQL charset 必须用 utf8mb4,否则中文字符报错
  • 中证2000 用 index_stock_cons_csindex("932000"),稳定性高于 index_stock_cons
  • 不要 hardcode 任何真实密码/地址/产品名称

Source Transparency

This detail page is rendered from real SKILL.md content. Trust labels are metadata-based hints, not a safety guarantee.

Related Skills

Related by shared tags or category signals.

General

futures-panda

通过AKShare财经数据接口库封装,提供股期货、期权的实时数据、历史行情数据、仓单数据、席位数据、基差数据、期货合约基础数据和期货交易费用参照表数据。

Registry SourceRecently Updated
5231Profile unavailable
Research

China Stock Quant

A-share quantitative analysis toolkit. Use when user wants to analyze Chinese stocks, backtest trading strategies, calculate technical indicators (MACD/KDJ/R...

Registry SourceRecently Updated
2040Profile unavailable
General

A股分析技能包装器

A股分析技能包装器,基于akshare数据源。支持实时行情、个股分析、板块轮动、资金流向等A股分析功能。使用自然语言查询A股市场数据。

Registry SourceRecently Updated
3050Profile unavailable
General

airoom-ltd-global-finance-data-platform

Automatically logs into a WordPress site and downloads all downloadable files from a specified page with error handling and configurable limits.

Registry SourceRecently Updated
2930Profile unavailable