Develops, validates, and backtests A-share LHB event-driven ranking factors using pandadata seat win rate, payoff, and premium data. Includes IC, Rank IC, and look-ahead checks for factor evaluation.
Ships in a1-lhb-tracking. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
{
"version": 1,
"task": {
"placeholder": "补充说明要构建、校验、解释或回测 A1 龙虎榜席位追踪因子的具体要求"
},
"fields": [
{
"key": "mode",
"label": "执行任务",
"type": "select",
"default": "backtest",
"options": [
{ "value": "build", "label": "生成生产因子" },
{ "value": "validate", "label": "校验因子文件" },
{ "value": "backtest", "label": "历史回测" },
{ "value": "explain", "label": "解释因子逻辑" }
]
},
{
"key": "start_date",
"label": "开始日期",
"type": "date"
},
{
"key": "end_date",
"label": "结束日期",
"type": "date"
},
{
"key": "lookback_days",
"label": "席位回看天数",
"type": "number",
"default": "30",
"help": "计算席位历史胜率与盈亏比时使用的回看窗口"
},
{
"key": "min_history",
"label": "最少历史样本",
"type": "number",
"default": "3"
}
],
"prompt_template": "{{#task}}任务与材料:\n{{task}}\n\n{{/task}}{{#attachments}}用户上传的材料(已放入工作区):\n{{attachments}}\n\n{{/attachments}}请对 A1 龙虎榜席位追踪因子执行 {{mode}}。{{#start_date}}开始日期:{{start_date}}。{{/start_date}}{{#end_date}}结束日期:{{end_date}}。{{/end_date}}{{#lookback_days}}席位回看窗口为 {{lookback_days}} 天。{{/lookback_days}}{{#min_history}}最少历史样本数为 {{min_history}}。{{/min_history}}严格防止未来函数,区分因子有效性与完整策略收益,覆盖相应校验或 IC、Rank IC、分组收益、风险及成本指标,并输出中文报告。"
}
本 skill 用于处理 A1「龙虎榜资金追踪」因子。
因子的核心思想是:如果某只股票当天被近期胜率较高、盈亏比较好的龙虎榜席位买入,并且买入金额较大,那么它在下一交易日开盘获得溢价的概率可能更高。
定位说明:本因子是龙虎榜事件驱动排序因子,适合在“当天上过龙虎榜的股票”内部做横截面排序;不建议直接包装为全市场通用日频 Alpha。
scripts/login_pandadata.py 或环境变量初始化 pandadata 登录状态。scripts/factor.py 生成生产因子文件。scripts/validate.py 校验生产文件。scripts/backtest.py 进行历史验证。references/ 下的公式、数据、验证和 QuantFlow 说明。正式数据源为 PandaAI panda_data:
get_lhb_listget_lhb_detailget_stock_dailyget_trade_cal开发或应急验证时,可使用 scripts/akshare_source.py 中的公开龙虎榜数据适配器。
正式交付应优先使用 pandadata。
注意:akshare 备用适配器中的 next_open_premium 使用公开源“上榜后 1 日”字段,只作为应急近似标签;正式验证口径以 pandadata 行情计算的“下一交易日开盘价 / 龙虎榜当日收盘价 - 1”为准。
历史标签:
次日开盘溢价 = 下一交易日开盘价 / 龙虎榜当日收盘价 - 1
席位分数:
seat_score =
100 * (
0.40 * win_rate
+ 0.25 * payoff_component
+ 0.25 * premium_component
+ 0.10 * sample_component
)
股票因子值:
raw_seat_score = sum(seat_score * buy_value) / sum(buy_value)
factor_value = raw_seat_score * (0.75 + 0.25 * 当日买入金额分位排名)
score = 当日 factor_value 分位排名 * 100
完整公式见:
references/formula_and_lookahead.mdT 的评分只使用 date < T 的席位历史。T 的次日开盘溢价只作为回测标签,不能参与日期 T 的因子计算。next_open_premium、next_open、future_return 等未来字段。trade_date、ts_code、factor_id 去重。python scripts/factor.py --source panda --start-date 20260501 --end-date 20260622 --lookback-days 30 --min-history 3 --latest-only --data-version A1-pandadata-YYYYMMDD --output production/database.parquet
python scripts/validate.py --factor-path production/database.parquet
python scripts/backtest.py --source panda --start-date 20260101 --end-date 20260622 --eval-start-date 20260216 --lookback-days 30 --min-history 3 --group-count 5 --output-dir production/backtest_pandadata_long
带成本和交易约束:
python scripts/backtest.py --source panda --start-date 20260101 --end-date 20260622 --eval-start-date 20260216 --lookback-days 30 --min-history 3 --group-count 5 --exclude-st --exclude-suspended --exclude-limit-open --one-way-cost-bps 10 --one-way-slippage-bps 5 --output-dir production/backtest_pandadata_stress
输出指标包括:
python scripts/factor.py --sample --lookback-days 6 --min-history 2 --output sample_database.parquet
python scripts/validate.py --factor-path sample_database.parquet
python scripts/backtest.py --sample --lookback-days 6 --min-history 2 --output-dir sample_backtest
python -m pytest scripts/test_a1_core.py -q
如需复核已落盘真实样本:
python scripts/validate_real_backtest.py --event-dir production/backtest_pandadata_event_corrected_202602 --neutral-dir production/backtest_pandadata_lhb_type_neutral_corrected_202602 --output-dir production/final_local_validation
references/formula_and_lookahead.mdreferences/data_guide.mdreferences/validation_report.mdreferences/quantflow_validation.md交付前必须确认:
validate.py 校验通过。What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
a-share, lhb-factor, event-driven-alpha, factor-backtesting, pandadata
Other plugins' skills for the same job
/a1-lhb-tracking:skill-a1-lhb-trackingfrom a1-lhb-tracking
a1-lhb-tracking@quantskills is listed by quantskills/registry — review the source before installing
npx claudepluginhub quantskills/registry --plugin a1-lhb-tracking