stock-analysis-plugin 0.1.15 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +20 -12
- package/package.json +3 -2
- package/pi/index.ts +193 -18
- package/skills/dragon-head/SKILL.md +3 -1
- package/skills/emotion-cycle/SKILL.md +2 -0
- package/skills/hot-theme/SKILL.md +2 -1
- package/skills/stock-analysis/SKILL.md +9 -1
- package/tools/alert_rules.py +5 -18
- package/tools/backtest.py +4 -4
- package/tools/capabilities.py +8 -0
- package/tools/gather.py +12 -31
- package/tools/market_review.py +1 -1
- package/tools/name_resolver.py +4 -10
- package/tools/pattern.py +3 -24
- package/tools/report_renderer.py +1 -2
- package/tools/screener.py +5 -18
- package/tools/search_intel.py +1 -24
- package/tools/signal_tracker.py +275 -0
- package/tools/stock_data.py +580 -110
- package/tools/trading_calendar.py +110 -9
- package/tools/volume_analysis.py +3 -23
- package/tools/watchlist_context.py +1 -10
- package/scripts/sync-version.sh +0 -56
package/README.md
CHANGED
|
@@ -31,7 +31,7 @@ A 股 / 港股 / 美股 / 日股 / 韩股 / 台股综合分析、多因子选股
|
|
|
31
31
|
|
|
32
32
|
## 功能概览
|
|
33
33
|
|
|
34
|
-
- **
|
|
34
|
+
- **48 个工具** — 行情数据、技术分析、K 线形态、资金流向、财务指标、新闻舆情、风险筛查、市场状态等
|
|
35
35
|
- **20 个 Skills** — 综合分析、全市场选股、策略回测 + 17 个策略方法论(缠论、波浪、龙头、情绪周期等)
|
|
36
36
|
- **策略回测引擎** — YAML DSL 定义策略,参数化条件组合,自动诊断,按需进行有限轮参数优化
|
|
37
37
|
- **多数据源 Failover** — 11 个数据源自动容灾切换(akshare / tushare / efinance / 腾讯行情 / 新浪行情 / pytdx / baostock / yfinance / finnhub / longbridge / alphavantage),A 股链路带粘性优选(最近成功的数据源下次优先尝试)
|
|
@@ -92,7 +92,7 @@ register(ctx)
|
|
|
92
92
|
openclaw plugins install clawhub:@weaxs/openclaw-stock-analysis
|
|
93
93
|
```
|
|
94
94
|
|
|
95
|
-
OpenClaw Gateway 启动后自动加载并注册
|
|
95
|
+
OpenClaw Gateway 启动后自动加载并注册 48 个 tool。安装时 postinstall 会自动建 `.venv` 并装好 Python 依赖(前提:本机有 `python3 >= 3.9`)。
|
|
96
96
|
|
|
97
97
|
详见 [OpenClaw 接入指南](docs/openclaw-integration.md),或 plugin 自身说明 [`openclaw/README.md`](openclaw/README.md)。
|
|
98
98
|
|
|
@@ -103,7 +103,7 @@ dsh plugin --profile <你的profile> add @weaxs/dsh-stock-analysis
|
|
|
103
103
|
dsh --profile <你的profile>
|
|
104
104
|
```
|
|
105
105
|
|
|
106
|
-
作为 dsh bundle 安装:`dsh plugin add` 会把 `cordis.patch.yml` 叠加进 profile 组合,注册
|
|
106
|
+
作为 dsh bundle 安装:`dsh plugin add` 会把 `cordis.patch.yml` 叠加进 profile 组合,注册 48 个 tool + 20 个 skill。postinstall 自动建 `.venv`(pnpm 需在 profile 的 `pnpm-workspace.yaml` 里给本包配 `allowBuilds`,否则回退系统 `python3`)。
|
|
107
107
|
|
|
108
108
|
详见 [`dsh/README.md`](dsh/README.md)。
|
|
109
109
|
|
|
@@ -236,17 +236,20 @@ Agent 会自动调用行情 → 技术面 → 基本面 → 资金面 → 消息
|
|
|
236
236
|
| 工具 | 说明 |
|
|
237
237
|
|------|------|
|
|
238
238
|
| `get_kline` | K 线数据(OHLCV),支持日/周/月线 |
|
|
239
|
-
| `get_quote` |
|
|
239
|
+
| `get_quote` | 实时行情快照(非交易时段返回最近交易日收盘价并以 as_of/stale 标注) |
|
|
240
240
|
| `get_capital_flow` | 资金流向(仅 A 股) |
|
|
241
241
|
| `get_news` | 个股相关新闻 |
|
|
242
242
|
| `get_financials` | 财务指标 |
|
|
243
243
|
| `get_stock_info` | 股票基本信息 |
|
|
244
244
|
| `get_chip_distribution` | 筹码分布 |
|
|
245
245
|
| `get_market_indices` | 主要指数行情 |
|
|
246
|
-
| `get_sector_rankings` |
|
|
246
|
+
| `get_sector_rankings` | 板块涨跌排行(行业/概念) |
|
|
247
247
|
| `get_sector_constituents` | 板块成分股查询(仅 A 股,板块名模糊匹配) |
|
|
248
248
|
| `resolve_stock_sectors` | 个股所属板块查询(A 股行业+概念 / 港股 GICS) |
|
|
249
249
|
| `get_market_stats` | 市场统计(涨跌家数、涨停等) |
|
|
250
|
+
| `get_limit_up_pool` | 涨停池/涨停板复盘(连板数、封板资金、炸板次数等,仅 A 股;非交易日自动回退到最近交易日并以 requested_date/stale 标注) |
|
|
251
|
+
| `get_dragon_tiger` | 龙虎榜(净买额/上榜原因/解读,仅 A 股;非交易日自动回退到最近交易日并以 requested_date/stale 标注) |
|
|
252
|
+
| `get_hot_stocks` | 全市场人气热搜榜(东财→雪球→百度,仅 A 股) |
|
|
250
253
|
| `get_fundamental_context` | 基本面综合上下文 |
|
|
251
254
|
|
|
252
255
|
### 分析计算
|
|
@@ -278,7 +281,7 @@ Agent 会自动调用行情 → 技术面 → 基本面 → 资金面 → 消息
|
|
|
278
281
|
| `search_stock_news` | 关键词搜索新闻 |
|
|
279
282
|
| `search_comprehensive_intel` | 综合情报搜索 |
|
|
280
283
|
| `get_social_sentiment` | 社交媒体情绪(A 股:东财股吧 + 雪球;美港股:Reddit / X / Polymarket) |
|
|
281
|
-
| `get_trending_sentiment` | 社交媒体热门趋势聚合(Reddit / X / Polymarket
|
|
284
|
+
| `get_trending_sentiment` | 社交媒体热门趋势聚合(Reddit / X / Polymarket) |
|
|
282
285
|
| `extract_article` | 网页正文提取 |
|
|
283
286
|
|
|
284
287
|
### 辅助
|
|
@@ -288,6 +291,7 @@ Agent 会自动调用行情 → 技术面 → 基本面 → 资金面 → 消息
|
|
|
288
291
|
| `resolve_stock_name` | 股票名称 / 拼音模糊匹配 |
|
|
289
292
|
| `check_trading_day` | 查询是否交易日 |
|
|
290
293
|
| `get_trading_days` | 获取前后 N 个交易日 |
|
|
294
|
+
| `get_trading_phase` | 查询市场当前交易时段(盘前/盘中/盘后/休市) |
|
|
291
295
|
| `diagnose_data_sources` | 诊断数据源、环境变量和市场链路 |
|
|
292
296
|
| `get_market_capabilities` | 查询各市场支持的工具边界 |
|
|
293
297
|
| `parse_stock_list` | 从自然语言、CSV 或 Markdown 解析股票列表 |
|
|
@@ -299,6 +303,9 @@ Agent 会自动调用行情 → 技术面 → 基本面 → 资金面 → 消息
|
|
|
299
303
|
| `build_watchlist_context` | 构建自选股摘要与后续工具建议 |
|
|
300
304
|
| `analyze_position_context` | 结合成本、仓位与止损止盈分析持仓 |
|
|
301
305
|
| `check_alert_rules` | 无状态检查价格、涨跌幅、异动和风险规则 |
|
|
306
|
+
| `record_signal` | 记录 AI 分析建议信号(本地 JSONL 持久化) |
|
|
307
|
+
| `evaluate_signals` | 评估到期信号(target_hit/stop_hit/timeout 结算) |
|
|
308
|
+
| `get_signal_summary` | 信号胜率汇总(按 source/symbol/status 过滤) |
|
|
302
309
|
| `render_stock_report` | 将结构化个股报告渲染为 Markdown |
|
|
303
310
|
| `render_market_report` | 将结构化市场复盘渲染为 Markdown |
|
|
304
311
|
|
|
@@ -425,23 +432,24 @@ python tools/market_regime.py detect A
|
|
|
425
432
|
```
|
|
426
433
|
stock-analysis/
|
|
427
434
|
├── pi/ # Pi Agent Extension
|
|
428
|
-
│ └── index.ts # 注册
|
|
435
|
+
│ └── index.ts # 注册 48 个工具 + 20 个 skill
|
|
429
436
|
├── hermes/ # Hermes Agent Plugin
|
|
430
437
|
│ ├── plugin.yaml # 插件清单
|
|
431
438
|
│ ├── __init__.py # register(ctx) 入口
|
|
432
439
|
│ ├── schemas.py # 工具 JSON Schema 定义
|
|
433
|
-
│ └── tools.py #
|
|
440
|
+
│ └── tools.py # 48 个 handler → subprocess 调 CLI
|
|
434
441
|
├── openclaw/ # OpenClaw Plugin
|
|
435
442
|
│ ├── openclaw.plugin.json # manifest(contracts.tools)
|
|
436
443
|
│ ├── package.json # 含 openclaw 块(pluginApi/SDK 版本)
|
|
437
|
-
│ └── index.ts # definePluginEntry + registerTool ×
|
|
444
|
+
│ └── index.ts # definePluginEntry + registerTool ×48
|
|
438
445
|
├── dsh/ # DeepSeek Harness (dsh) Plugin
|
|
439
446
|
│ ├── cordis.patch.yml # bundle patch(insert 插件入口)
|
|
440
447
|
│ ├── package.json # 含 dsh.bundle 块(bundle manifest)
|
|
441
|
-
│ └── index.ts # cordis apply(ctx) + defineTool ×
|
|
448
|
+
│ └── index.ts # cordis apply(ctx) + defineTool ×48
|
|
442
449
|
│
|
|
443
|
-
├── tools/ # 共享 Python CLI 工具(
|
|
444
|
-
│ ├── stock_data.py # 行情 / 资金流 / 新闻 / 财务
|
|
450
|
+
├── tools/ # 共享 Python CLI 工具(23 个脚本)
|
|
451
|
+
│ ├── stock_data.py # 行情 / 资金流 / 新闻 / 财务 / 短线情绪
|
|
452
|
+
│ ├── signal_tracker.py # AI 买卖建议回测闭环(本地 JSONL 存储)
|
|
445
453
|
│ ├── technical.py # 技术指标分析
|
|
446
454
|
│ ├── pattern.py # K 线形态识别
|
|
447
455
|
│ ├── screener.py # 全市场多因子筛选(含市场情绪调节,--l2 量化增强)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "stock-analysis-plugin",
|
|
3
|
-
"version": "0.1
|
|
3
|
+
"version": "0.2.1",
|
|
4
4
|
"description": "Pi Agent extension for stock analysis, screening, and strategy backtesting across A/HK/US markets",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./pi/index.ts",
|
|
@@ -39,7 +39,8 @@
|
|
|
39
39
|
"schemas/",
|
|
40
40
|
"templates/",
|
|
41
41
|
"strategies/",
|
|
42
|
-
"scripts/"
|
|
42
|
+
"scripts/",
|
|
43
|
+
"!scripts/sync-version.sh"
|
|
43
44
|
],
|
|
44
45
|
"scripts": {
|
|
45
46
|
"postinstall": "node scripts/setup-python.mjs",
|
package/pi/index.ts
CHANGED
|
@@ -63,7 +63,7 @@ export default (pi: ExtensionAPI) => {
|
|
|
63
63
|
pi.registerTool({
|
|
64
64
|
name: "get_quote",
|
|
65
65
|
description:
|
|
66
|
-
"获取股票实时行情报价(现价、涨跌幅、量比等)。支持A
|
|
66
|
+
"获取股票实时行情报价(现价、涨跌幅、量比等)。支持A股、港股、美股、日股、韩股、台股;非交易时段返回最近交易日收盘价并以 as_of/stale 标注",
|
|
67
67
|
parameters: {
|
|
68
68
|
type: "object",
|
|
69
69
|
properties: {
|
|
@@ -254,7 +254,7 @@ export default (pi: ExtensionAPI) => {
|
|
|
254
254
|
|
|
255
255
|
pi.registerTool({
|
|
256
256
|
name: "get_sector_rankings",
|
|
257
|
-
description: "获取A
|
|
257
|
+
description: "获取A股板块涨跌幅排行(含领涨股、涨跌家数等)。board_type=industry(默认)为行业板块,board_type=concept 时为概念板块排行。支持查看涨幅榜/跌幅榜/双向",
|
|
258
258
|
parameters: {
|
|
259
259
|
type: "object",
|
|
260
260
|
properties: {
|
|
@@ -267,15 +267,22 @@ export default (pi: ExtensionAPI) => {
|
|
|
267
267
|
enum: ["top", "bottom", "both"],
|
|
268
268
|
description: "top=涨幅榜(默认),bottom=跌幅榜,both=双向",
|
|
269
269
|
},
|
|
270
|
+
board_type: {
|
|
271
|
+
type: "string",
|
|
272
|
+
enum: ["industry", "concept"],
|
|
273
|
+
description: "板块类型:industry=行业(默认),concept=概念",
|
|
274
|
+
},
|
|
270
275
|
},
|
|
271
276
|
},
|
|
272
|
-
async execute(_id, { top = 10, direction = "top" }) {
|
|
277
|
+
async execute(_id, { top = 10, direction = "top", board_type = "industry" }) {
|
|
273
278
|
const result = await py("stock_data.py", [
|
|
274
279
|
"sector_rankings",
|
|
275
280
|
"--top",
|
|
276
281
|
String(top),
|
|
277
282
|
"--direction",
|
|
278
283
|
direction,
|
|
284
|
+
"--board-type",
|
|
285
|
+
board_type,
|
|
279
286
|
]);
|
|
280
287
|
return asText(result.stdout);
|
|
281
288
|
},
|
|
@@ -375,18 +382,85 @@ export default (pi: ExtensionAPI) => {
|
|
|
375
382
|
name: "get_market_stats",
|
|
376
383
|
description:
|
|
377
384
|
"获取A股市场整体统计(涨跌家数、涨停跌停数、平均涨幅、涨跌Top5、总成交额)。用于衡量市场整体情绪与温度",
|
|
385
|
+
parameters: {
|
|
386
|
+
type: "object",
|
|
387
|
+
properties: {},
|
|
388
|
+
},
|
|
389
|
+
async execute() {
|
|
390
|
+
const result = await py("stock_data.py", ["market_stats"]);
|
|
391
|
+
return asText(result.stdout);
|
|
392
|
+
},
|
|
393
|
+
});
|
|
394
|
+
|
|
395
|
+
pi.registerTool({
|
|
396
|
+
name: "get_limit_up_pool",
|
|
397
|
+
description:
|
|
398
|
+
"获取A股涨停池/涨停板复盘——当日涨停个股,含连板数、封板资金、炸板次数、首末次封板时间、所属行业。短线情绪与龙头战法核心数据",
|
|
378
399
|
parameters: {
|
|
379
400
|
type: "object",
|
|
380
401
|
properties: {
|
|
381
|
-
|
|
402
|
+
date: {
|
|
382
403
|
type: "string",
|
|
383
|
-
|
|
384
|
-
description: "市场,目前仅支持 A",
|
|
404
|
+
description: "日期(YYYYMMDD),默认当日;非交易日或未来日期自动回退到最近交易日(返回含 requested_date 与 stale 标注)",
|
|
385
405
|
},
|
|
386
406
|
},
|
|
387
407
|
},
|
|
388
|
-
async execute(_id, {
|
|
389
|
-
const result = await py("stock_data.py", [
|
|
408
|
+
async execute(_id, { date }) {
|
|
409
|
+
const result = await py("stock_data.py", [
|
|
410
|
+
"limit_up_pool",
|
|
411
|
+
...(date ? ["--date", date] : []),
|
|
412
|
+
]);
|
|
413
|
+
return asText(result.stdout);
|
|
414
|
+
},
|
|
415
|
+
});
|
|
416
|
+
|
|
417
|
+
pi.registerTool({
|
|
418
|
+
name: "get_dragon_tiger",
|
|
419
|
+
description:
|
|
420
|
+
"获取A股龙虎榜——上榜个股净买额/买入额/卖出额/上榜原因/解读,可按个股过滤",
|
|
421
|
+
parameters: {
|
|
422
|
+
type: "object",
|
|
423
|
+
properties: {
|
|
424
|
+
date: {
|
|
425
|
+
type: "string",
|
|
426
|
+
description: "日期(YYYY-MM-DD),默认当日;非交易日或未来日期自动回退到最近交易日(返回含 requested_date 与 stale 标注)",
|
|
427
|
+
},
|
|
428
|
+
symbol: {
|
|
429
|
+
type: "string",
|
|
430
|
+
description: "A股股票代码(可选,按个股过滤),如 600519",
|
|
431
|
+
},
|
|
432
|
+
top: {
|
|
433
|
+
type: "number",
|
|
434
|
+
description: "返回前N条,默认 20",
|
|
435
|
+
},
|
|
436
|
+
},
|
|
437
|
+
},
|
|
438
|
+
async execute(_id, { date, symbol, top = 20 }) {
|
|
439
|
+
const result = await py("stock_data.py", [
|
|
440
|
+
"dragon_tiger",
|
|
441
|
+
...(date ? ["--date", date] : []),
|
|
442
|
+
...(symbol ? ["--symbol", symbol] : []),
|
|
443
|
+
"--top",
|
|
444
|
+
String(top),
|
|
445
|
+
]);
|
|
446
|
+
return asText(result.stdout);
|
|
447
|
+
},
|
|
448
|
+
});
|
|
449
|
+
|
|
450
|
+
pi.registerTool({
|
|
451
|
+
name: "get_hot_stocks",
|
|
452
|
+
description: "获取A股全市场人气热搜榜(东方财富人气榜)",
|
|
453
|
+
parameters: {
|
|
454
|
+
type: "object",
|
|
455
|
+
properties: {
|
|
456
|
+
top: {
|
|
457
|
+
type: "number",
|
|
458
|
+
description: "返回前N只,默认 20",
|
|
459
|
+
},
|
|
460
|
+
},
|
|
461
|
+
},
|
|
462
|
+
async execute(_id, { top = 20 }) {
|
|
463
|
+
const result = await py("stock_data.py", ["hot_stocks", "--top", String(top)]);
|
|
390
464
|
return asText(result.stdout);
|
|
391
465
|
},
|
|
392
466
|
});
|
|
@@ -650,6 +724,27 @@ export default (pi: ExtensionAPI) => {
|
|
|
650
724
|
},
|
|
651
725
|
});
|
|
652
726
|
|
|
727
|
+
pi.registerTool({
|
|
728
|
+
name: "get_trading_phase",
|
|
729
|
+
description:
|
|
730
|
+
"查询某市场当前交易时段(盘前/早盘/午间休市/午盘/交易中/盘后/休市),用于正确解读实时行情的盘中语义。支持CN/HK/US/JP/KR/TW",
|
|
731
|
+
parameters: {
|
|
732
|
+
type: "object",
|
|
733
|
+
properties: {
|
|
734
|
+
market: {
|
|
735
|
+
type: "string",
|
|
736
|
+
enum: ["CN", "HK", "US", "JP", "KR", "TW"],
|
|
737
|
+
description: "市场",
|
|
738
|
+
},
|
|
739
|
+
},
|
|
740
|
+
required: ["market"],
|
|
741
|
+
},
|
|
742
|
+
async execute(_id, { market }) {
|
|
743
|
+
const result = await py("trading_calendar.py", ["phase", market]);
|
|
744
|
+
return asText(result.stdout);
|
|
745
|
+
},
|
|
746
|
+
});
|
|
747
|
+
|
|
653
748
|
// --- Standalone MA Calculator ---
|
|
654
749
|
|
|
655
750
|
pi.registerTool({
|
|
@@ -810,7 +905,7 @@ export default (pi: ExtensionAPI) => {
|
|
|
810
905
|
pi.registerTool({
|
|
811
906
|
name: "get_trending_sentiment",
|
|
812
907
|
description:
|
|
813
|
-
"获取社交媒体热门趋势(Reddit/X/Polymarket
|
|
908
|
+
"获取社交媒体热门趋势(Reddit/X/Polymarket热门股票讨论)。适用于发现市场热点;查个股情绪用 get_social_sentiment",
|
|
814
909
|
parameters: {
|
|
815
910
|
type: "object",
|
|
816
911
|
properties: {},
|
|
@@ -1044,19 +1139,12 @@ export default (pi: ExtensionAPI) => {
|
|
|
1044
1139
|
type: "object",
|
|
1045
1140
|
properties: {
|
|
1046
1141
|
report: { type: "object", description: "结构化市场复盘" },
|
|
1047
|
-
template: { type: "string", enum: ["full"], description: "模板类型,默认 full" },
|
|
1048
1142
|
},
|
|
1049
1143
|
required: ["report"],
|
|
1050
1144
|
},
|
|
1051
|
-
async execute(_id, { report
|
|
1145
|
+
async execute(_id, { report }) {
|
|
1052
1146
|
const b64 = Buffer.from(JSON.stringify(report), "utf-8").toString("base64");
|
|
1053
|
-
const result = await py("report_renderer.py", [
|
|
1054
|
-
"market",
|
|
1055
|
-
"--template",
|
|
1056
|
-
template,
|
|
1057
|
-
"--input-b64",
|
|
1058
|
-
b64,
|
|
1059
|
-
]);
|
|
1147
|
+
const result = await py("report_renderer.py", ["market", "--input-b64", b64]);
|
|
1060
1148
|
return asText(result.stdout);
|
|
1061
1149
|
},
|
|
1062
1150
|
});
|
|
@@ -1150,6 +1238,93 @@ export default (pi: ExtensionAPI) => {
|
|
|
1150
1238
|
},
|
|
1151
1239
|
});
|
|
1152
1240
|
|
|
1241
|
+
pi.registerTool({
|
|
1242
|
+
name: "record_signal",
|
|
1243
|
+
description:
|
|
1244
|
+
"记录一条 AI 分析建议信号(方向/入场价/目标价/止损价/持有期限),供后续胜率评估。信号持久化在本地 JSONL($STOCK_SIGNAL_STORE 或 ~/.stock-analysis/signals.jsonl),宿主 Agent 自行决定何时 record/evaluate",
|
|
1245
|
+
parameters: {
|
|
1246
|
+
type: "object",
|
|
1247
|
+
properties: {
|
|
1248
|
+
symbol: { type: "string", description: "股票代码(A股如600519,美股如AAPL,港股如00700.HK)" },
|
|
1249
|
+
direction: {
|
|
1250
|
+
type: "string",
|
|
1251
|
+
enum: ["buy", "sell"],
|
|
1252
|
+
description: "建议方向",
|
|
1253
|
+
},
|
|
1254
|
+
entry_price: { type: "number", description: "入场价(可选)" },
|
|
1255
|
+
target_price: { type: "number", description: "目标价(可选)" },
|
|
1256
|
+
stop_price: { type: "number", description: "止损价(可选)" },
|
|
1257
|
+
horizon_days: { type: "number", description: "持有期限(交易日),默认 10" },
|
|
1258
|
+
source: { type: "string", description: "信号来源(如触发该建议的 skill 名)" },
|
|
1259
|
+
note: { type: "string", description: "备注(可选)" },
|
|
1260
|
+
},
|
|
1261
|
+
required: ["symbol", "direction"],
|
|
1262
|
+
},
|
|
1263
|
+
async execute(_id, { symbol, direction, entry_price, target_price, stop_price, horizon_days = 10, source, note }) {
|
|
1264
|
+
const result = await py("signal_tracker.py", [
|
|
1265
|
+
"record",
|
|
1266
|
+
symbol,
|
|
1267
|
+
"--direction",
|
|
1268
|
+
direction,
|
|
1269
|
+
...(entry_price !== undefined ? ["--entry-price", String(entry_price)] : []),
|
|
1270
|
+
...(target_price !== undefined ? ["--target-price", String(target_price)] : []),
|
|
1271
|
+
...(stop_price !== undefined ? ["--stop-price", String(stop_price)] : []),
|
|
1272
|
+
"--horizon-days",
|
|
1273
|
+
String(horizon_days),
|
|
1274
|
+
...(source ? ["--source", source] : []),
|
|
1275
|
+
...(note ? ["--note", note] : []),
|
|
1276
|
+
]);
|
|
1277
|
+
return asText(result.stdout);
|
|
1278
|
+
},
|
|
1279
|
+
});
|
|
1280
|
+
|
|
1281
|
+
pi.registerTool({
|
|
1282
|
+
name: "evaluate_signals",
|
|
1283
|
+
description:
|
|
1284
|
+
"评估到期信号:拉取记录日之后的日K,判定 target_hit/stop_hit/timeout 并计算收益,回写存储。记录建议用 record_signal,胜率复盘用 get_signal_summary",
|
|
1285
|
+
parameters: {
|
|
1286
|
+
type: "object",
|
|
1287
|
+
properties: {
|
|
1288
|
+
symbol: { type: "string", description: "股票代码(可选,只评估该股的信号)" },
|
|
1289
|
+
},
|
|
1290
|
+
},
|
|
1291
|
+
async execute(_id, { symbol }) {
|
|
1292
|
+
const result = await py("signal_tracker.py", [
|
|
1293
|
+
"evaluate",
|
|
1294
|
+
...(symbol ? ["--symbol", symbol] : []),
|
|
1295
|
+
]);
|
|
1296
|
+
return asText(result.stdout);
|
|
1297
|
+
},
|
|
1298
|
+
});
|
|
1299
|
+
|
|
1300
|
+
pi.registerTool({
|
|
1301
|
+
name: "get_signal_summary",
|
|
1302
|
+
description:
|
|
1303
|
+
"信号胜率汇总(可按 source/symbol/status 过滤):胜率、平均收益、结果分布与明细",
|
|
1304
|
+
parameters: {
|
|
1305
|
+
type: "object",
|
|
1306
|
+
properties: {
|
|
1307
|
+
source: { type: "string", description: "按信号来源过滤(可选)" },
|
|
1308
|
+
symbol: { type: "string", description: "按股票代码过滤(可选)" },
|
|
1309
|
+
status: {
|
|
1310
|
+
type: "string",
|
|
1311
|
+
enum: ["open", "closed", "all"],
|
|
1312
|
+
description: "open=未结算,closed=已结算,all=全部(默认)",
|
|
1313
|
+
},
|
|
1314
|
+
},
|
|
1315
|
+
},
|
|
1316
|
+
async execute(_id, { source, symbol, status = "all" }) {
|
|
1317
|
+
const result = await py("signal_tracker.py", [
|
|
1318
|
+
"summary",
|
|
1319
|
+
...(source ? ["--source", source] : []),
|
|
1320
|
+
...(symbol ? ["--symbol", symbol] : []),
|
|
1321
|
+
"--status",
|
|
1322
|
+
status,
|
|
1323
|
+
]);
|
|
1324
|
+
return asText(result.stdout);
|
|
1325
|
+
},
|
|
1326
|
+
});
|
|
1327
|
+
|
|
1153
1328
|
pi.registerTool({
|
|
1154
1329
|
name: "parse_stock_list",
|
|
1155
1330
|
description:
|
|
@@ -24,6 +24,8 @@ python3 scripts/gather.py <symbol>
|
|
|
24
24
|
同时用 resolve_stock_sectors 确认个股所属板块,再用 get_sector_constituents 拉取同板块个股列表——后续「龙头 vs 跟风」的强弱对比都在这个板块池内进行。
|
|
25
25
|
获取不到板块池或池内个股同期表现时,只评估候选股的强势特征,不给出“龙头/龙一”结论。
|
|
26
26
|
|
|
27
|
+
短线情绪与资金席位补充:`get_limit_up_pool`(涨停池的连板数、首末次封板时间、封板资金、炸板次数)用于确认板块内个股的高度与封板质量;`get_dragon_tiger`(龙虎榜)用于查看上榜个股的席位净买额与上榜原因。两者在非交易日或未来日期会自动回退到最近交易日的数据(返回含 `requested_date` 与 `stale: true` 标注),解读时以 `date` 字段的实际数据日期为准,不得把回退数据当成请求日当日数据。
|
|
28
|
+
|
|
27
29
|
### 2. 相对强弱验证
|
|
28
30
|
|
|
29
31
|
在同一截止时间比较板块候选股:
|
|
@@ -33,7 +35,7 @@ python3 scripts/gather.py <symbol>
|
|
|
33
35
|
- 上涨日与下跌日的成交量结构
|
|
34
36
|
- 板块上涨时是否领涨,板块分歧时是否保持相对强度
|
|
35
37
|
|
|
36
|
-
|
|
38
|
+
连板数、封板资金、炸板次数和首末次封板时间用 `get_limit_up_pool` 获取;竞价强弱和分时承接仍需盘口或分钟数据。当前数据无法验证时明确标注缺失,不得据此评定龙头。
|
|
37
39
|
|
|
38
40
|
### 3. 判断阶段与计划
|
|
39
41
|
|
|
@@ -17,6 +17,8 @@ description: 市场情绪周期:用市场宽度、涨跌停、成交额和热
|
|
|
17
17
|
python3 scripts/gather.py [A|HK|US]
|
|
18
18
|
```
|
|
19
19
|
|
|
20
|
+
A 股情绪另有两个直接数据源:`get_limit_up_pool`(涨停池:连板梯队高度、炸板率、封板资金)与 `get_hot_stocks`(全市场人气热搜榜)。`get_limit_up_pool` 在非交易日或未来日期会回退到最近交易日数据(返回含 `requested_date` 与 `stale: true`),情绪判断以其 `date` 字段的实际数据日期为准。
|
|
21
|
+
|
|
20
22
|
### 2. 情绪指标
|
|
21
23
|
|
|
22
24
|
- 市场温度和策略姿态
|
|
@@ -20,7 +20,8 @@ gather 工具返回:
|
|
|
20
20
|
- `financials` — 基本面数据(实质受益判断)
|
|
21
21
|
- `news` — 近期新闻(题材催化来源)
|
|
22
22
|
- `stock_info` — 公司基本信息(行业、业务)
|
|
23
|
-
- `sector_rankings` —
|
|
23
|
+
- `sector_rankings` — 板块排名(核心数据源);`get_sector_rankings` 传 `board_type=concept` 时为概念板块排行,热点题材以概念口径为主
|
|
24
|
+
- `hot_stocks` — 全市场人气热搜榜(`get_hot_stocks`,东方财富人气榜),辅助判断题材热度
|
|
24
25
|
|
|
25
26
|
评估扩散度前,必须获取板块成分股及其当日表现;只有板块排名时,仅可判断当日相对强弱,不判断扩散度或持续性。
|
|
26
27
|
|
|
@@ -30,6 +30,8 @@ python3 scripts/gather.py <symbol>
|
|
|
30
30
|
|
|
31
31
|
解析返回的 JSON 数据。如果某个字段为 `null`,表示该数据获取失败,基于可用数据继续分析。
|
|
32
32
|
|
|
33
|
+
解读实时行情前先调 `get_trading_phase` 确认该市场当前盘中阶段(盘前/早盘/午间休市/午盘/交易中/盘后/休市),避免把休市时的静态快照当作盘中信号解读。
|
|
34
|
+
|
|
33
35
|
### 第二步:综合研判
|
|
34
36
|
|
|
35
37
|
根据获取的数据进行多维度分析:
|
|
@@ -63,11 +65,17 @@ python3 scripts/gather.py <symbol>
|
|
|
63
65
|
|
|
64
66
|
### 第三步:渲染研报
|
|
65
67
|
|
|
66
|
-
1. 按 [报告 schema](
|
|
68
|
+
1. 按 [报告 schema](../../schemas/report_schema.json) 构建结构化报告。
|
|
67
69
|
2. 每个结论只使用成功返回的数据;缺失维度在 `risk_warning` 中说明影响。
|
|
68
70
|
3. 调用 `render_stock_report`:快速问答用 `brief`,完整研判用 `full`。
|
|
69
71
|
4. 输出渲染后的 Markdown;只在用户要求机器可读数据时附加结构化 JSON。
|
|
70
72
|
|
|
73
|
+
## 信号跟踪闭环
|
|
74
|
+
|
|
75
|
+
- 给出明确买卖建议(方向 + 入场价/目标价/止损价)时,调 `record_signal` 存档,`source` 填触发该建议的 skill 名(如 `stock-analysis`、`dragon-head`)。
|
|
76
|
+
- 后续会话用 `evaluate_signals` 结算到期信号(target_hit/stop_hit/timeout 并回写收益),用 `get_signal_summary` 复盘胜率(可按 source/symbol/status 过滤)。
|
|
77
|
+
- 信号持久化在本地 JSONL(`$STOCK_SIGNAL_STORE` 或 `~/.stock-analysis/signals.jsonl`);是否记录由宿主 Agent 决定,不阻塞报告输出。
|
|
78
|
+
|
|
71
79
|
## 注意事项
|
|
72
80
|
- 始终提供风险提示
|
|
73
81
|
- 不做绝对化的涨跌预测
|
package/tools/alert_rules.py
CHANGED
|
@@ -26,19 +26,6 @@ RULE_TYPES = {
|
|
|
26
26
|
}
|
|
27
27
|
|
|
28
28
|
|
|
29
|
-
def _severity_for(rule_type: str) -> str:
|
|
30
|
-
return {
|
|
31
|
-
"risk_veto": "high",
|
|
32
|
-
"risk_level_at_least": "high",
|
|
33
|
-
"anomaly": "medium",
|
|
34
|
-
"price_below": "medium",
|
|
35
|
-
"price_above": "medium",
|
|
36
|
-
"change_pct_above": "medium",
|
|
37
|
-
"change_pct_below": "medium",
|
|
38
|
-
"volume_ratio_above": "medium",
|
|
39
|
-
}.get(rule_type, "low")
|
|
40
|
-
|
|
41
|
-
|
|
42
29
|
def _check_rule(rule: dict, quote: dict, tech: dict, anom: dict, risk: dict) -> dict | None:
|
|
43
30
|
rtype = rule.get("type")
|
|
44
31
|
value = rule.get("value")
|
|
@@ -55,7 +42,7 @@ def _check_rule(rule: dict, quote: dict, tech: dict, anom: dict, risk: dict) ->
|
|
|
55
42
|
"triggered": True,
|
|
56
43
|
"value": value,
|
|
57
44
|
"actual": price,
|
|
58
|
-
"severity":
|
|
45
|
+
"severity": "medium",
|
|
59
46
|
"message": f"现价 {price} 跌破 {value}",
|
|
60
47
|
}
|
|
61
48
|
elif rtype == "price_above":
|
|
@@ -65,7 +52,7 @@ def _check_rule(rule: dict, quote: dict, tech: dict, anom: dict, risk: dict) ->
|
|
|
65
52
|
"triggered": True,
|
|
66
53
|
"value": value,
|
|
67
54
|
"actual": price,
|
|
68
|
-
"severity":
|
|
55
|
+
"severity": "medium",
|
|
69
56
|
"message": f"现价 {price} 突破 {value}",
|
|
70
57
|
}
|
|
71
58
|
elif rtype == "change_pct_above":
|
|
@@ -75,7 +62,7 @@ def _check_rule(rule: dict, quote: dict, tech: dict, anom: dict, risk: dict) ->
|
|
|
75
62
|
"triggered": True,
|
|
76
63
|
"value": value,
|
|
77
64
|
"actual": change_pct,
|
|
78
|
-
"severity":
|
|
65
|
+
"severity": "medium",
|
|
79
66
|
"message": f"涨幅 {change_pct}% 超过 {value}%",
|
|
80
67
|
}
|
|
81
68
|
elif rtype == "change_pct_below":
|
|
@@ -85,7 +72,7 @@ def _check_rule(rule: dict, quote: dict, tech: dict, anom: dict, risk: dict) ->
|
|
|
85
72
|
"triggered": True,
|
|
86
73
|
"value": value,
|
|
87
74
|
"actual": change_pct,
|
|
88
|
-
"severity":
|
|
75
|
+
"severity": "medium",
|
|
89
76
|
"message": f"跌幅 {change_pct}% 低于 {value}%",
|
|
90
77
|
}
|
|
91
78
|
elif rtype == "volume_ratio_above":
|
|
@@ -97,7 +84,7 @@ def _check_rule(rule: dict, quote: dict, tech: dict, anom: dict, risk: dict) ->
|
|
|
97
84
|
"triggered": True,
|
|
98
85
|
"value": value,
|
|
99
86
|
"actual": ratio,
|
|
100
|
-
"severity":
|
|
87
|
+
"severity": "medium",
|
|
101
88
|
"message": f"量比 {ratio} 超过 {value}",
|
|
102
89
|
}
|
|
103
90
|
elif rtype == "anomaly":
|
package/tools/backtest.py
CHANGED
|
@@ -482,7 +482,7 @@ def diagnose_advanced(metrics: dict, trades: list, equity_curve: list, strategy:
|
|
|
482
482
|
trade_count_quality = "sufficient"
|
|
483
483
|
|
|
484
484
|
# main_failure_reason — pick the most impactful weakness
|
|
485
|
-
sell_trades = [t for t in trades if t.get("
|
|
485
|
+
sell_trades = [t for t in trades if t.get("type") == "sell"]
|
|
486
486
|
stop_hits = sum(
|
|
487
487
|
1
|
|
488
488
|
for t in sell_trades
|
|
@@ -509,9 +509,9 @@ def diagnose_advanced(metrics: dict, trades: list, equity_curve: list, strategy:
|
|
|
509
509
|
if len(equity_curve) >= 3:
|
|
510
510
|
# split into halves, compare
|
|
511
511
|
mid = len(equity_curve) // 2
|
|
512
|
-
first = equity_curve[mid][
|
|
513
|
-
last = equity_curve[-1][
|
|
514
|
-
start_v = equity_curve[0][
|
|
512
|
+
first = equity_curve[mid]["equity"]
|
|
513
|
+
last = equity_curve[-1]["equity"]
|
|
514
|
+
start_v = equity_curve[0]["equity"]
|
|
515
515
|
first_half = (first - start_v) / start_v if start_v else 0
|
|
516
516
|
second_half = (last - first) / first if first else 0
|
|
517
517
|
if first_half > 0.05 and second_half > 0.05:
|
package/tools/capabilities.py
CHANGED
|
@@ -39,6 +39,9 @@ TOOL_MATRIX = {
|
|
|
39
39
|
"get_market_stats": {"markets": ["A"], "reason": "A-share only"},
|
|
40
40
|
"get_fundamental_context": {"markets": ["A"], "reason": "A-share only"},
|
|
41
41
|
"resolve_stock_name": {"markets": ["A"], "reason": "A-share name/pinyin index only"},
|
|
42
|
+
"get_limit_up_pool": {"markets": ["A"], "reason": "A-share only"},
|
|
43
|
+
"get_dragon_tiger": {"markets": ["A"], "reason": "A-share only"},
|
|
44
|
+
"get_hot_stocks": {"markets": ["A"], "reason": "A-share only"},
|
|
42
45
|
"get_social_sentiment": {
|
|
43
46
|
"markets": ["A", "HK", "US"],
|
|
44
47
|
"reason": "A-share uses Eastmoney/Xueqiu; HK/US require SENTIMENT_API_KEY",
|
|
@@ -52,6 +55,11 @@ TOOL_MATRIX = {
|
|
|
52
55
|
"search_comprehensive_intel": {"markets": ALL_MARKETS, "reason": None},
|
|
53
56
|
"extract_article": {"markets": ALL_MARKETS, "reason": None},
|
|
54
57
|
"screen_risk": {"markets": ["A"], "reason": "A-share only"},
|
|
58
|
+
# trading phase (session tables) + signal tracking (local JSONL store)
|
|
59
|
+
"get_trading_phase": {"markets": ALL_MARKETS, "reason": None},
|
|
60
|
+
"record_signal": {"markets": ALL_MARKETS, "reason": None},
|
|
61
|
+
"evaluate_signals": {"markets": ALL_MARKETS, "reason": None},
|
|
62
|
+
"get_signal_summary": {"markets": ALL_MARKETS, "reason": None},
|
|
55
63
|
}
|
|
56
64
|
|
|
57
65
|
|