Skip to content
Back to search

hl-quant

heuristic learning quant

Safety scan

A static text scan, not a guarantee. Select the badge to see what was scanned and every finding.

Checked today
Badge for your README
findsafeskills safety rating

Markdown

[![findsafeskills safety rating](/api/listings/toddwyl--hl-quant/badge.svg)](/listings/toddwyl--hl-quant)

HTML

<a href="/listings/toddwyl--hl-quant"><img src="/api/listings/toddwyl--hl-quant/badge.svg" alt="findsafeskills safety rating" /></a>

Install

i

Install instructions from the README

As written by the repo's author. findsafeskills has not verified these steps.

上面这套循环已经打包成一个可复用的 [Agent Skill](skills/hl-quant/SKILL.md),用 [`npx skills`](https://github.com/vercel-labs/skills) 一键安装到你自己的 agent(Claude Code / Cursor 等):

npx skills add toddwyl/hl-quant

装好后,跟 agent 说「用启发式探索优化这个策略」就会触发它,按 `Probe → Diagnose → Propose → Patch → Evaluate → Decide` 的纪律帮你迭代——只改策略文件、严格门槛、反过拟合。

What was scanned

The files the safety scan read, as written by the repository's author and shown as plain text. Lines with a finding are marked.

README.md · README · 202 lines

View this file on GitHub (read at the repository's current version: the scan did not record which commit it read)

  1. <div align="center">
  2. <img src="docs/images/banner.svg" alt="hl-quant" width="760">
  3. ### 把量化研究压缩成「一个可编辑的策略 + 一个固定的打分器」<br>再用启发式学习持续把指标推高。
  4. 中文 · [English](README.en.md)
  5. [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
  6. [![Stars](https://img.shields.io/github/stars/toddwyl/hl-quant?style=flat)](https://github.com/toddwyl/hl-quant/stargazers)
  7. [![Agent Skill](https://img.shields.io/badge/Agent%20Skill-npx%20skills-black)](skills/hl-quant/SKILL.md)
  8. [![Demo Data: JoinQuant](https://img.shields.io/badge/demo%20data-聚宽%20JQData-orange)](https://www.joinquant.com/help/api/doc?name=JQDatadoc)
  9. [![Linux.do community](https://img.shields.io/badge/Linux.do-community-0ea5e9)](https://linux.do/)
  10. [What is this](#what-is-this) · [快速开始](#快速开始) · [How it works](#how-it-works) · [安装 Skills](#安装-skills) · [Star History](#star-history)
  11. </div>
  12. ---
  13. ## What is this
  14. `hl-quant` 把 Jiayi Weng 的 [Heuristic Learning](https://trinkle23897.github.io/learning-beyond-gradients/) 框架和 Andrej Karpathy 的 [auto-research](https://github.com/karpathy/autoresearch) 范式,落到**量化交易策略优化**这件具体的事上。
  15. 它是一个**最小化**的范例:把量化策略的研究流程,提炼成「**一个可编辑的策略 + 一个固定的回测打分器**」两件东西,再用启发式学习(Heuristic Learning / 启发式探索)一轮轮把分数推高。
  16. 这里保留的是一个**通用的最小演示**:用简单策略和固定回测器展示 HL 如何组织“提出假设 → 修改策略 → 固定评估 → 接受/拒绝”的优化过程。具体策略、股票池、数据源、交易约束和评分门槛都需要按自己的研究目标重新设计;本仓库不构成投资建议。
  17. ## 核心范式:固定评估器 + 单一可编辑程序
  18. ```
  19. ┌─────────────────┐ 改它 ┌──────────────────┐
  20. HL → │ strategy.py │ ──────────▶ │ backtest.py │ ──▶ 一个分数
  21. │ 唯一可编辑程序 │ 只读它 │ 固定评估器 │ (score)
  22. └─────────────────┘ └──────────────────┘
  23. ```
  24. - **`strategy.py`** —— 策略的唯一语义源。启发式学习**只允许改这一个文件**:提假设、改逻辑、调参数。
  25. - **`backtest.py`** —— 固定的评估口径。拉数据、模拟成交、算指标、输出**单一分数**。一旦固定就**不许动**——否则「改了评估器把分数刷上去」,候选之间不再可比。
  26. 每个候选策略都用同一条命令、同一段数据、同一个评分公式打分,于是「这版到底有没有更好」变成一个可排序的客观问题。
  27. 评分口径采用 **Sortino ratio(索提诺比率)**,把一条策略的下行风险调整后收益压成一个标量:
  28. ```
  29. score = Sortino
  30. ```
  31. > [!NOTE]
  32. > 范式背后的完整设计见 [`docs/design/heuristic-exploration-framework.md`](docs/design/heuristic-exploration-framework.md)。
  33. ## 快速开始
  34. <details>
  35. <summary>🔑 配置数据凭证</summary>
  36. 示例回测默认用[聚宽 JQData](https://www.joinquant.com/help/api/doc?name=JQDatadoc) 拉取日线数据,只是为了演示数据接口和固定评估流程;实际项目可以替换成自己的数据源。不要把账号密码写进代码或提交进仓库,用环境变量传入:
  37. ```bash
  38. export JOINQUANT_ACCOUNT=<你的聚宽账号>
  39. export JOINQUANT_PASSWORD=<你的聚宽密码>
  40. ```
  41. </details>
  42. <details>
  43. <summary>📦 安装依赖</summary>
  44. 按 `requirements.txt` 安装依赖:
  45. ```bash
  46. pip install -r requirements.txt
  47. ```
  48. </details>
  49. <details>
  50. <summary>▶️ 跑一次回测</summary>
  51. ```bash
  52. cd example
  53. python backtest.py
  54. ```
  55. </details>
  56. ## How it works
  57. <details>
  58. <summary>🧭 HL 循环</summary>
  59. 启发式学习是一个结构化的推理循环——每一轮提一个**有经济含义**的假设,只改策略文件,用固定评估器打分,**严格更好才留**:
  60. ```
  61. Probe(跑基线)→ Diagnose(看弱点)→ Propose(提一个有经济含义的假设)
  62. → Patch(只改 strategy.py)→ Evaluate(固定评估器打分)→ Decide(严格更好才留)
  63. ```
  64. 两条硬规矩:
  65. 1. **只改 `strategy.py`**,评估器 / 数据源 / 评分公式一律不动。
  66. 2. **严格更好才算数**——分数没有严格高于基线的候选,不予保留;窄区间死区式的过拟合(在连续变量上挖 1~2 点宽的坑)一律拒绝。
  67. </details>
  68. <details>
  69. <summary>📈 演示:HL trial ledger</summary>
  70. 按 [`skills/hl-quant/SKILL.md`](skills/hl-quant/SKILL.md) 的纪律跑:固定评估器不动,只改 `strategy.py`,每轮留下证据、判断和决策。
  71. 固定命令:
  72. ```bash
  73. cd example
  74. python backtest.py
  75. ```
  76. 本轮回测标的为上证指数(`000001.XSHG`),区间 `2025-03-01 ~ 2026-02-28`,同期买入持有约 **+25.50%**。
  77. | HL 步骤 | 证据 | 判断 | 动作 |
  78. | --- | --- | --- | --- |
  79. | **Probe** | 基线 5/10:score 0.7545,总收益 +5.46%,胜率 41.67%,12 笔交易 | 只吃到指数涨幅的一小段,交易多但质量低 | 保持评估器不动,进入诊断 |
  80. | **Diagnose** | 12 笔交易、胜率低、收益远低于买入持有 | 5/10 均线太灵敏,震荡里频繁翻转、过早离场 | 聚焦“均线灵敏度”这一变量 |
  81. | **Propose** | 趋势行情里,放慢均线通常能过滤日间噪声 | 把 5/10 放慢到 10/20 有经济含义,不是窄区间挖坑 | 只提出这一处参数变化 |
  82. | **Patch** | `strategy.py` 是唯一可编辑程序 | 评估器、数据源、评分公式不动 | `SHORT_WINDOW: 5 → 10`,`LONG_WINDOW: 10 → 20` |
  83. | **Evaluate** | 10/20:score 2.0615,总收益 +17.33%,胜率 57.14%,7 笔交易 | 分数严格提高,收益、Sharpe、回撤、胜率同步改善 | 候选进入接受检查 |
  84. | **Replay** | 10/30、20/60 分数更高,但只剩 2 笔 / 1 笔交易 | 样本量过小,像撞上这段行情 | 拒绝追最高分 |
  85. | **Decide** | 10/20 分数更高且交易笔数仍可接受 | 改进可信度高于 10/30、20/60 | **接受 10/20** |
  86. 实际补丁只有两个参数:
  87. ```python
  88. SHORT_WINDOW = 10 # 基线 5
  89. LONG_WINDOW = 20 # 基线 10
  90. ```
  91. 固定评估器重跑输出:
  92. ```
  93. 参数 SHORT_WINDOW=10 LONG_WINDOW=20
  94. ------------------------------------------------
  95. 总收益 : +17.33%
  96. 年化收益 : +18.19%
  97. Sharpe : 1.839
  98. Sortino : 2.062
  99. 最大回撤 : 6.71%
  100. 胜率 : 57.14% (7 笔)
  101. ------------------------------------------------
  102. >>> SCORE : 2.0615
  103. ```
  104. 候选证据表:
  105. | 候选 | Score / Sortino | 总收益 | Sharpe | 最大回撤 | 胜率 | 交易笔数 | 决策 |
  106. | --- | ---: | ---: | ---: | ---: | ---: | ---: | --- |
  107. | 5/10 基线 | 0.7545 | +5.46% | 0.698 | 7.10% | 41.67% | 12 | 基线 |
  108. | 10/20 | 2.0615 | +17.33% | 1.839 | 6.71% | 57.14% | 7 | 接受 |
  109. | 10/30 | 2.2579 | +19.24% | 2.017 | 4.94% | 100.00% | 2 | 拒绝:样本太少 |
  110. | 20/60 | 2.0898 | +17.93% | 1.915 | 5.01% | 100.00% | 1 | 拒绝:样本太少 |
  111. </details>
  112. ## 安装 Skills
  113. 上面这套循环已经打包成一个可复用的 [Agent Skill](skills/hl-quant/SKILL.md),用 [`npx skills`](https://github.com/vercel-labs/skills) 一键安装到你自己的 agent(Claude Code / Cursor 等):
  114. ```bash
  115. npx skills add toddwyl/hl-quant
  116. ```
  117. 装好后,跟 agent 说「用启发式探索优化这个策略」就会触发它,按 `Probe → Diagnose → Propose → Patch → Evaluate → Decide` 的纪律帮你迭代——只改策略文件、严格门槛、反过拟合。
  118. ## 仓库结构
  119. ```
  120. hl-quant/
  121. ├── README.md
  122. ├── requirements.txt # pip 依赖(仓库不附带任何虚拟环境)
  123. ├── example/
  124. │ ├── strategy.py # 唯一可编辑程序(HL 改这里)
  125. │ └── backtest.py # 固定评估器(拉示例数据 → 模拟 → 打分)
  126. ├── skills/
  127. │ └── hl-quant/SKILL.md # 可 npx 安装的启发式探索 skill
  128. └── docs/
  129. └── design/heuristic-exploration-framework.md # 范式背后的完整设计
  130. ```
  131. ## Star History
  132. <a href="https://star-history.com/#toddwyl/hl-quant&Date">
  133. <picture>
  134. <source media="(prefers-color-scheme: dark)" srcset="https://api.star-history.com/svg?repos=toddwyl/hl-quant&type=Date&theme=dark" />
  135. <source media="(prefers-color-scheme: light)" srcset="https://api.star-history.com/svg?repos=toddwyl/hl-quant&type=Date" />
  136. <img alt="Star History Chart" src="https://api.star-history.com/svg?repos=toddwyl/hl-quant&type=Date" width="600" />
  137. </picture>
  138. </a>
  139. ## References
  140. Weng, J. (2026). *Learning Beyond Gradients*. https://trinkle23897.github.io/learning-beyond-gradients/
  141. Karpathy, A. (2025). *auto-research*. https://github.com/karpathy/autoresearch

Ratings and comments

Sign in to rate this skill.

Sign in

Free to use. If it’s helped, pass it on.