hk-stock-factor

Hong Kong stocks (Hang Seng Index ∩ Stock Connect, 88 stocks) multi-factor stock selection, based on pure westock-mcp data source. 20

Installation

Review the source and dependencies with a prompt. A package is available to download.

Install with an AI assistant

Copy the prompt so your assistant can review the pinned revision and dependencies first.

View promptHide prompt
Check whether SkillPI Skill Finder is installed for your current agent. If it is missing, install and enable it using the official instructions at https://github.com/Findskills/skillpi. Then use Skill Finder to locate and install "hk-stock-factor" from this exact SkillPI detail page: https://skillpi.com/skills/deepskill-f300ffcd5ed93ec9ee280a94cf632d54e6d22ed37cc1fbca8f25dda80e0e0a66. Verify the upstream source and version against https://skillhub.cn/skills/user_ecbd3b70/hk-stock-factor before installing. If they do not match, stop and report the mismatch. Report the installed path and source version.

Source and setup

skillhub.cn

Setup guidance pending

See the original source for supported tools, dependencies, and permissions.

Installation test pending

Hong Kong stocks (Hang Seng Index ∩ Stock Connect, 88 stocks) multi-factor stock selection, based on pure westock-mcp data source. 20

0 Downloads

Introduction source: third_party · user_ecbd3b70 · 1.0.0 Reference

SkillPi interpretation

Tasks
Translation pending; see source documentation.
Testing
Not tested

Browse files

Browse files at the source ↗

Original SKILL.md

Open original ↗
Frontmatter
name: hk-stock-factor
description: 港股(恒生指数∩港股通, 88只) 多因子选股, 纯 westock-mcp 数据源. 20
  因子(价值/规模/动量/波动/情绪/质量/成长/技术), 截面 z-score 合成, 月度调仓回测, 基准恒生指数.
  不依赖通达信/mcporter/QClaw/akshare.

hk-stock-factor (港股 多因子选股, westock-native)

数据源

westock-mcp (腾讯自选股, WorkBuddy 原生连接器), 全部通过 DeferExecuteTool 调用, 支持 codes 批量:

  • data_kline(codes, period=day, fq=qfq, limit=520) → K线 (量最大, 大响应自动落盘)
  • data_quote(codes) → 估值/规模/52周/短期涨跌快照
  • data_finance(codes, type=income, num=5) → 综合财报(港股单次即含比率+成长, 见下)
  • data_fund_flow(codes) → 主力/散户/总净流快照
  • 基准: data_kline(code=hkHSI, period=day, fq=, limit=2000) 恒生指数

westock 是平台托管 MCP, Python 无法 spawn; 批量靠 AI 用 codes 一次多只调用, 大响应自动落盘, land.py 离线解析. 彻底不用 mcporter/QClaw/akshare.

标的池 (universe.csv, 88 只)

恒生指数成分股 ∩ 港股通 (深港通∪沪港通), 由用户提供三份本地文件交叉得到:

  • Table.xlsx = 恒指成分股 (93 只)
  • Table深港通.txt / Table沪港通.txt = 港股通标的 (615 只, 去重并集)
  • 三者取交集 = 88 只。用户原估 87 (88 − 00011 恒生银行), 但 00011 本就不在恒指 xlsx 交集内, 故 88 即为终值, 无需再减。

目录

config/universe.csv      88 只港股 (ticker 纯5位, 如 00001)
scripts/land.py          原始 JSON -> 面板 (写入 sqlite data/stock.db, parquet 仅兼容备份)
scripts/calc_factors.py  20 因子 + 合成 composite (读 sqlite)
scripts/backtest.py      月度调仓回测 (对比 hkHSI, 读 sqlite)
scripts/report.py        选股 HTML+CSV 报告; 按收盘日命名 report/hk_factor_top{N}_{date}.html/.csv (不覆盖), 另写 report/hk_report.html (最新别名)
scripts/run_all.py       编排: land -> calc -> backtest -> report (全读/写 sqlite)
scripts/migrate_to_sqlite.py  一次性: 把历史 parquet 灌入 data/stock.db (首次迁移用)
scripts/fetch.py         (AI 用) 打印批次取数计划
scripts/save_raw.py      (AI 用) 存原始响应到 data/raw
data/raw/*.json          AI 取数落盘
data/stock.db            ★主库 (sqlite): price/spot_all/financial/fund_flow/benchmark/factor_panel
data/cache/*.parquet     面板 (兼容备份, 非主读路径)
data/factors/*.parquet   因子面板 + 回测 (兼容备份)

存储已迁移到 sqlite: 时间序列表(price/financial/benchmark/factor_panel)用 INSERT OR REPLACE 增量 upsert; 快照表(spot_all/fund_flow)无时间维, 每次补数据全量覆盖. parquet 仍写但仅作备份.

因子 (20, 方向高好+ / 低好-)

价值 ep+(1/pe) bp+(1/pb) div_yield+ ; 规模 ln_mv+ ; 动量 mom1m/mom3m/mom12m+ ; 波动 vol60- ; 情绪 turn60- main_net_flow+ retail_net_flow+ total_net_flow+ ; 质量 gpm+(毛利率) op_margin+(营业利润率) roe+(加权ROE) lev-(资产负债率) roa+ ; 成长 revg+(营收YoY) npg+(归母净利YoY) ; 技术 pos_52w+(52周位置). composite = 各因子截面 z 的带符号均值 (NaN 跳过).

港股数据特性 (与 A股 关键差异)

  • 财务单次取足: data_finance(type=income) 直接返回综合字段 — 毛利率 GrossIncomeRatio、加权ROE RoeWeighted、资产负债率 DebtAssetsRatio、ROA、营收YoY OperatingRevenueGr1y、归母净利YoY NpParentCompanyGr1y — 无需 income+balance 合并 (A股需两表)。
  • 资金流仅快照: 港股 data_fund_flow 只给当日主力/散户/总净流, 无 5D/20D/换手率细分 (A股有)。故情绪因子为横截面当期值。
  • PE 可能为负 (亏损股如部分科技股): ep 对 pe<=0 置 NaN, 不制造虚假"便宜"。

工作流

默认动作 = 直接用现有数据算因子/回测/报告 (跳过取数). 拉取/刷新数据是选做——仅当用户明确说"补全数据/刷新/更新/拉最新/补数"时才先去取数; 否则直接进步骤 2, 跑 land→calc→backtest→report (用 data/stock.db 已有数据, 不浪费 token/限频).

  1. 补数据 (选做, 仅当用户明确要求时):
    • 触发条件: 用户说"补全/刷新/更新/拉最新数据" 或 本地 data/stock.db 不存在/空库(首次运行). 否则跳过此步, 直接进步骤 2.
    • 首次(本地无 data/stock.db 或空库): python migrate_to_sqlite.py 灌历史 parquet; 然后全量取数.
    • 日常补数: python fetch.py 拿批次 (每批 <=20 只), AI 逐批 DeferExecuteTool 取 data_kline(codes=<批>, start=<末日+1>, end=today, limit=10) 并 save_raw 落盘; 同理 quote/fin/fund/benchmark. 数据量过大时先取一二十只验证即可.
    • 限频安全模式(实测稳定): 第一轮 kline+finance 并发, 第二轮 quote+fund_flow 并发, 每轮≤2 并发; 每批 15~20 只.
    • 落盘后: python run_all.py 内的 land.py 会自动把 raw JSON upsert 进 sqlite (时间序列增量, 快照全量覆盖).
  2. 算因子+回测+报告: python run_all.py --top-pct 0.1 → 依次 land→calc→backtest→report, 末端自动生成报告. (land 解析 raw→sqlite; calc/backtest/report 全读 sqlite.)
  3. 选股结果: data/stock.db 表 factor_panel (含 composite); 回测: data/factors/backtest.csv; 报告输出(按行情收盘日命名, 不同日期互不覆盖):
    • report/hk_factor_top{N}_{date}.html — 净值曲线+KPI卡+最新选股因子表 (与 us/cn 风格对齐)
    • report/hk_factor_top{N}_{date}.csv — 选股明细 (UTF-8-sig, 列: 排名/代码/名称/综合分/各因子z/基准日), Excel 中文不乱码
    • report/hk_report.html — 最新一次运行的别名(每次覆盖), 便于快速打开
    • {date} = factor_panel 最新截面日期(即取数收盘日), {N} = 当次选股只数 (Top 10%≈8~9).

已知近似

估值/规模/质量/成长/资金流为最新快照因子 (westock quote/finance/fund_flow 仅给最新值), 在时间序列上恒为最新快照; 动量/波动/换手/52w 为真实时间序列. 回测据此评估, 不随时间重算估值.

验证记录

20 只子集 (00001..00386) 已端到端跑通: 面板 price 5200 行 / quote 20 / fin 52 / fund 20 / bench 2000; 因子面板 0% NaN; 月度 top10% 回测 组合 +18.5% vs 恒指 +4.9%, 夏普 1.18, 最大回撤 -5.9%. (子集仅验证管线, 非策略结论)

Current listing version

1.0.0

Verify the source revision ↗

Quality assessment

Out of 100 · Assessment report from SkillPi LAB.

Scenario Value75/100

Highlights

  • 提供港股多因子选股功能,面向量化投资用户,具有明确场景和实用价值
  • 支持88只恒生指数成分股与港股通交集标的,覆盖主流港股投资标的
Trigger Precision85/100

Highlights

  • 触发词精准完整,涵盖'港股多因子选股'、'恒生指数'、'因子'等核心关键词
  • 边界清晰,用户可通过关键词精准触发,避免误触或漏触
Structure and Standards90/100

Highlights

  • 文档结构完整,包含数据源、标的池、因子定义、工作流等关键章节
  • 步骤清晰,有端到端示例和出口条件,frontmatter完整,符合规范
Execution Reliability88/100

Highlights

  • 工具来源明确(westock-mcp),参数正确,覆盖主要异常处理
  • 有确认机制(用户需明确指令才补数据),限频安全模式合理,执行可靠
Evidence Verifiability (mean of the first four)85/100

The arithmetic mean of the first four original scores, rounded to a whole number.

Static text checks

100 / 100 · skillpi-20261123-no-r3-v1

No current rules matched the text.

This score reflects rule matches in the text and is provided for reference before use. It excludes attachments and runtime behavior.

Permissions and checks before use

Automatically summarized from this main document. Matches may be examples or defensive advice; they are not actual permission declarations. Attachments, external dependencies and runtime behavior are not covered.

These common operations were not identified in the main document. This does not mean no permissions or risks exist.

These notices grant no permissions. Your host tool must still confirm file changes, secrets, external transfers or costs as needed.

Security rating and access scope

safe · Static evidence review; not a runtime safety guarantee.

Before use, confirm and authorize actual file access, external services and network destinations in your host. This review grants no runtime permissions.