stock-analysis-plugin 0.2.1 → 0.2.3
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/LICENSE +21 -0
- package/README.md +33 -11
- package/package.json +5 -5
- package/pi/index.ts +86 -8
- package/scripts/ci-resolve-llm-host.mjs +29 -0
- package/scripts/setup-python.mjs +7 -9
- package/skills/hot-theme/SKILL.md +3 -2
- package/skills/stock-screener/SKILL.md +1 -1
- package/skills/strategy-backtest/SKILL.md +9 -5
- package/strategies/examples/bottom_volume.yaml +5 -0
- package/strategies/examples/box_oscillation.yaml +5 -0
- package/strategies/examples/bull_trend.yaml +11 -3
- package/strategies/examples/dragon_head.yaml +4 -2
- package/strategies/examples/emotion_cycle.yaml +5 -0
- package/strategies/examples/ma_crossover.yaml +10 -3
- package/strategies/examples/rsi_oversold.yaml +5 -0
- package/strategies/examples/shrink_pullback.yaml +7 -1
- package/strategies/examples/volume_breakout.yaml +7 -1
- package/tools/_subproc.py +49 -0
- package/tools/alert_rules.py +19 -9
- package/tools/anomaly_detect.py +24 -35
- package/tools/backtest.py +180 -100
- package/tools/capabilities.py +4 -5
- package/tools/diagnostics.py +6 -6
- package/tools/gather.py +13 -9
- package/tools/import_parser.py +2 -5
- package/tools/market_regime.py +27 -35
- package/tools/market_review.py +56 -9
- package/tools/name_resolver.py +2 -5
- package/tools/pattern.py +2 -5
- package/tools/position_context.py +2 -5
- package/tools/report_renderer.py +10 -6
- package/tools/requirements.txt +2 -1
- package/tools/risk_screening.py +29 -23
- package/tools/screener.py +26 -16
- package/tools/search_intel.py +5 -13
- package/tools/signal_tracker.py +2 -6
- package/tools/stock_data.py +393 -100
- package/tools/technical.py +136 -40
- package/tools/trading_calendar.py +78 -18
- package/tools/volume_analysis.py +2 -5
- package/tools/watchlist.py +2 -5
- package/tools/watchlist_context.py +2 -5
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Weaxs
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -24,6 +24,7 @@ A 股 / 港股 / 美股 / 日股 / 韩股 / 台股综合分析、多因子选股
|
|
|
24
24
|
- [策略回测 DSL](#策略回测-dsl)
|
|
25
25
|
- [市场路由规则](#市场路由规则)
|
|
26
26
|
- [独立 CLI 使用](#独立-cli-使用)
|
|
27
|
+
- [CI 真实宿主测试](#ci-真实宿主测试)
|
|
27
28
|
- [项目结构](#项目结构)
|
|
28
29
|
- [致谢](#致谢)
|
|
29
30
|
- [常见问题](#常见问题)
|
|
@@ -31,7 +32,7 @@ A 股 / 港股 / 美股 / 日股 / 韩股 / 台股综合分析、多因子选股
|
|
|
31
32
|
|
|
32
33
|
## 功能概览
|
|
33
34
|
|
|
34
|
-
- **
|
|
35
|
+
- **51 个工具** — 行情数据、技术分析、K 线形态、资金流向、财务指标、新闻舆情、风险筛查、市场状态等
|
|
35
36
|
- **20 个 Skills** — 综合分析、全市场选股、策略回测 + 17 个策略方法论(缠论、波浪、龙头、情绪周期等)
|
|
36
37
|
- **策略回测引擎** — YAML DSL 定义策略,参数化条件组合,自动诊断,按需进行有限轮参数优化
|
|
37
38
|
- **多数据源 Failover** — 11 个数据源自动容灾切换(akshare / tushare / efinance / 腾讯行情 / 新浪行情 / pytdx / baostock / yfinance / finnhub / longbridge / alphavantage),A 股链路带粘性优选(最近成功的数据源下次优先尝试)
|
|
@@ -92,7 +93,7 @@ register(ctx)
|
|
|
92
93
|
openclaw plugins install clawhub:@weaxs/openclaw-stock-analysis
|
|
93
94
|
```
|
|
94
95
|
|
|
95
|
-
OpenClaw Gateway 启动后自动加载并注册
|
|
96
|
+
OpenClaw Gateway 启动后自动加载并注册 51 个 tool。安装时 postinstall 会自动建 `.venv` 并装好 Python 依赖(前提:本机有 `python3 >= 3.10`)。
|
|
96
97
|
|
|
97
98
|
详见 [OpenClaw 接入指南](docs/openclaw-integration.md),或 plugin 自身说明 [`openclaw/README.md`](openclaw/README.md)。
|
|
98
99
|
|
|
@@ -103,7 +104,7 @@ dsh plugin --profile <你的profile> add @weaxs/dsh-stock-analysis
|
|
|
103
104
|
dsh --profile <你的profile>
|
|
104
105
|
```
|
|
105
106
|
|
|
106
|
-
作为 dsh bundle 安装:`dsh plugin add` 会把 `cordis.patch.yml` 叠加进 profile 组合,注册
|
|
107
|
+
作为 dsh bundle 安装:`dsh plugin add` 会把 `cordis.patch.yml` 叠加进 profile 组合,注册 51 个 tool + 20 个 skill。postinstall 自动建 `.venv`(pnpm 需在 profile 的 `pnpm-workspace.yaml` 里给本包配 `allowBuilds`,否则回退系统 `python3`)。
|
|
107
108
|
|
|
108
109
|
详见 [`dsh/README.md`](dsh/README.md)。
|
|
109
110
|
|
|
@@ -236,7 +237,7 @@ Agent 会自动调用行情 → 技术面 → 基本面 → 资金面 → 消息
|
|
|
236
237
|
| 工具 | 说明 |
|
|
237
238
|
|------|------|
|
|
238
239
|
| `get_kline` | K 线数据(OHLCV),支持日/周/月线 |
|
|
239
|
-
| `get_quote` | 实时行情快照(非交易时段返回最近交易日收盘价并以 as_of/stale
|
|
240
|
+
| `get_quote` | 实时行情快照(非交易时段返回最近交易日收盘价并以 as_of/stale 标注;ETF 的 premium_discount_rate 为正=溢价、负=折价) |
|
|
240
241
|
| `get_capital_flow` | 资金流向(仅 A 股) |
|
|
241
242
|
| `get_news` | 个股相关新闻 |
|
|
242
243
|
| `get_financials` | 财务指标 |
|
|
@@ -249,14 +250,16 @@ Agent 会自动调用行情 → 技术面 → 基本面 → 资金面 → 消息
|
|
|
249
250
|
| `get_market_stats` | 市场统计(涨跌家数、涨停等) |
|
|
250
251
|
| `get_limit_up_pool` | 涨停池/涨停板复盘(连板数、封板资金、炸板次数等,仅 A 股;非交易日自动回退到最近交易日并以 requested_date/stale 标注) |
|
|
251
252
|
| `get_dragon_tiger` | 龙虎榜(净买额/上榜原因/解读,仅 A 股;非交易日自动回退到最近交易日并以 requested_date/stale 标注) |
|
|
252
|
-
| `get_hot_stocks` |
|
|
253
|
+
| `get_hot_stocks` | 全市场人气热搜榜(东财→百度,仅 A 股) |
|
|
254
|
+
| `get_margin_trading` | 个股融资融券明细(融资余额/融资买入额/融券余量等,沪深交易所官方数据,仅 A 股两融标的;金额单位为元,short_*_shares 单位为股) |
|
|
255
|
+
| `get_northbound_flow` | 北向资金市场级净买入序列(东财沪深港通历史数据;2024-08-16 起交易所停止披露日度净买额,仅 2024-08 之前历史数据可查,仅 A 股) |
|
|
253
256
|
| `get_fundamental_context` | 基本面综合上下文 |
|
|
254
257
|
|
|
255
258
|
### 分析计算
|
|
256
259
|
|
|
257
260
|
| 工具 | 说明 |
|
|
258
261
|
|------|------|
|
|
259
|
-
| `get_technical_analysis` | 全面技术指标分析(MA/MACD/RSI/BOLL/KDJ) |
|
|
262
|
+
| `get_technical_analysis` | 全面技术指标分析(MA/MACD/RSI/BOLL/KDJ;多周期共振时 resonance.direction ∈ aligned_bullish/aligned_bearish/divergent) |
|
|
260
263
|
| `analyze_pattern` | K 线形态识别 |
|
|
261
264
|
| `calculate_ma` | 多周期均线计算 |
|
|
262
265
|
| `get_volume_analysis` | 量价分析 |
|
|
@@ -272,6 +275,7 @@ Agent 会自动调用行情 → 技术面 → 基本面 → 资金面 → 消息
|
|
|
272
275
|
| `run_backtest` | YAML 策略回测 |
|
|
273
276
|
| `detect_market_regime` | 市场状态检测(牛/熊/震荡) |
|
|
274
277
|
| `get_market_review` | 市场日度复盘数据 |
|
|
278
|
+
| `get_review_history` | 复盘归档历史(最近 N 条,最新在前,用于纵向对比) |
|
|
275
279
|
| `run_watchlist_analysis` | 批量自选股分析 |
|
|
276
280
|
|
|
277
281
|
### 搜索与舆情
|
|
@@ -307,7 +311,7 @@ Agent 会自动调用行情 → 技术面 → 基本面 → 资金面 → 消息
|
|
|
307
311
|
| `evaluate_signals` | 评估到期信号(target_hit/stop_hit/timeout 结算) |
|
|
308
312
|
| `get_signal_summary` | 信号胜率汇总(按 source/symbol/status 过滤) |
|
|
309
313
|
| `render_stock_report` | 将结构化个股报告渲染为 Markdown |
|
|
310
|
-
| `render_market_report` | 将结构化市场复盘渲染为 Markdown |
|
|
314
|
+
| `render_market_report` | 将结构化市场复盘渲染为 Markdown(save=true 时归档到本地 JSONL) |
|
|
311
315
|
|
|
312
316
|
## 策略回测 DSL
|
|
313
317
|
|
|
@@ -351,6 +355,12 @@ position:
|
|
|
351
355
|
max_positions: 1
|
|
352
356
|
```
|
|
353
357
|
|
|
358
|
+
其他可用键:
|
|
359
|
+
|
|
360
|
+
- `exit.trailing_stop`:移动止损,价格自持仓期间最高收盘价回撤达到该比例即卖出(如 `0.08` = 峰值回撤 8% 触发);与 `stop_loss` 同时设置时先判固定止损。
|
|
361
|
+
- `benchmark`(顶层):基准对比标的代码(如 `"sh000300"` 沪深300;指数代码必须带 sh/sz 交易所前缀,裸 6 位数字会被当作个股),设置后回测结果附带 `benchmark` 块(基准买入持有收益与 `excess_return` 超额收益)。
|
|
362
|
+
- `simulation`(顶层):交易成本。`slippage`(滑点,买卖双边,默认 0.001)、`commission`(佣金,买卖双边,默认 0.0015)、`stamp_tax`(印花税,仅卖出收取,默认 0;A股为 0.0005,各市场税率不同且会调整,按当下实际费率填写)。费率均须在 [0, 1) 区间,越界报错。回测结果附带 `costs` 块(实际生效费率与实付费用合计 `commission_paid`/`stamp_tax_paid`)。
|
|
363
|
+
|
|
354
364
|
### 可用指标
|
|
355
365
|
|
|
356
366
|
| 指标 | 说明 | 需要 period |
|
|
@@ -427,25 +437,37 @@ python tools/risk_screening.py screen 600519
|
|
|
427
437
|
python tools/market_regime.py detect A
|
|
428
438
|
```
|
|
429
439
|
|
|
440
|
+
## CI 真实宿主测试
|
|
441
|
+
|
|
442
|
+
GitHub Actions 的 `e2e-host` 使用 Pi、Hermes、OpenClaw、dsh 的真实运行时执行工具调用。在仓库 **Settings → Secrets and variables → Actions** 中配置以下三项,所有 E2E 共用:
|
|
443
|
+
|
|
444
|
+
| 名称 | 存放位置 | 内容 |
|
|
445
|
+
|---|---|---|
|
|
446
|
+
| `OPENAI_BASE_URL` | Variable 或 Secret | OpenAI 兼容的 API base URL,包含服务商要求的路径(例如 `/v1`) |
|
|
447
|
+
| `OPENAI_API_KEY` | Secret | 对应的 API key |
|
|
448
|
+
| `OPENAI_MODEL` | Variable 或 Secret | 支持 tool calling 的模型 ID |
|
|
449
|
+
|
|
450
|
+
`e2e-llm` 也使用这三项配置;同仓库 PR 和主分支推送会运行,fork PR 不读取 API key。`e2e-host` 缺少任一项时会失败。URL 和 model 同时存在于 Variable 与 Secret 时,优先使用 Secret。
|
|
451
|
+
|
|
430
452
|
## 项目结构
|
|
431
453
|
|
|
432
454
|
```
|
|
433
455
|
stock-analysis/
|
|
434
456
|
├── pi/ # Pi Agent Extension
|
|
435
|
-
│ └── index.ts # 注册
|
|
457
|
+
│ └── index.ts # 注册 51 个工具 + 20 个 skill
|
|
436
458
|
├── hermes/ # Hermes Agent Plugin
|
|
437
459
|
│ ├── plugin.yaml # 插件清单
|
|
438
460
|
│ ├── __init__.py # register(ctx) 入口
|
|
439
461
|
│ ├── schemas.py # 工具 JSON Schema 定义
|
|
440
|
-
│ └── tools.py #
|
|
462
|
+
│ └── tools.py # 51 个 handler → subprocess 调 CLI
|
|
441
463
|
├── openclaw/ # OpenClaw Plugin
|
|
442
464
|
│ ├── openclaw.plugin.json # manifest(contracts.tools)
|
|
443
465
|
│ ├── package.json # 含 openclaw 块(pluginApi/SDK 版本)
|
|
444
|
-
│ └── index.ts # definePluginEntry + registerTool ×
|
|
466
|
+
│ └── index.ts # definePluginEntry + registerTool ×51
|
|
445
467
|
├── dsh/ # DeepSeek Harness (dsh) Plugin
|
|
446
468
|
│ ├── cordis.patch.yml # bundle patch(insert 插件入口)
|
|
447
469
|
│ ├── package.json # 含 dsh.bundle 块(bundle manifest)
|
|
448
|
-
│ └── index.ts # cordis apply(ctx) + defineTool ×
|
|
470
|
+
│ └── index.ts # cordis apply(ctx) + defineTool ×51
|
|
449
471
|
│
|
|
450
472
|
├── tools/ # 共享 Python CLI 工具(23 个脚本)
|
|
451
473
|
│ ├── stock_data.py # 行情 / 资金流 / 新闻 / 财务 / 短线情绪
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "stock-analysis-plugin",
|
|
3
|
-
"version": "0.2.
|
|
4
|
-
"description": "Pi Agent extension for stock analysis, screening, and strategy backtesting across A/HK/US markets",
|
|
3
|
+
"version": "0.2.3",
|
|
4
|
+
"description": "Pi Agent extension for stock analysis, screening, and strategy backtesting across A/HK/US/JP/KR/TW markets",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./pi/index.ts",
|
|
7
7
|
"pi": {
|
|
@@ -75,9 +75,9 @@
|
|
|
75
75
|
},
|
|
76
76
|
"license": "MIT",
|
|
77
77
|
"devDependencies": {
|
|
78
|
-
"@deepseek-ai/cordis": "
|
|
79
|
-
"@deepseek-ai/dsh-skill": "
|
|
80
|
-
"@deepseek-ai/dsh-tools": "
|
|
78
|
+
"@deepseek-ai/cordis": "4.0.4",
|
|
79
|
+
"@deepseek-ai/dsh-skill": "0.2.0-rc.2",
|
|
80
|
+
"@deepseek-ai/dsh-tools": "0.2.0-rc.2",
|
|
81
81
|
"@types/node": "^22.0.0",
|
|
82
82
|
"esbuild": "^0.28.0",
|
|
83
83
|
"jiti": "^2.7.0",
|
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股、港股、美股、日股、韩股、台股;非交易时段返回最近交易日收盘价并以 as_of/stale
|
|
66
|
+
"获取股票实时行情报价(现价、涨跌幅、量比等)。支持A股、港股、美股、日股、韩股、台股;非交易时段返回最近交易日收盘价并以 as_of/stale 标注;ETF 的 premium_discount_rate 为正=溢价、负=折价",
|
|
67
67
|
parameters: {
|
|
68
68
|
type: "object",
|
|
69
69
|
properties: {
|
|
@@ -143,11 +143,19 @@ export default (pi: ExtensionAPI) => {
|
|
|
143
143
|
type: "string",
|
|
144
144
|
description: "股票代码(A股如600519,美股如AAPL,港股如00700.HK)",
|
|
145
145
|
},
|
|
146
|
+
periods: {
|
|
147
|
+
type: "number",
|
|
148
|
+
description: "返回最近N个报告期的财务趋势,默认 1(仅最新一期)",
|
|
149
|
+
},
|
|
146
150
|
},
|
|
147
151
|
required: ["symbol"],
|
|
148
152
|
},
|
|
149
|
-
async execute(_id, { symbol }) {
|
|
150
|
-
const result = await py("stock_data.py", [
|
|
153
|
+
async execute(_id, { symbol, periods = 1 }) {
|
|
154
|
+
const result = await py("stock_data.py", [
|
|
155
|
+
"financials",
|
|
156
|
+
symbol,
|
|
157
|
+
...(periods > 1 ? ["--periods", String(periods)] : []),
|
|
158
|
+
]);
|
|
151
159
|
return asText(result.stdout);
|
|
152
160
|
},
|
|
153
161
|
});
|
|
@@ -157,7 +165,7 @@ export default (pi: ExtensionAPI) => {
|
|
|
157
165
|
pi.registerTool({
|
|
158
166
|
name: "get_technical_analysis",
|
|
159
167
|
description:
|
|
160
|
-
"获取股票技术面分析(MA/MACD/RSI/BOLL/KDJ/成交量等指标 + 100分综合评分 + 6级买卖信号 +
|
|
168
|
+
"获取股票技术面分析(MA/MACD/RSI/BOLL/KDJ/成交量等指标 + 100分综合评分 + 6级买卖信号 + 趋势/偏离度/支撑压力位;多周期共振时 resonance.direction ∈ aligned_bullish/aligned_bearish/divergent)。个股技术面综合判断与买卖时机分析的首选;只要均线数值或自定义周期用 calculate_ma,专问量价用 get_volume_analysis,扫当日异动用 detect_anomaly",
|
|
161
169
|
parameters: {
|
|
162
170
|
type: "object",
|
|
163
171
|
properties: {
|
|
@@ -174,10 +182,14 @@ export default (pi: ExtensionAPI) => {
|
|
|
174
182
|
type: "number",
|
|
175
183
|
description: "用于计算指标的K线条数,默认 120",
|
|
176
184
|
},
|
|
185
|
+
periods: {
|
|
186
|
+
type: "string",
|
|
187
|
+
description: '多周期共振分析,逗号分隔的周期列表,如 "daily,weekly";不传则只分析 period 指定的单周期',
|
|
188
|
+
},
|
|
177
189
|
},
|
|
178
190
|
required: ["symbol"],
|
|
179
191
|
},
|
|
180
|
-
async execute(_id, { symbol, period = "daily", count = 120 }) {
|
|
192
|
+
async execute(_id, { symbol, period = "daily", count = 120, periods }) {
|
|
181
193
|
const result = await py("technical.py", [
|
|
182
194
|
"analyze",
|
|
183
195
|
symbol,
|
|
@@ -185,6 +197,7 @@ export default (pi: ExtensionAPI) => {
|
|
|
185
197
|
period,
|
|
186
198
|
"--count",
|
|
187
199
|
String(count),
|
|
200
|
+
...(periods ? ["--periods", periods] : []),
|
|
188
201
|
]);
|
|
189
202
|
return asText(result.stdout);
|
|
190
203
|
},
|
|
@@ -465,6 +478,49 @@ export default (pi: ExtensionAPI) => {
|
|
|
465
478
|
},
|
|
466
479
|
});
|
|
467
480
|
|
|
481
|
+
pi.registerTool({
|
|
482
|
+
name: "get_margin_trading",
|
|
483
|
+
description:
|
|
484
|
+
"获取A股个股融资融券明细(融资余额/融资买入额/融券余量等,上交所/深交所官方数据按交易所分流),返回最近N个交易日序列(最新在前)。金额单位为元,short_*_shares 单位为股。仅两融标的有数据,非两融标的返回错误",
|
|
485
|
+
parameters: {
|
|
486
|
+
type: "object",
|
|
487
|
+
properties: {
|
|
488
|
+
symbol: {
|
|
489
|
+
type: "string",
|
|
490
|
+
description: "A股股票代码,如 600519",
|
|
491
|
+
},
|
|
492
|
+
days: {
|
|
493
|
+
type: "number",
|
|
494
|
+
description: "返回最近N个交易日,默认 10",
|
|
495
|
+
},
|
|
496
|
+
},
|
|
497
|
+
required: ["symbol"],
|
|
498
|
+
},
|
|
499
|
+
async execute(_id, { symbol, days = 10 }) {
|
|
500
|
+
const result = await py("stock_data.py", ["margin_trading", symbol, "--days", String(days)]);
|
|
501
|
+
return asText(result.stdout);
|
|
502
|
+
},
|
|
503
|
+
});
|
|
504
|
+
|
|
505
|
+
pi.registerTool({
|
|
506
|
+
name: "get_northbound_flow",
|
|
507
|
+
description:
|
|
508
|
+
"获取北向资金市场级净买入序列(最新在前,单位亿元)。数据口径:东方财富沪深港通历史数据;2024-08-16 起交易所停止披露日度净买额,仅 2024-08 之前历史数据可查(近期小 days 窗口会返回停披错误,加大 days 可取历史)",
|
|
509
|
+
parameters: {
|
|
510
|
+
type: "object",
|
|
511
|
+
properties: {
|
|
512
|
+
days: {
|
|
513
|
+
type: "number",
|
|
514
|
+
description: "返回最近N个交易日,默认 10",
|
|
515
|
+
},
|
|
516
|
+
},
|
|
517
|
+
},
|
|
518
|
+
async execute(_id, { days = 10 }) {
|
|
519
|
+
const result = await py("stock_data.py", ["northbound_flow", "--days", String(days)]);
|
|
520
|
+
return asText(result.stdout);
|
|
521
|
+
},
|
|
522
|
+
});
|
|
523
|
+
|
|
468
524
|
pi.registerTool({
|
|
469
525
|
name: "get_fundamental_context",
|
|
470
526
|
description:
|
|
@@ -1134,17 +1190,39 @@ export default (pi: ExtensionAPI) => {
|
|
|
1134
1190
|
pi.registerTool({
|
|
1135
1191
|
name: "render_market_report",
|
|
1136
1192
|
description:
|
|
1137
|
-
"大盘复盘报告渲染 — 将结构化报告 JSON 通过 j2 模板渲染为 Markdown。report 字段以 schemas/market_review_schema.json
|
|
1193
|
+
"大盘复盘报告渲染 — 将结构化报告 JSON 通过 j2 模板渲染为 Markdown。report 字段以 schemas/market_review_schema.json 为准。save=true 时把报告对象追加归档到本地 JSONL(默认不保存不推送),纵向对比用 get_review_history",
|
|
1138
1194
|
parameters: {
|
|
1139
1195
|
type: "object",
|
|
1140
1196
|
properties: {
|
|
1141
1197
|
report: { type: "object", description: "结构化市场复盘" },
|
|
1198
|
+
save: { type: "boolean", description: "是否归档到本地复盘 JSONL 存储,默认 false" },
|
|
1142
1199
|
},
|
|
1143
1200
|
required: ["report"],
|
|
1144
1201
|
},
|
|
1145
|
-
async execute(_id, { report }) {
|
|
1202
|
+
async execute(_id, { report, save }) {
|
|
1146
1203
|
const b64 = Buffer.from(JSON.stringify(report), "utf-8").toString("base64");
|
|
1147
|
-
const result = await py("report_renderer.py", [
|
|
1204
|
+
const result = await py("report_renderer.py", [
|
|
1205
|
+
"market",
|
|
1206
|
+
"--input-b64",
|
|
1207
|
+
b64,
|
|
1208
|
+
...(save ? ["--save"] : []),
|
|
1209
|
+
]);
|
|
1210
|
+
return asText(result.stdout);
|
|
1211
|
+
},
|
|
1212
|
+
});
|
|
1213
|
+
|
|
1214
|
+
pi.registerTool({
|
|
1215
|
+
name: "get_review_history",
|
|
1216
|
+
description:
|
|
1217
|
+
"复盘归档历史 — 读取本地 JSONL 归档的最近 N 条市场复盘(最新在前),用于纵向对比(温度/姿态/主线变化)。归档由 render_market_report 的 save=true 写入,空存档返回空列表",
|
|
1218
|
+
parameters: {
|
|
1219
|
+
type: "object",
|
|
1220
|
+
properties: {
|
|
1221
|
+
limit: { type: "number", description: "返回条数,默认 10" },
|
|
1222
|
+
},
|
|
1223
|
+
},
|
|
1224
|
+
async execute(_id, { limit = 10 }) {
|
|
1225
|
+
const result = await py("market_review.py", ["history", "--limit", String(limit)]);
|
|
1148
1226
|
return asText(result.stdout);
|
|
1149
1227
|
},
|
|
1150
1228
|
});
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// Some model gateways resolve through Chinese DNS but not the runner's resolver.
|
|
2
|
+
// Keep the original hostname for HTTPS; only supply its missing A record.
|
|
3
|
+
import { execFileSync } from "node:child_process";
|
|
4
|
+
import { lookup } from "node:dns/promises";
|
|
5
|
+
import { isIP } from "node:net";
|
|
6
|
+
|
|
7
|
+
if (process.env.OPENAI_BASE_URL) {
|
|
8
|
+
const host = new URL(process.env.OPENAI_BASE_URL).hostname;
|
|
9
|
+
let resolved = false;
|
|
10
|
+
try {
|
|
11
|
+
await lookup(host, { family: 4 });
|
|
12
|
+
resolved = true;
|
|
13
|
+
} catch { /* ask a second resolver below */ }
|
|
14
|
+
|
|
15
|
+
if (!resolved) {
|
|
16
|
+
// Ask for the China-facing record; the runner's overseas view gets only a CNAME.
|
|
17
|
+
const url = `https://dns.alidns.com/resolve?name=${encodeURIComponent(host)}&type=A&edns_client_subnet=223.5.5.0%2F24`;
|
|
18
|
+
const response = await fetch(url, { signal: AbortSignal.timeout(10_000) });
|
|
19
|
+
if (!response.ok) throw new Error(`AliDNS lookup failed: HTTP ${response.status}`);
|
|
20
|
+
const answer = (await response.json()).Answer?.find((record) => record.type === 1);
|
|
21
|
+
if (isIP(answer?.data) !== 4) throw new Error(`No IPv4 address found for ${host}`);
|
|
22
|
+
execFileSync("sudo", ["tee", "-a", "/etc/hosts"], {
|
|
23
|
+
input: `${answer.data} ${host}\n`,
|
|
24
|
+
stdio: ["pipe", "ignore", "pipe"],
|
|
25
|
+
});
|
|
26
|
+
await fetch(`https://${host}/`, { signal: AbortSignal.timeout(10_000) });
|
|
27
|
+
console.log(`Resolved ${host} through AliDNS; HTTPS is reachable`);
|
|
28
|
+
}
|
|
29
|
+
}
|
package/scripts/setup-python.mjs
CHANGED
|
@@ -15,7 +15,7 @@ const venvPython = venvPythonPath(pkgDir);
|
|
|
15
15
|
const requirements = join(pkgDir, "tools", "requirements.txt");
|
|
16
16
|
|
|
17
17
|
function run(cmd) {
|
|
18
|
-
execSync(cmd, { stdio: "
|
|
18
|
+
execSync(cmd, { stdio: "inherit", timeout: 1_800_000 });
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
function findPython() {
|
|
@@ -23,7 +23,7 @@ function findPython() {
|
|
|
23
23
|
try {
|
|
24
24
|
const ver = execSync(`${name} --version`, { stdio: "pipe" }).toString().trim();
|
|
25
25
|
const match = ver.match(/(\d+)\.(\d+)/);
|
|
26
|
-
if (match && (parseInt(match[1]) > 3 || (parseInt(match[1]) === 3 && parseInt(match[2]) >=
|
|
26
|
+
if (match && (parseInt(match[1]) > 3 || (parseInt(match[1]) === 3 && parseInt(match[2]) >= 10))) {
|
|
27
27
|
return name;
|
|
28
28
|
}
|
|
29
29
|
} catch {}
|
|
@@ -35,23 +35,21 @@ try {
|
|
|
35
35
|
const python = findPython();
|
|
36
36
|
if (!python) {
|
|
37
37
|
console.warn(
|
|
38
|
-
"\n[
|
|
39
|
-
"Install Python 3.
|
|
38
|
+
"\n[stock-analysis-plugin] python3 >= 3.10 not found.\n" +
|
|
39
|
+
"Install Python 3.10+, then re-run: npm install\n"
|
|
40
40
|
);
|
|
41
|
-
process.exit(
|
|
41
|
+
process.exit(1);
|
|
42
42
|
}
|
|
43
43
|
|
|
44
44
|
if (!existsSync(venvDir)) {
|
|
45
45
|
run(`${python} -m venv "${venvDir}"`);
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
|
|
49
|
-
run(`"${venvPython}" -m pip install -q -r "${requirements}"`);
|
|
50
|
-
}
|
|
48
|
+
run(`"${venvPython}" -m pip install -q -r "${requirements}"`);
|
|
51
49
|
} catch (err) {
|
|
52
50
|
console.warn(
|
|
53
51
|
`\n[pi-stock-analysis] Python setup failed: ${err.message}\n` +
|
|
54
52
|
"You can manually create the venv and install tools/requirements.txt with your platform's python.\n"
|
|
55
53
|
);
|
|
56
|
-
process.exit(
|
|
54
|
+
process.exit(1);
|
|
57
55
|
}
|
|
@@ -10,7 +10,7 @@ description: 热点题材分析:评估板块强度、扩散度、个股关联
|
|
|
10
10
|
先运行:
|
|
11
11
|
|
|
12
12
|
```bash
|
|
13
|
-
python3
|
|
13
|
+
python3 tools/gather.py fundamental <symbol>
|
|
14
14
|
```
|
|
15
15
|
|
|
16
16
|
gather 工具返回:
|
|
@@ -21,7 +21,8 @@ gather 工具返回:
|
|
|
21
21
|
- `news` — 近期新闻(题材催化来源)
|
|
22
22
|
- `stock_info` — 公司基本信息(行业、业务)
|
|
23
23
|
- `sector_rankings` — 板块排名(核心数据源);`get_sector_rankings` 传 `board_type=concept` 时为概念板块排行,热点题材以概念口径为主
|
|
24
|
-
|
|
24
|
+
|
|
25
|
+
人气热搜榜不在 gather 返回中,需要时单独调用 `get_hot_stocks`(东方财富人气榜)辅助判断题材热度。
|
|
25
26
|
|
|
26
27
|
评估扩散度前,必须获取板块成分股及其当日表现;只有板块排名时,仅可判断当日相对强弱,不判断扩散度或持续性。
|
|
27
28
|
|
|
@@ -21,7 +21,7 @@ description: 全市场股票筛选:按市场、估值、成长、趋势或自
|
|
|
21
21
|
运行数据采集脚本进行 L1 量化筛选:
|
|
22
22
|
|
|
23
23
|
```bash
|
|
24
|
-
python3
|
|
24
|
+
python3 tools/screener.py screen --market A --top 20
|
|
25
25
|
```
|
|
26
26
|
|
|
27
27
|
可选参数:`--market`(A/HK/US)、`--top`(返回数量)、`--config`(自定义 YAML 配置路径)、`--l2`(L2 量化增强开关,默认关闭)。
|
|
@@ -39,6 +39,11 @@ exit:
|
|
|
39
39
|
stop_loss: -0.05 # 止损比例
|
|
40
40
|
take_profit: 0.15 # 止盈比例
|
|
41
41
|
|
|
42
|
+
simulation:
|
|
43
|
+
slippage: 0.001 # 滑点(买卖双边),默认 0.001
|
|
44
|
+
commission: 0.00025 # 佣金(买卖双边,券商自定;A股常见万2.5),默认 0.0015
|
|
45
|
+
stamp_tax: 0.0005 # 印花税(仅卖出收;A股 0.05%,其他市场按当下实际费率,无则省略),默认 0
|
|
46
|
+
|
|
42
47
|
position:
|
|
43
48
|
size: 1.0 # 仓位比例
|
|
44
49
|
max_positions: 1 # 最大持仓数
|
|
@@ -53,14 +58,13 @@ position:
|
|
|
53
58
|
运行回测脚本:
|
|
54
59
|
|
|
55
60
|
```bash
|
|
56
|
-
python3
|
|
61
|
+
python3 tools/backtest.py run <path.yaml> <symbol> --start <date> --end <date>
|
|
57
62
|
```
|
|
58
63
|
|
|
59
64
|
参数说明:
|
|
60
|
-
-
|
|
61
|
-
- `--symbol`:股票代码
|
|
65
|
+
- 前两个为位置参数,依次为:策略 YAML 文件路径、股票代码
|
|
62
66
|
- `--start` / `--end`:回测时间范围(可选,默认近一年)
|
|
63
|
-
- 初始资金默认 100
|
|
67
|
+
- 初始资金默认 100 万,可用 `--capital` 调整
|
|
64
68
|
|
|
65
69
|
### 第三步:分析结果
|
|
66
70
|
|
|
@@ -69,7 +73,7 @@ python3 scripts/gather.py --strategy <path.yaml> --symbol <symbol> --start <date
|
|
|
69
73
|
- 从 `metrics` 和 `trades` 计算期望值并与盈亏比一起报告。
|
|
70
74
|
- 报告最大回撤、连续亏损、交易次数和平均持有期;结果未携带初始风险时,将 1R 分布标为不可计算。
|
|
71
75
|
- 使用用户指定的互斥日期区间分别运行样本内和样本外回测。
|
|
72
|
-
-
|
|
76
|
+
- 成本假设引用结果中的 `costs` 字段(实际生效的佣金/滑点/印花税费率与实付费用合计),未模拟的费用与成交约束列入限制。
|
|
73
77
|
|
|
74
78
|
未模拟的结算、涨跌停、复权或特定市场费用列入限制,结论限定为该模拟条件下的历史表现。
|
|
75
79
|
|
|
@@ -42,6 +42,11 @@ exit:
|
|
|
42
42
|
stop_loss: "{stop_loss}"
|
|
43
43
|
take_profit: "{take_profit}"
|
|
44
44
|
|
|
45
|
+
simulation:
|
|
46
|
+
slippage: 0.001 # 滑点(买卖双边)
|
|
47
|
+
commission: 0.00025 # 佣金(买卖双边,A股常见万2.5)
|
|
48
|
+
stamp_tax: 0.0005 # 印花税(A股卖出单边;其他市场按当下实际费率,无则删除本行)
|
|
49
|
+
|
|
45
50
|
position:
|
|
46
51
|
size: 0.6
|
|
47
52
|
max_positions: 1
|
|
@@ -36,6 +36,11 @@ exit:
|
|
|
36
36
|
stop_loss: "{stop_loss}"
|
|
37
37
|
take_profit: "{take_profit}"
|
|
38
38
|
|
|
39
|
+
simulation:
|
|
40
|
+
slippage: 0.001 # 滑点(买卖双边)
|
|
41
|
+
commission: 0.00025 # 佣金(买卖双边,A股常见万2.5)
|
|
42
|
+
stamp_tax: 0.0005 # 印花税(A股卖出单边;其他市场按当下实际费率,无则删除本行)
|
|
43
|
+
|
|
39
44
|
position:
|
|
40
45
|
size: 0.8
|
|
41
46
|
max_positions: 1
|
|
@@ -9,11 +9,13 @@ parameters:
|
|
|
9
9
|
entry:
|
|
10
10
|
conditions:
|
|
11
11
|
- indicator: "ma_diff"
|
|
12
|
-
|
|
12
|
+
fast_period: 5
|
|
13
|
+
slow_period: 10
|
|
13
14
|
operator: ">"
|
|
14
15
|
value: 0
|
|
15
16
|
- indicator: "ma_diff"
|
|
16
|
-
|
|
17
|
+
fast_period: 10
|
|
18
|
+
slow_period: 20
|
|
17
19
|
operator: ">"
|
|
18
20
|
value: 0
|
|
19
21
|
- indicator: "macd_dif"
|
|
@@ -27,7 +29,8 @@ entry:
|
|
|
27
29
|
exit:
|
|
28
30
|
conditions:
|
|
29
31
|
- indicator: "ma_diff"
|
|
30
|
-
|
|
32
|
+
fast_period: 5
|
|
33
|
+
slow_period: 10
|
|
31
34
|
operator: "cross_below"
|
|
32
35
|
value: 0
|
|
33
36
|
- indicator: "macd_dif"
|
|
@@ -37,6 +40,11 @@ exit:
|
|
|
37
40
|
stop_loss: "{stop_loss}"
|
|
38
41
|
take_profit: "{take_profit}"
|
|
39
42
|
|
|
43
|
+
simulation:
|
|
44
|
+
slippage: 0.001 # 滑点(买卖双边)
|
|
45
|
+
commission: 0.00025 # 佣金(买卖双边,A股常见万2.5)
|
|
46
|
+
stamp_tax: 0.0005 # 印花税(A股卖出单边;其他市场按当下实际费率,无则删除本行)
|
|
47
|
+
|
|
40
48
|
position:
|
|
41
49
|
size: 1.0
|
|
42
50
|
max_positions: 1
|
|
@@ -18,7 +18,8 @@ entry:
|
|
|
18
18
|
operator: ">"
|
|
19
19
|
value: "{volume_threshold}"
|
|
20
20
|
- indicator: "ma_diff"
|
|
21
|
-
|
|
21
|
+
fast_period: 5
|
|
22
|
+
slow_period: 10
|
|
22
23
|
operator: ">"
|
|
23
24
|
value: 0
|
|
24
25
|
logic: "all"
|
|
@@ -37,8 +38,9 @@ exit:
|
|
|
37
38
|
take_profit: "{take_profit}"
|
|
38
39
|
|
|
39
40
|
simulation:
|
|
40
|
-
slippage: 0.002
|
|
41
|
+
slippage: 0.002 # 打板策略用更保守的费率:滑点0.2%、佣金万15(其余示例为 0.001/万2.5)
|
|
41
42
|
commission: 0.0015
|
|
43
|
+
stamp_tax: 0.0005 # 印花税(A股卖出单边;其他市场按当下实际费率,无则删除本行)
|
|
42
44
|
|
|
43
45
|
position:
|
|
44
46
|
size: 0.5
|
|
@@ -38,6 +38,11 @@ exit:
|
|
|
38
38
|
stop_loss: "{stop_loss}"
|
|
39
39
|
take_profit: "{take_profit}"
|
|
40
40
|
|
|
41
|
+
simulation:
|
|
42
|
+
slippage: 0.001 # 滑点(买卖双边)
|
|
43
|
+
commission: 0.00025 # 佣金(买卖双边,A股常见万2.5)
|
|
44
|
+
stamp_tax: 0.0005 # 印花税(A股卖出单边;其他市场按当下实际费率,无则删除本行)
|
|
45
|
+
|
|
41
46
|
position:
|
|
42
47
|
size: 0.5
|
|
43
48
|
max_positions: 1
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
name: "MA Golden Cross"
|
|
2
2
|
version: "1.0"
|
|
3
|
-
description: "均线金叉策略 — MA5上穿MA20时买入,MA5下穿MA20时卖出。使用 ma_diff
|
|
3
|
+
description: "均线金叉策略 — MA5上穿MA20时买入,MA5下穿MA20时卖出。使用 ma_diff 指标(fast_period/slow_period 显式指定快慢均线)检测交叉"
|
|
4
4
|
|
|
5
5
|
parameters:
|
|
6
6
|
fast_period: 5
|
|
@@ -11,7 +11,8 @@ parameters:
|
|
|
11
11
|
entry:
|
|
12
12
|
conditions:
|
|
13
13
|
- indicator: "ma_diff"
|
|
14
|
-
|
|
14
|
+
fast_period: "{fast_period}"
|
|
15
|
+
slow_period: "{slow_period}"
|
|
15
16
|
operator: "cross_above"
|
|
16
17
|
value: 0
|
|
17
18
|
- indicator: "volume_ratio"
|
|
@@ -22,13 +23,19 @@ entry:
|
|
|
22
23
|
exit:
|
|
23
24
|
conditions:
|
|
24
25
|
- indicator: "ma_diff"
|
|
25
|
-
|
|
26
|
+
fast_period: "{fast_period}"
|
|
27
|
+
slow_period: "{slow_period}"
|
|
26
28
|
operator: "cross_below"
|
|
27
29
|
value: 0
|
|
28
30
|
logic: "any"
|
|
29
31
|
stop_loss: "{stop_loss}"
|
|
30
32
|
take_profit: "{take_profit}"
|
|
31
33
|
|
|
34
|
+
simulation:
|
|
35
|
+
slippage: 0.001 # 滑点(买卖双边)
|
|
36
|
+
commission: 0.00025 # 佣金(买卖双边,A股常见万2.5)
|
|
37
|
+
stamp_tax: 0.0005 # 印花税(A股卖出单边;其他市场按当下实际费率,无则删除本行)
|
|
38
|
+
|
|
32
39
|
position:
|
|
33
40
|
size: 1.0
|
|
34
41
|
max_positions: 1
|
|
@@ -30,6 +30,11 @@ exit:
|
|
|
30
30
|
stop_loss: "{stop_loss}"
|
|
31
31
|
take_profit: "{take_profit}"
|
|
32
32
|
|
|
33
|
+
simulation:
|
|
34
|
+
slippage: 0.001 # 滑点(买卖双边)
|
|
35
|
+
commission: 0.00025 # 佣金(买卖双边,A股常见万2.5)
|
|
36
|
+
stamp_tax: 0.0005 # 印花税(A股卖出单边;其他市场按当下实际费率,无则删除本行)
|
|
37
|
+
|
|
33
38
|
position:
|
|
34
39
|
size: 1.0
|
|
35
40
|
max_positions: 1
|
|
@@ -9,7 +9,8 @@ parameters:
|
|
|
9
9
|
entry:
|
|
10
10
|
conditions:
|
|
11
11
|
- indicator: "ma_diff"
|
|
12
|
-
|
|
12
|
+
fast_period: 10
|
|
13
|
+
slow_period: 20
|
|
13
14
|
operator: ">"
|
|
14
15
|
value: 0
|
|
15
16
|
- indicator: "bollinger_position"
|
|
@@ -40,6 +41,11 @@ exit:
|
|
|
40
41
|
stop_loss: "{stop_loss}"
|
|
41
42
|
take_profit: "{take_profit}"
|
|
42
43
|
|
|
44
|
+
simulation:
|
|
45
|
+
slippage: 0.001 # 滑点(买卖双边)
|
|
46
|
+
commission: 0.00025 # 佣金(买卖双边,A股常见万2.5)
|
|
47
|
+
stamp_tax: 0.0005 # 印花税(A股卖出单边;其他市场按当下实际费率,无则删除本行)
|
|
48
|
+
|
|
43
49
|
position:
|
|
44
50
|
size: 1.0
|
|
45
51
|
max_positions: 1
|