a-share-etf-pcf-metrics
使用确定性脚本生成 ETF 底层资产穿透指标。用户要求 ETF 穿透、PCF 申赎篮子、股息率、PE/PB、Sortino、组合风险、单股权重约束,或处理 A 股上市 ETF、港股/美股成分 QDII、美股上市 ETF 和跨市场 ETF 组合时使用。
Codex 또는 Claude로 설치 이 Prompt를 복사해 Codex, Claude 또는 다른 어시스턴트에 붙여 넣으면 Skill 페이지를 검토하고 설치를 진행할 수 있습니다.
메뉴
使用确定性脚本生成 ETF 底层资产穿透指标。用户要求 ETF 穿透、PCF 申赎篮子、股息率、PE/PB、Sortino、组合风险、单股权重约束,或处理 A 股上市 ETF、港股/美股成分 QDII、美股上市 ETF 和跨市场 ETF 组合时使用。
Codex 또는 Claude로 설치 이 Prompt를 복사해 Codex, Claude 또는 다른 어시스턴트에 붙여 넣으면 Skill 페이지를 검토하고 설치를 진행할 수 있습니다.
SOC 직업 분류 기준
| name | a-share-etf-pcf-metrics |
| description | 使用确定性脚本生成 ETF 底层资产穿透指标。用户要求 ETF 穿透、PCF 申赎篮子、股息率、PE/PB、Sortino、组合风险、单股权重约束,或处理 A 股上市 ETF、港股/美股成分 QDII、美股上市 ETF 和跨市场 ETF 组合时使用。 |
当用户要用脚本而不是模型能力,基于交易所 PCF 或公开持仓数据穿透 ETF 底层资产,并计算股息率、PE、PB、收益和风险指标时,使用本 skill。
按标的选择流程:
scripts/run_pcf_metrics.pyscripts/selected_etf_lookthrough.pyscripts/us_listed_etf_lookthrough.pyscripts/run_a_share_dividend_etf_pcf_metrics.py先解析 skill 目录。$SKILL_DIR 指向包含本 SKILL.md 的目录;如果当前目录就是 skill 或仓库目录:
$SKILL_DIR = Resolve-Path .
指定 ETF 代码:
python "$SKILL_DIR\scripts\run_pcf_metrics.py" --etf 513690,159569 --out-dir pcf-metrics-output
从 CSV 读取 ETF 列表:
python "$SKILL_DIR\scripts\run_pcf_metrics.py" --input ".\my_etf_list.csv" --code-column "ETF代码" --out-dir pcf-metrics-output
默认输入是 lookthrough-hk-all-ranking/all_etf_summary.csv。该文件不随 skill 打包;如果不存在,显式传入 --etf,或先生成 ETF 发现结果。
默认最终输出:
pcf_full_metrics_table.xlsxpcf_full_metrics_table.csv默认会删除中间 CSV/JSON/MD 文件。调试或审计来源数据时加 --keep-intermediates。
扫描名称含“红利”“分红”“股息”、且底层主要为 A 股的 ETF:
python "$SKILL_DIR\scripts\run_a_share_dividend_etf_pcf_metrics.py" --out-dir a-share-dividend-output
最终表为 a_share_dividend_etf_pcf_metrics.csv 和 .xlsx。失败候选保留在最终表;股息率、PE、PB 任一指标为空或覆盖权重低于 80% 的行不标记为“有效”或参与排名。全部候选失败时必须返回非零状态。
用于 A 股上市、底层为美股的 ETF/QDII:
python "$SKILL_DIR\scripts\run_pcf_metrics.py" --market us --etf 513100,513500 --out-dir lookthrough-us-pcf-risk
最终输出仍是 pcf_full_metrics_table.xlsx 和 pcf_full_metrics_table.csv。
当 ETF 本身在美股上市,例如 QQQ.US、DRAM.US,优先使用专用脚本:
python "$SKILL_DIR\scripts\us_listed_etf_lookthrough.py" --ticker QQQ.US --out-dir us-etf-output
python "$SKILL_DIR\scripts\us_listed_etf_lookthrough.py" --ticker QQQ.US,DRAM.US --weights 50,50 --out-dir us-etf-portfolio-output
python "$SKILL_DIR\scripts\us_listed_etf_lookthrough.py" --ticker QQQ.US --skip-metrics --out-dir us-qqq-holdings
python "$SKILL_DIR\scripts\us_listed_etf_lookthrough.py" --ticker QQQ.US,DRAM.US --full-output --out-dir us-etf-full-audit
默认只输出核心文件:lookthrough_detail.csv、lookthrough_summary.csv、etf_summary.csv、metrics_summary.csv、lookthrough_report.xlsx、run_manifest.json。只有需要额外 CSV、Markdown、HTML 审计文件时才加 --full-output。
数据来源行为:
DRAM 等 Roundhill ETF 优先使用发行商每日持仓 CSV。--cache 后,持仓、成分股指标和 ETF 价格历史写入 out-dir/cache;缓存必须带匹配的 schema 版本,持仓与估值缓存最多复用 24 小时,行情缓存还要求末日距当前不超过 7 天。--refresh-cache 不依赖本次是否开启缓存写入。--lookback-days 是 --nav-lookback-days 的别名。单只 ETF:
python "$SKILL_DIR\scripts\selected_etf_lookthrough.py" --etf 159569 --out-dir selected-etf-output
带权重组合:
python "$SKILL_DIR\scripts\selected_etf_lookthrough.py" --etf 159569,159758 --weights 60,40 --out-dir selected-etf-output
美股成分 QDII:
python "$SKILL_DIR\scripts\selected_etf_lookthrough.py" --etf 513100 --markets us --out-dir selected-us-etf-output
跨 A 股、港股、美股成分、直接美股上市 ETF 的组合:
python "$SKILL_DIR\scripts\selected_etf_lookthrough.py" --etf 510880,159569,513100 --markets a,hk,us --weights 40,30,30 --out-dir selected-global-etf-output
python "$SKILL_DIR\scripts\selected_etf_lookthrough.py" --etf 510880,159569,513100,QQQ.US --markets a,hk,us,us_listed --weights 25,25,25,25 --out-dir selected-global-us-listed-output
--weights 支持百分数或小数,并会自动归一化;非有限数和重复 ETF 会直接拒绝。未提供权重时等权。--markets 可传 auto、hk、a、us、us_listed;auto 会合并成功解析出的 A/HK/US 成分,不得只选择单一市场。确认无适用成分不算失败,真实解析错误必须进入 ETF 的 错误 字段。以 .US 结尾的 ticker 会自动进入 us_listed 模式。
selected_etf_lookthrough.py 默认只生成:
metrics_summary.csv:每只 ETF 一行,加一行 PORTFOLIO。lookthrough_summary.csv:按底层股票聚合后的组合持仓。lookthrough_detail.csv:每只 ETF 的底层明细,含股票 PE/PB/股息率。etf_summary.csv:ETF 持仓来源和指标汇总。lookthrough_report.xlsx:核心表和增强审计工作表。run_manifest.json:参数、字段和行数。加 --full-output 后才额外生成:
classified_detail.csv:加上板块、规则行业、主题分类的明细。structure_analysis.csv:持仓数量、Top5/10/20 集中度、最大单股、现金/其他估计。market_board_exposure.csv:A/HK/US/现金及 A 股板块暴露。industry_theme_exposure.csv:规则估计的行业和主题暴露。valuation_buckets.csv:PE/PB/股息率分层。profit_quality.csv、dividend_quality.csv:仅输出已有数据支持的质量摘要,不写空占位指标。risk_analysis.csv:收益风险指标及不可用字段诊断。overlap_pairs.csv、common_holdings.csv:ETF 之间的重合度和共同持仓。pcf_quality.csv、cross_validation.csv、constraint_checks.csv、historical_tracking.csv。enhanced_report.md、enhanced_report.html、run_summary.json。常用参数:
--max-stock-weight 7:检查穿透后单一股票是否超过 7%。--max-industry-weight、--min-dividend-yield、--max-pe、--max-pb、--max-drawdown、--target-a-weight、--target-hk-weight、--target-us-weight:组合约束检查。--us-script:覆盖 A 股上市美股成分 ETF helper 路径。--us-listed-script:覆盖直接美股上市 ETF helper 路径。--full-output:写出辅助 CSV、Markdown、HTML 和 run_summary;默认关闭。--cache / --no-cache:是否在 cache/ 写入本次持仓快照;默认关闭。--refresh-cache:运行前删除旧 holdings_*.csv 快照。--compare、--portfolio、--industry、--theme、--risk、--html-report:兼容语义参数,增强输出默认生成。sum(weight) / sum(weight / PE);非正 PE 不进入分母,并记录负 PE 权重。AAPL、MSFT、NVDA、BRK.B、BRK-B。0;无法区分“无股息”和“来源缺失”时留空。PB 小于 0.05 或大于 1000 视为来源异常,不进入聚合。修改来源优先级或权重公式前,先读 references/pcf-method.md。
关键规则:
PCF 是申赎篮子估算,不等同于基金实际持仓;季报、SEC N-PORT 和发行商持仓必须在 穿透口径 中区分。
保留原始股票行数、有效权重行数和未定价/缺失权重行数;不得在质量检查前静默丢弃。
上交所 ETF PCF:SUBSTITUTION_CASH_AMOUNT / NAVPERCU。
深交所现金替代行:CreationCashSubstitute / (1 + PremiumRatio) / NAVperCU。
深交所港股实物行且替代现金为 0:ComponentShare * HK spot price * HKD/CNY / NAVperCU。
美股行优先用 PCF 现金替代金额除以 NAVperCU;只有数量时,可用 ComponentShare * US latest price * USD/CNY / NAVperCU 估算,并在 权重来源 记录公式。
深交所下载页出现多个 XML 候选时,选择股票成分最相关的 XML。
只加载当前任务需要的文件:
references/pcf-method.md:数据源优先级和 PCF 公式。references/output-schema.md:字段定义、单位和空值语义。references/troubleshooting.md:网络或数据源失败诊断。数据状态=失败 和 错误;不得静默缩小排名样本。只有缺包时才安装:
python -m pip install -r "$SKILL_DIR\requirements.txt"
需要网络访问交易所 PCF、股票估值/股息数据、港股/美股价格、HKD/CNY、USD/CNY 汇率和 ETF 历史行情。
快速离线检查:
python -m py_compile "$SKILL_DIR\scripts\pcf_common.py" "$SKILL_DIR\scripts\pcf_enhanced_analytics.py" "$SKILL_DIR\scripts\run_pcf_metrics.py" "$SKILL_DIR\scripts\pcf_lookthrough.py" "$SKILL_DIR\scripts\run_a_share_dividend_etf_pcf_metrics.py" "$SKILL_DIR\scripts\selected_etf_lookthrough.py" "$SKILL_DIR\scripts\us_etf_lookthrough.py"
python -m py_compile "$SKILL_DIR\scripts\us_listed_etf_lookthrough.py"
python -m unittest discover -s "$SKILL_DIR\tests"
网络 smoke test:
python "$SKILL_DIR\scripts\run_pcf_metrics.py" --etf 513690,159569 --out-dir pcf-metrics-smoke-test
python "$SKILL_DIR\scripts\selected_etf_lookthrough.py" --etf 513100 --markets us --skip-metrics --out-dir selected-us-smoke-test
python "$SKILL_DIR\scripts\us_listed_etf_lookthrough.py" --ticker QQQ.US,DRAM.US --out-dir us-listed-smoke-test
批量流程的预期结果是最终 .csv 和 .xlsx;中间文件只在传入 --keep-intermediates 时保留。