Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 14 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
- **盘后复盘**:指数、涨跌家数、板块轮动、涨停池、龙虎榜和市场情绪温度。
- **价值投资数据**:估值分位、股息、股东结构、ETF 折溢价、财报日历、公告,以及美股 SEC 13F / Form 4。
- **持仓与风控**:组合集中度、压力测试、调仓计划和仓位计算;只计算你本次传入的数据,不保存账户。
- **策略视角**:缠论、波浪理论、龙头战法、情绪周期等 18 套方法论,以 Skill 形式按需调用。
- **策略视角**:缠论、波浪理论、龙头战法、情绪周期等 19 套方法论,以 Skill 形式按需调用。
- **dsh 仪表盘**:在 dsh Web / Desktop 侧栏看自选股和六个市场的行情,后台预热,打开即显示。

一共 76 个工具、21 个 Skills,11 个数据源自动容灾。大部分功能不需要任何 API Key。
一共 77 个工具、22 个 Skills,11 个数据源自动容灾。大部分功能不需要任何 API Key。

## 快速开始

Expand Down Expand Up @@ -140,11 +140,12 @@
| 全市场选股 | `/skill:stock-screener` | L1 多因子硬筛(市场情绪调节,可选 `--l2` 量化增强)→ L2 LLM 智能排序 → 输出推荐列表 |
| 策略回测 | `/skill:strategy-backtest` | YAML 策略定义 → 回测 → 诊断;按需进行最多 3 轮参数优化 |

### 策略、复盘与研究(18 个)
### 策略、复盘与研究(19 个)

| Skill | 调用方式 | 方法论 |
|-------|----------|--------|
| 趋势追踪 | `/skill:bull-trend` | 均线排列 + MACD 方向 + 趋势阶段判断 |
| 分时承接与底仓 T0 | `/skill:intraday-support-t0` | A 股分钟级 VWAP、量价与可选逐笔,支持等量配对观察和回放 |
| 缩量回调 | `/skill:shrink-pullback` | 上升趋势中的缩量洗盘识别 |
| 均线金叉 | `/skill:ma-crossover` | MA5/10/20/60 交叉信号 + 金叉质量评估 |
| 放量突破 | `/skill:volume-breakout` | 关键阻力位的放量突破确认 |
Expand All @@ -165,20 +166,20 @@

## 工具列表

76 个工具按用途分组:
77 个工具按用途分组:

| 类别 | 数量 | 主要内容 |
|------|------|----------|
| 数据获取 | 30 | K 线、报价、基金净值、资金流、财务、板块、涨停池、龙虎榜、两融、估值历史、股东、ETF、股息、公告、SEC、CDS 指数、宏观利率与汇率基准 |
| 分析计算 | 9 | 技术指标、K 线形态、量价、异动、信号胜率、趋势与行业轮动研究 |
| 分析计算 | 10 | 技术指标、K 线形态、量价、异动、信号胜率、趋势与行业轮动研究 |
| 筛选与回测 | 8 | 多因子选股、风险筛查、策略回测(含多标的组合/再平衡/定投)、市场状态、日度复盘、自选股批量分析 |
| 搜索与舆情 | 5 | 新闻搜索、综合情报、社交情绪、正文提取 |
| 辅助 | 7 | 名称/拼音解析、交易日历、交易时段、数据源诊断、股票列表解析 |
| 上下文与报告 | 8 | 自选股上下文、持仓分析、告警规则、信号记录与评估、研报渲染 |
| 无状态研究与风险计算 | 9 | 同行比较、公告变更、组合风险、调仓计划、仓位计算、DCF 估值、事件研究、回测稳健性 |

<details>
<summary>完整工具列表(76 个)</summary>
<summary>完整工具列表(77 个)</summary>

#### 数据获取

Expand All @@ -190,7 +191,7 @@
| `get_valuation_history` | A/HK/US PE-TTM/PB 历史、正值分位与估值 Band,实际采样窗口(美股由 SEC 申报与周收盘派生) |
| `get_index_valuation` | 中国指数 PE/PB 历史水位;中证官方多年滚动 PE;可选理杏仁补充 PB |
| `get_cds_index` | 市场级 CDS 指数:中国在岸 CFETS-SHCH 指数期限曲线,或 DTCC 公开成交的 CDX/iTraxx 当前系列日中位数;窗口变化与分位,可按 index/tenor 只取单个指数和期限;非个股 CDS |
| `get_macro_anchors` | 宏观、利率、汇率与风险偏好基准(免 Key,缓存 1 小时):中美 10Y/美债 2Y 收益率及利差(bp)、DXY/USD-CNH/USD-HKD/推导 HKD-CNY、VIX/黄金/原油 |
| `get_macro_anchors` | 宏观、利率、汇率与风险偏好基准;`liquidity_a` 查国内资金与信用,`liquidity_hk` 查美债实际利率、HIBOR、汇率和南向成交 |
| `get_earnings_calendar` | A 股报告期披露与业绩预告;HK 董事会排期;US/JP yfinance 预计日期(provider_only,非官方确认) |
| `get_shareholder_structure` | A 股股东户数/十大流通股东变化/报告期北向名义持股;HK 南向持股 |
| `get_etf_details` | A 股 ETF 净值折溢价、规模变动、披露持仓、可选基准成分与跟踪误差 |
Expand Down Expand Up @@ -219,6 +220,7 @@

| 工具 | 说明 |
|------|------|
| `analyze_intraday_t0` | 从调用方提供的 A 股分钟线和可选逐笔识别支撑回踩及 VWAP 收复;可回放底仓等量配对 |
| `calculate_rotation_metrics` | 真实MC-dropout分布集中度与历史原始配权计算;不生成预测或买入信号 |
| `backtest_rotation_allocation` | 股票/ETF代码自动取数,按市场与报价币种独立比较等权和历史配权;分项回测,非完整论文模型 |
| `analyze_trend_strategy` | 月度右侧趋势策略:单市场股票池筛选、真实旧仓保持/退出与逆波动新仓预算;直接传股票代码、自动取行情,无持仓存储,仍为not_validated |
Expand Down Expand Up @@ -462,7 +464,7 @@ sort_order: "desc"
npm install # 同时构建仓库 .venv
.venv/bin/python -m pytest -q # Python 单元测试(离线)
npx tsc --noEmit # TypeScript 类型检查
npx tsx tests/test_adapter_parity.ts # 四个宿主的 76 个工具和参数映射一致
npx tsx tests/test_adapter_parity.ts # 四个宿主的 77 个工具和参数映射一致
npm run build:openclaw && npm run build:dsh # 构建 OpenClaw / dsh bundle
```

Expand All @@ -474,12 +476,12 @@ npm run build:openclaw && npm run build:dsh # 构建 OpenClaw / dsh bundle
```
stock-analysis/
├── pi/ # Pi Agent Extension
│ └── index.ts # 注册 76 个工具 + 21 个 skill
│ └── index.ts # 注册 77 个工具 + 22 个 skill
├── hermes/ # Hermes Agent Plugin
│ ├── plugin.yaml # 插件清单
│ ├── __init__.py # register(ctx) 入口
│ ├── schemas.py # 读取 tools/tool_schemas.json
│ └── tools.py # 76 个 handler → subprocess 调 CLI
│ └── tools.py # 77 个 handler → subprocess 调 CLI
├── openclaw/ # OpenClaw Plugin
│ ├── openclaw.plugin.json # manifest(contracts.tools)
│ ├── package.json # 含 openclaw 块(pluginApi/SDK 版本)
Expand All @@ -494,7 +496,7 @@ stock-analysis/
│
├── mcp_host/ # MCP stdio 服务器(复用 Hermes schema/handler)
├── tools/ # 共享 Python CLI 工具
│ ├── tool_schemas.json # 76 个工具的名称/描述/参数(各宿主共用)
│ ├── tool_schemas.json # 77 个工具的名称/描述/参数(各宿主共用)
│ ├── stock_data.py # 行情 / 资金流 / 新闻 / 财务 / 短线情绪
│ ├── signal_tracker.py # AI 买卖建议回测闭环(本地 JSONL 存储)
│ ├── technical.py # 技术指标分析
Expand All @@ -511,7 +513,7 @@ stock-analysis/
│ ├── trading_calendar.py # 交易日历
│ └── requirements.txt
│
├── skills/ # 共享 SKILL.md(21 个)
├── skills/ # 共享 SKILL.md(22 个)
│ ├── stock-analysis/ # 综合分析 workflow
│ ├── stock-screener/ # 选股 workflow
│ ├── strategy-backtest/ # 回测 + 进化 workflow
Expand Down
4 changes: 2 additions & 2 deletions docs/hermes-integration.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ stock-analysis-plugin (wheel)
├── hermes/
│ ├── __init__.py # register(ctx) entry point
│ ├── plugin.yaml # plugin manifest
│ ├── schemas.py # loads tools/tool_schemas.json (JSON Schemas for 76 tools)
│ ├── tools.py # 76 handlers that run the CLIs as subprocesses
│ ├── schemas.py # loads tools/tool_schemas.json (JSON Schemas for 77 tools)
│ ├── tools.py # 77 handlers that run the CLIs as subprocesses
│ └── _payload/ # tools/, skills/, schemas/, templates/
└── mcp_host/ # MCP stdio server (stock-analysis-mcp)
```
4 changes: 2 additions & 2 deletions docs/hermes-integration.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ stock-analysis-plugin (wheel)
├── hermes/
│ ├── __init__.py # register(ctx) 入口
│ ├── plugin.yaml # 插件清单
│ ├── schemas.py # 读取 tools/tool_schemas.json(76 个工具的 JSON Schema)
│ ├── tools.py # 76 个 handler,以子进程调用 CLI
│ ├── schemas.py # 读取 tools/tool_schemas.json(77 个工具的 JSON Schema)
│ ├── tools.py # 77 个 handler,以子进程调用 CLI
│ └── _payload/ # tools/、skills/、schemas/、templates/
└── mcp_host/ # MCP stdio 服务器(stock-analysis-mcp)
```
6 changes: 3 additions & 3 deletions docs/mcp.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# MCP 接入指南(WorkBuddy / Claude Desktop / Cursor)

`mcp_host/server.py` 是本插件的 MCP stdio 服务器:一行一条 JSON-RPC 2.0 消息,只用 Python 标准库。它复用所有宿主共用的 JSON Schema(`tools/tool_schemas.json`,经 `hermes/schemas.py` 读取)和参数映射(`hermes/tools.py`),所以 76 个工具的名称、参数和输出与其他宿主一致。同时自动将 21 个 `skills/*/SKILL.md` 暴露为 MCP Prompts、将 `SKILL.md`、`references/` 与 `schemas/*.json` 暴露为只读 MCP Resources。
`mcp_host/server.py` 是本插件的 MCP stdio 服务器:一行一条 JSON-RPC 2.0 消息,只用 Python 标准库。它复用所有宿主共用的 JSON Schema(`tools/tool_schemas.json`,经 `hermes/schemas.py` 读取)和参数映射(`hermes/tools.py`),所以 77 个工具的名称、参数和输出与其他宿主一致。同时自动将 22 个 `skills/*/SKILL.md` 暴露为 MCP Prompts、将 `SKILL.md`、`references/` 与 `schemas/*.json` 暴露为只读 MCP Resources。

## 前置条件

Expand Down Expand Up @@ -36,7 +36,7 @@
| Claude Desktop | `claude_desktop_config.json`(设置 → Developer → Edit Config) |
| Cursor | `~/.cursor/mcp.json`(全局)或 `<项目目录>/.cursor/mcp.json` |

保存后,客户端里出现 76 个工具(如 `get_quote`、`get_technical_analysis`、`get_macro_anchors`)即接入成功。
保存后,客户端里出现 77 个工具(如 `get_quote`、`get_technical_analysis`、`get_macro_anchors`)即接入成功。

### 按需发现与精简模式(降低上下文占用)

Expand All @@ -51,7 +51,7 @@
- **错误**:未知工具、参数不是对象、未知方法、无法解析的 JSON 作为 JSON-RPC 错误返回(`-32602` / `-32601` / `-32700` / `-32600`)。缺少必填参数、数据源失败、Python CLI 超时则作为工具结果返回:`isError: true`,正文为 `{"error": "..."}`。
- **并发与取消**:每次 `tools/call` 在独立线程里运行。收到 `notifications/cancelled` 后,服务器会结束对应的 Python 子进程,并且不再回复该请求。客户端关闭 stdin 时,服务器结束所有进行中的调用后退出。
- **超时**:沿用 `tools/cli_budgets.json` 的命令预算,与其他宿主一致。
- **Skills 与 Schemas**:21 个 `skills/*/SKILL.md` 已自动暴露为 MCP Prompts(带可选 `request` 参数,并在 `prompts/get` 头部附带 MCP 工具与资源调用引导,适配无本地 shell 环境的客户端);`SKILL.md` 与 `references/` 暴露为只读 `stock-skill://...` Resources,`schemas/*.json`(如 `stock-schema://report_schema.json`)暴露为只读 `stock-schema://...` Resources。
- **Skills 与 Schemas**:22 个 `skills/*/SKILL.md` 已自动暴露为 MCP Prompts(带可选 `request` 参数,并在 `prompts/get` 头部附带 MCP 工具与资源调用引导,适配无本地 shell 环境的客户端);`SKILL.md` 与 `references/` 暴露为只读 `stock-skill://...` Resources,`schemas/*.json`(如 `stock-schema://report_schema.json`)暴露为只读 `stock-schema://...` Resources。

## 本地验证

Expand Down
2 changes: 1 addition & 1 deletion docs/openclaw-integration.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ OpenClaw Gateway 启动时会扫描 `extensions/*` 工作区包并加载。
openclaw plugins inspect stock-analysis --runtime --json
```

应该看到 76 个 tool 全部出现在 `tools` 列表里。也可以直接在 OpenClaw 对话中调用:
应该看到 77 个 tool 全部出现在 `tools` 列表里。也可以直接在 OpenClaw 对话中调用:

```
帮我查一下贵州茅台的实时行情
Expand Down
6 changes: 3 additions & 3 deletions docs/pi-integration.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ npm install

## Verify

Start Pi and type `/skills`. You should see 21 Skills, such as `stock-analysis`, `stock-screener` and `strategy-backtest`. Then ask:
Start Pi and type `/skills`. You should see 22 Skills, such as `stock-analysis`, `stock-screener` and `strategy-backtest`. Then ask:

```
Get the real-time quote for AAPL
Expand All @@ -53,7 +53,7 @@ The agent should call `get_quote` and return market data.

## On-demand tool discovery

Pi 1.5.2 supports native tool discovery. At session startup, the plugin checks for the native `tool_search` exposure metadata and active-tool APIs. When available, it defers its stock tools and activates search while preserving other active tools. Older hosts and SDK sessions without the native search extension keep all 76 tools directly exposed.
Pi 1.5.2 supports native tool discovery. At session startup, the plugin checks for the native `tool_search` exposure metadata and active-tool APIs. When available, it defers its stock tools and activates search while preserving other active tools. Older hosts and SDK sessions without the native search extension keep all 77 tools directly exposed.

If search is registered but inactive, the plugin enables it and confirms activation before deferring stock tools. Missing, restricted, or unavailable search keeps the tools directly exposed. Disabling search during a session restores the stock tools before the next model request and removes the discovery guidance.

Expand Down Expand Up @@ -125,7 +125,7 @@ git pull && npm install

```
stock-analysis-plugin/
├── pi/index.ts # Pi extension entry: 76 tools and 21 Skills
├── pi/index.ts # Pi extension entry: 77 tools and 22 Skills
├── tools/ # shared Python CLIs
├── skills/ # SKILL.md files
├── schemas/ templates/ strategies/
Expand Down
6 changes: 3 additions & 3 deletions docs/pi-integration.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ npm install

## 验证

启动 Pi 后输入 `/skills`,应能看到 21 个 Skill(如 `stock-analysis`、`stock-screener`、`strategy-backtest`)。再问一句:
启动 Pi 后输入 `/skills`,应能看到 22 个 Skill(如 `stock-analysis`、`stock-screener`、`strategy-backtest`)。再问一句:

```
帮我查一下贵州茅台的实时行情
Expand All @@ -53,7 +53,7 @@ Agent 应调用 `get_quote` 并返回行情。

## 按需工具发现

最新稳定版 Pi 1.5.2 支持原生按需工具发现。插件在 `session_start` 检查 `tool_search` 的 exposure 元数据及活动工具 API:具备这些能力时,将股票工具设为 `deferred` 并启用原生搜索,保留其他插件的活动工具;旧宿主保持原来的 76 工具全量暴露,无需升级才能继续使用。
最新稳定版 Pi 1.5.2 支持原生按需工具发现。插件在 `session_start` 检查 `tool_search` 的 exposure 元数据及活动工具 API:具备这些能力时,将股票工具设为 `deferred` 并启用原生搜索,保留其他插件的活动工具;旧宿主保持原来的 77 工具全量暴露,无需升级才能继续使用。

新版中搜索已注册但未激活时,插件会尝试启用并确认成功后再隐藏股票工具;未加载搜索扩展、被宿主限制或无法启用时保持全量暴露。会话中途关闭搜索时,下次模型请求前恢复全部股票工具,并停止发送搜索指引。

Expand Down Expand Up @@ -125,7 +125,7 @@ git pull && npm install

```
stock-analysis-plugin/
├── pi/index.ts # Pi Extension 入口,注册 76 个工具和 21 个 Skill
├── pi/index.ts # Pi Extension 入口,注册 77 个工具和 22 个 Skill
├── tools/ # 共享 Python CLI
├── skills/ # SKILL.md
├── schemas/ templates/ strategies/
Expand Down
5 changes: 5 additions & 0 deletions docs/tool-behavior.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,8 @@ python tools/stateless_analysis.py position_size --input input.json
L1 与 L2 综合分均在排序前按可用因子重新归一化;缺失或非有限因子不作零分处理,因子组内部也仅平均有效输入。factor_coverage.ratio 保留原始权重覆盖率,effective_weights 是实际归一化后的权重,高分仍需结合覆盖率判断。估值比较需同时读取 `pe_basis`;有限非正 PE/PB 的价值子分为 0,不能因数值更低而获得最高价值分。

L2 的 `vol20` 只使用恰好 20 个有效日收益,`factor_coverage.vol20_samples` 记录实际样本数,非正/非有限收盘价先剔除,空输入为 0;质量因子按 `report_date` 分组归一,避免年度累计与单季累计直接比较。资金流 5/10/20 日窗口不足返回 null,不按 0 或完整窗口处理。HK 快照统一带 `.HK`,US 快照移除东财交易所后缀并把类别股点号转为 Yahoo 连字符。主板 ST/*ST 按 5% 识别涨跌停,其他板块比例不变。

## 宏观流动性与分时承接

- `get_macro_anchors(group="liquidity_a"|"liquidity_hk")` 为可选分组。指标返回实际日期、来源、单位、窗口变化、滞后和缺失;现有默认分组维持原来的指标集合。方法及历史方向核验见[宏观流动性](../skills/stock-analysis/references/macro-liquidity.md)。
- `analyze_intraday_t0` 接受单日已收盘 A 股分钟 K 线及可选逐笔,`mode="backtest"` 使用按日期排列的历史会话。分钟输入、降级、配对条件和回放口径见[分时承接与底仓 T0](../skills/intraday-support-t0/SKILL.md)。
Loading
Loading