grid-optimizer

ETF/stock grid-trading parameter optimizer. Triggered when users mention terms like "optimize grid", "grid parameters", "grid trading optimization", "adjust my grid", "ETF grid setup", "grid spacing", "T+1 grid", "stock grid", or provide ETF/stock codes seeking grid parameter optimization. Not applicable to non-grid strategies, pure fundamental analysis, or pure market data queries.

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 "grid-optimizer" from this exact SkillPI detail page: https://skillpi.com/skills/deepskill-cb238cc6fe32f7f8de2cdf665b28b66365f7e8eca7c5d14f23e7539fe00de60c. Verify the upstream source and version against https://skillhub.cn/skills/user_c1ee5550/grid-optimizer 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

ETF/stock grid-trading parameter optimizer. Triggered when users mention terms like "optimize grid", "grid parameters", "grid trading optimization", "adjust my grid", "ETF grid setup", "grid spacing", "T+1 grid", "stock grid", or provide ETF/stock codes seeking grid parameter optimization. Not applicable to non-grid strategies, pure fundamental analysis, or pure market data queries.

0 Downloads

Introduction source: third_party · user_c1ee5550 · 1.0.0 Reference

SkillPi interpretation

Tasks
Translation pending; see source documentation.
Limits and differences
Translation pending; see source documentation.
Testing
Not tested

Browse files

Browse files at the source ↗

Original SKILL.md

Open original ↗
Frontmatter
name: grid-optimizer
slug: grid-optimizer
version: "1.0.0"
displayName: Grid Optimizer
description: ETF/股票网格交易参数优化。当用户提到"优化网格"、"网格参数"、"网格交易优化"、"帮我调网格"、"ETF网格设置"、"网格间距"、"T+1网格"、"股票网格",或提供了ETF/股票代码希望优化网格交易参数时触发。不适用于非网格类策略、纯基本面分析、纯行情查询。

Grid Optimizer v4 — ETF/股票网格交易参数优化

概述

帮用户找到网格交易的最优参数组合。支持两种交易模式:

  • T0模式(ETF日内回转):回落卖出/反弹买入跟踪触发,窄间距0.3-1.99%
  • T+1模式(股票隔日交易):简单价格触发,宽间距2-5%,叠加股息率综合收益

通过拉取真实K线数据 → 校准蒙特卡洛模拟(含波动率聚集AR(1))→ 参数网格搜索 → 实操约束筛选 → 多目标评分(含最大回撤)→ 多场景稳健性验证,输出可直接在同花顺上设置的推荐方案。

你的工作方式

两个阶段:Phase 1(Agent拉数据)→ Phase 2-4(脚本一次性完成所有计算),Agent解读输出向用户汇报。


Phase 1:数据采集

目标

获取标的近250个交易日的日线OHLC数据和实时行情,整理为CSV文件供脚本使用。

步骤

  1. 确定标的信息:从用户提供的代码确定 code 和 setcode(沪市="1",深市="0",北交所="2")
  2. 确定交易模式:
    • ETF → T0模式(--mode t0,tick-size=0.001)
    • 股票 → T+1模式(--mode t1,tick-size=0.01)
  3. 拉取K线数据:使用 tdx_kline 工具(参数:period="4", wantNum="250", tqFlag="0" 不复权),分批拉取避免截断(每批25根,并行10个API调用覆盖250根)
  4. 拉取实时行情:使用 tdx_quotes 获取当前价格、昨收价(基准价)、涨跌停价等
  5. 写入CSV文件:从K线API返回中提取每根K线的日期/开盘/最高/最低/收盘,写入CSV文件(格式:日期,开盘,最高,最低,收盘,无表头),保存到workspace临时路径
  6. 向用户简要汇报:数据量、数据范围、当前价格和昨收价

注意事项

  • API一次返回数据可能被截断,务必分批(25根/批)拉取,用 startxh 做偏移
  • tqFlag="0" 不复权,网格交易基于真实价格
  • 振幅统计由脚本计算,Agent无需重复计算

Phase 2-4:运行优化脚本(一次性完成)

目标

调用 grid_optimizer.py 完成MC模拟、参数搜索、稳健性验证、历史回测和推荐方案输出。

步骤

  1. 准备K线数据文件:将Phase 1采集的OHLC数据写成CSV文件

  2. 确定脚本参数:

    通用必选参数:

    • --data: CSV文件路径
    • --code: 证券代码
    • --current-price: 最新价
    • --yesterday-close: 昨收价(基准价)
    • --limit-up / --limit-down: 涨跌停价

    模式选择:

    • --mode t0: ETF日内回转(默认)
    • --mode t1: 股票隔日交易

    T0模式常用参数:

    • --cost 0.05(万五佣金)
    • --tick-size 0.001(ETF最小变动)
    • --user-rise/pb-s/fall/pb-b(用户对照组,4个全提供才启用)

    T1模式专用参数:

    • --tick-size 0.01(个股最小变动)
    • --dividend-yield 5.9(年股息率%,计入综合收益)
    • --capital 45600(总资金,提供时输出仓位管理方案)
    • --base-position-pct 60(底仓占比%,默认60%)

    可选参数:

    • --mc-trials 200 / --sim-days 250 / --robust-trials 50
    • --vol-persistence 0.75(波动率聚集系数AR(1) φ,0=无聚集,0.75=中等,0.95=强聚集)
  3. 调用脚本:

    T0模式(ETF):

    python3 scripts/grid_optimizer.py \
      --mode t0 --data <CSV> --code <ETF代码> \
      --current-price <最新价> --yesterday-close <昨收> \
      --limit-up <涨停> --limit-down <跌停> \
      --cost 0.05 --tick-size 0.001

    T+1模式(股票):

    python3 scripts/grid_optimizer.py \
      --mode t1 --data <CSV> --code <股票代码> \
      --current-price <最新价> --yesterday-close <昨收> \
      --limit-up <涨停> --limit-down <跌停> \
      --cost 0.05 --tick-size 0.01 \
      --dividend-yield <股息率> --capital <总资金> --base-position-pct 60
  4. 解读输出:脚本输出完整文本报告(10+部分),Agent需提取关键信息向用户汇报:

    • 振幅统计摘要
    • TOP20方案表(含最大回撤列)
    • 🥇方案A和🥈方案B的具体参数
    • T+1模式:综合年化收益(网格+股息)和仓位管理方案
    • 6场景稳健性验证结果(含回撤列)
    • 历史回测结果
    • 同花顺实操设置指南

⚠️ 确认门(可选)

脚本运行约2-5分钟,可先仅汇报Phase 1振幅统计,等用户确认后再调用脚本。


v4版本新增功能

功能 说明
T+1原生模式 --mode t1启用,简单价格触发,间距2-5%自适应
自适应搜索范围 T1模式根据日均振幅自动计算搜索区间
仓位管理 --capital提供时输出底仓+网格资金分配方案
风险指标 最大回撤纳入评分体系(权重15%)
波动率聚集 AR(1)模型φ参数,模拟趋势行情中的波动聚集
股息叠加 T1模式综合年化=网格收益+股息率

评分体系

综合评分 = 日均收益35% + Sharpe25% + 稳定性15% + 触发频率10% + 回撤控制15%


多轮修改

如果用户对推荐方案不满意,可以:

  • 调整参数范围:如缩小间距区间或只看对称方案
  • 调整评分权重:如更重视Sharpe或回撤
  • 更改交易成本:如佣金万三
  • 调整波动率聚集:--vol-persistence 0(无聚集)到0.95(强趋势)
  • 更换基准价:如用5日均价或每股净资产

资源目录

scripts/

grid_optimizer.py — 核心优化脚本v4,支持T0/T+1双模式。

references/

methodology.md — 详细方法论说明。


工作流示例

示例1:ETF T0优化

用户:"帮我优化159829的网格参数"

  1. Phase 1: 确认159829为深市ETF(setcode="0"),拉250日K线+实时行情
  2. Phase 2-4: --mode t0 --tick-size 0.001,调用脚本,解读输出

示例2:股票T+1优化

用户:"帮我算兴业银行的T+1网格参数"

  1. Phase 1: 确认601166为沪市(setcode="1"),拉250日K线+实时行情,获取PE/PB/股息率
  2. Phase 2-4: --mode t1 --tick-size 0.01 --dividend-yield 5.9 --capital 45600 --base-position-pct 60,调用脚本
  3. 解读输出:重点汇报综合年化收益(网格+股息)和仓位管理方案

示例3:对比当前设置

用户:"我现在用的是1.99%/0.40%/1.99%/0.40%,帮我看看有没有更好的"

  1. Phase 1: 拉取数据(同上)
  2. Phase 2-4: 传入--user-rise 1.99 --user-pb-s 0.40 --user-fall 1.99 --user-pb-b 0.40,脚本自动对比

Current listing version

1.0.0

Verify the source revision ↗

Safety and assessment details

Quality assessment

Out of 100 · Assessment report from SkillPi LAB.

Scenario Value92/100

Areas to improve

  • 缺少When to Use章节 Reported severity: Minor

    文档结构完整但未显式标注When to Use章节

    Recommendation: 建议在概述后增加When to Use章节明确适用场景

Highlights

  • 解决ETF/股票网格交易参数优化的核心痛点
  • 支持T0/T+1双模式覆盖主流交易场景
  • 多轮修改能力增强用户体验
Trigger Precision95/100

Highlights

  • 触发词覆盖全面且边界清晰
  • 明确排除非网格类策略避免误触
Structure and Standards93/100

Highlights

  • Phase划分清晰有明确出口条件
  • 提供3个端到端示例增强可操作性
  • frontmatter完整版本信息明确
Execution Reliability91/100

Highlights

  • 工具来源明确参数设置合理
  • 覆盖分批拉取防截断等异常场景
  • 脚本调用路径清晰可靠
Evidence Verifiability (mean of the first four)93/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.