初始提交:高股息策略研究与回测系统

从 Point-in-Time 股票筛选到统一 Web 前端的完整链路:
筛选 → 画像 → 策略 → 回测 → Walk-forward → 绩效分析 → 报告/前端。

架构
- 数据层与策略层分离;策略代码不写 SQL,只经 data/repo.py 取数
- 所有业务阈值集中在 config/*.yml,代码零硬编码(字段写错直接报错)
- 报告只做「run_id → SQL → 渲染」,不做任何计算,数字可追溯
- 前后端分离:output/ 静态站点 + hdiv web 提供的 REST API

数据安全
- 只增不删:SQL 钩子拦截 DELETE/DROP/TRUNCATE,并有源码扫描测试守护
- qlib 原有表只读,本项目数据写入 hd_ 前缀表
- 回补使用 INSERT IGNORE,保证既有行零改动
- .env 存密钥且已 gitignore;output/、logs/、.venv/ 不入库

交付物
- 30 张 hd_* 表、7 个 YAML 配置、283 项自动化测试
- 统一 Web 前端(hash 路由 SPA)+ nginx 部署配置与 launchd 托管脚本

如实声明的限制
- 策略缺少稳定的样本外超额收益(Walk-forward 7 窗口均值 -0.95%,
  基准 +2.29%);其价值体现在回撤控制,而非超额收益
- 涨跌停/停牌约束仅覆盖 2019 年起;index_weight 尚未填充
- AI Agent 层(plan.md 第四版 P8)未实现

详见 docs/user-guide.md 与 docs/implementation-status.md。
This commit is contained in:
2026-10-03 13:54:56 +08:00
commit fce725e13c
127 changed files with 28001 additions and 0 deletions
+94
View File
@@ -0,0 +1,94 @@
# ============================================================
# 高股息均值回归策略 v1.0(★ 可直接修改)
# 对应 plan.md §16–§21(买入/卖出/加仓/仓位/风控)
#
# 修改任一字段后 config_hash 变化,历史 run 仍可复现。
# status 生命周期:DRAFT → RESEARCH → BACKTEST → VALIDATED → PAPER → LIVE → ARCHIVED
# ============================================================
strategy:
id: HD_MR_V1
name: high_dividend_mean_reversion
version: "1.0"
status: DRAFT
description: >-
高股息 + 安全边际 + 估值均值回归。寻找长期稳定分红、财务质量较好、
规模较大、上市时间较长的公司,当其股息率进入历史相对高位时买入,
当股息率下降到历史相对低位时卖出或减仓。
# ------------------------------------------------------------
# 股票池:引用全局筛选配置,可就地覆盖
# ------------------------------------------------------------
universe:
ref: config/universe.yml
# 就地覆盖示例(留空则完全沿用 universe.yml):
# override:
# dividend:
# min_dividend_yield: 0.035
override: {}
# ------------------------------------------------------------
# 买入规则(plan.md §17)
# ------------------------------------------------------------
entry:
# 股息率 >= 历史 P75 —— plan.md §43 MVP 买入条件
yield_percentile: 75
# 必须通过基本面筛选
require_universe_pass: true
# 必须未进入风险状态
require_risk_pass: true
# 分批建仓(plan.md §19)。留空 => 一次性建满。
scale_in:
- { percentile: 75, weight: 0.25 }
- { percentile: 80, weight: 0.50 }
- { percentile: 85, weight: 0.75 }
- { percentile: 90, weight: 1.00 }
# ------------------------------------------------------------
# 卖出规则(plan.md §18)
# ------------------------------------------------------------
exit:
# 股息率 <= 历史 P25 —— plan.md §43 MVP 卖出条件
yield_percentile: 25
# 分批减仓;weight 为该分位下的目标仓位比例
scale_out:
- { percentile: 50, weight: 0.50 }
- { percentile: 25, weight: 0.00 }
# 第一版不加止损(plan.md §21:止损易致过拟合)
stop_loss_pct: null
max_holding_days: null
# ------------------------------------------------------------
# 仓位控制(plan.md §20)
# ------------------------------------------------------------
position:
max_position: 0.10 # 单只股票最大仓位 10%
min_position: 0.01 # 低于该权重不建仓(避免碎股)
sector_max_position: 0.25 # 单行业最大仓位 25%
max_holdings: 20
# equal | score | inverse_vol
weight_scheme: equal
# ------------------------------------------------------------
# 风险控制(plan.md §21)
# ------------------------------------------------------------
risk:
max_portfolio_drawdown: 0.20
max_single_drawdown: 0.25
# 单笔成交不超过该股当日成交额的比例
liquidity_limit_pct_adv: 0.05
# ------------------------------------------------------------
# 撮合
# ------------------------------------------------------------
execution:
signal_to_execution: next_open # next_open | next_close | same_close
limit_up_down_rule: skip
suspended_rule: defer
# ------------------------------------------------------------
# 成本:引用全局成本模型
# ------------------------------------------------------------
cost:
ref: config/cost.yml