@weaxs/dsh-stock-analysis 0.2.2 → 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 +2 -2
- package/dist/index.js +68 -15
- package/package.json +3 -3
- 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 +301 -92
- 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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Stock Analysis — DeepSeek Harness (dsh) Plugin
|
|
2
2
|
|
|
3
|
-
A股 / 港股 / 美股 / 日股 / 韩股 / 台股 行情、技术分析、筛选与回测。作为 dsh bundle 安装到 profile 后,对话中可调用
|
|
3
|
+
A股 / 港股 / 美股 / 日股 / 韩股 / 台股 行情、技术分析、筛选与回测。作为 dsh bundle 安装到 profile 后,对话中可调用 51 个工具,并自动注册 20 个工作流/策略方法论 skill。
|
|
4
4
|
|
|
5
5
|
## 安装
|
|
6
6
|
|
|
@@ -20,7 +20,7 @@ dsh plugin --profile <你的profile> add ./dsh
|
|
|
20
20
|
|
|
21
21
|
### Python 运行时
|
|
22
22
|
|
|
23
|
-
工具实际逻辑在 `tools/*.py`,依赖 `akshare`、`pandas`、`numpy`、`requests`。本包的 postinstall(`scripts/setup-python.mjs`)会在包目录下自动建 `.venv` 并装好依赖,前提:本机有 `python3 >= 3.
|
|
23
|
+
工具实际逻辑在 `tools/*.py`,依赖 `akshare`、`pandas`、`numpy`、`requests`。本包的 postinstall(`scripts/setup-python.mjs`)会在包目录下自动建 `.venv` 并装好依赖,前提:本机有 `python3 >= 3.10`。依赖安装失败时 postinstall 会返回非零状态,避免 pnpm 缓存未装完整的 `.venv`;解决安装问题后重新安装插件即可。
|
|
24
24
|
|
|
25
25
|
注意:dsh profile 使用 pnpm 且默认不执行第三方包的安装脚本。如 postinstall 被跳过,请在 profile 的 `pnpm-workspace.yaml` 中允许:
|
|
26
26
|
|
package/dist/index.js
CHANGED
|
@@ -112,7 +112,7 @@ function apply(ctx) {
|
|
|
112
112
|
ctx.tools.register(
|
|
113
113
|
pyTool({
|
|
114
114
|
name: "get_quote",
|
|
115
|
-
description: "\u83B7\u53D6\u80A1\u7968\u5B9E\u65F6\u884C\u60C5\u62A5\u4EF7\uFF08\u73B0\u4EF7\u3001\u6DA8\u8DCC\u5E45\u3001\u91CF\u6BD4\u7B49\uFF09\u3002\u652F\u6301A\u80A1\u3001\u6E2F\u80A1\u3001\u7F8E\u80A1\u3001\u65E5\u80A1\u3001\u97E9\u80A1\u3001\u53F0\u80A1\uFF1B\u975E\u4EA4\u6613\u65F6\u6BB5\u8FD4\u56DE\u6700\u8FD1\u4EA4\u6613\u65E5\u6536\u76D8\u4EF7\u5E76\u4EE5 as_of/stale \u6807\u6CE8",
|
|
115
|
+
description: "\u83B7\u53D6\u80A1\u7968\u5B9E\u65F6\u884C\u60C5\u62A5\u4EF7\uFF08\u73B0\u4EF7\u3001\u6DA8\u8DCC\u5E45\u3001\u91CF\u6BD4\u7B49\uFF09\u3002\u652F\u6301A\u80A1\u3001\u6E2F\u80A1\u3001\u7F8E\u80A1\u3001\u65E5\u80A1\u3001\u97E9\u80A1\u3001\u53F0\u80A1\uFF1B\u975E\u4EA4\u6613\u65F6\u6BB5\u8FD4\u56DE\u6700\u8FD1\u4EA4\u6613\u65E5\u6536\u76D8\u4EF7\u5E76\u4EE5 as_of/stale \u6807\u6CE8\uFF1BETF \u7684 premium_discount_rate \u4E3A\u6B63=\u6EA2\u4EF7\u3001\u8D1F=\u6298\u4EF7",
|
|
116
116
|
parameters: {
|
|
117
117
|
symbol: { type: "string", required: true, description: "\u80A1\u7968\u4EE3\u7801\uFF08A\u80A1\u5982600519\uFF0C\u7F8E\u80A1\u5982AAPL\uFF0C\u6E2F\u80A1\u598200700.HK\uFF09" }
|
|
118
118
|
},
|
|
@@ -161,16 +161,21 @@ function apply(ctx) {
|
|
|
161
161
|
name: "get_financials",
|
|
162
162
|
description: "\u83B7\u53D6\u80A1\u7968\u8D22\u52A1\u6458\u8981\u3002A\u80A1\u8FD4\u56DE\u6700\u65B0\u62A5\u544A\u671F ROE/\u6BDB\u5229\u7387/\u51C0\u5229\u7387/\u8D1F\u503A\u7387/\u6D41\u52A8\u6BD4\u7387\uFF1B\u5176\u4ED6\u5E02\u573A\u8FD4\u56DE PE/PB/\u5E02\u503C/\u8425\u6536/\u51C0\u5229\u6DA6\u7B49\u3002A\u80A1\u4F30\u503C\u3001\u6210\u957F\u548C\u5206\u7EA2\u7528 get_fundamental_context",
|
|
163
163
|
parameters: {
|
|
164
|
-
symbol: { type: "string", required: true, description: "\u80A1\u7968\u4EE3\u7801\uFF08A\u80A1\u5982600519\uFF0C\u7F8E\u80A1\u5982AAPL\uFF0C\u6E2F\u80A1\u598200700.HK\uFF09" }
|
|
164
|
+
symbol: { type: "string", required: true, description: "\u80A1\u7968\u4EE3\u7801\uFF08A\u80A1\u5982600519\uFF0C\u7F8E\u80A1\u5982AAPL\uFF0C\u6E2F\u80A1\u598200700.HK\uFF09" },
|
|
165
|
+
periods: { type: "number", description: "\u8FD4\u56DE\u6700\u8FD1N\u4E2A\u62A5\u544A\u671F\u7684\u8D22\u52A1\u8D8B\u52BF\uFF0C\u9ED8\u8BA4 1\uFF08\u4EC5\u6700\u65B0\u4E00\u671F\uFF09" }
|
|
165
166
|
},
|
|
166
167
|
script: "stock_data.py",
|
|
167
|
-
argv: (p) =>
|
|
168
|
+
argv: (p) => {
|
|
169
|
+
const args = ["financials", p.symbol];
|
|
170
|
+
if (p.periods && p.periods > 1) args.push("--periods", String(p.periods));
|
|
171
|
+
return args;
|
|
172
|
+
}
|
|
168
173
|
})
|
|
169
174
|
);
|
|
170
175
|
ctx.tools.register(
|
|
171
176
|
pyTool({
|
|
172
177
|
name: "get_technical_analysis",
|
|
173
|
-
description: "\u83B7\u53D6\u80A1\u7968\u6280\u672F\u9762\u5206\u6790\uFF08MA/MACD/RSI/BOLL/KDJ/\u6210\u4EA4\u91CF\u7B49\u6307\u6807 + 100\u5206\u7EFC\u5408\u8BC4\u5206 + 6\u7EA7\u4E70\u5356\u4FE1\u53F7 + \u8D8B\u52BF/\u504F\u79BB\u5EA6/\u652F\u6491\u538B\u529B\u4F4D\uFF09\u3002\u4E2A\u80A1\u6280\u672F\u9762\u7EFC\u5408\u5224\u65AD\u4E0E\u4E70\u5356\u65F6\u673A\u5206\u6790\u7684\u9996\u9009\uFF1B\u53EA\u8981\u5747\u7EBF\u6570\u503C\u6216\u81EA\u5B9A\u4E49\u5468\u671F\u7528 calculate_ma\uFF0C\u4E13\u95EE\u91CF\u4EF7\u7528 get_volume_analysis\uFF0C\u626B\u5F53\u65E5\u5F02\u52A8\u7528 detect_anomaly",
|
|
178
|
+
description: "\u83B7\u53D6\u80A1\u7968\u6280\u672F\u9762\u5206\u6790\uFF08MA/MACD/RSI/BOLL/KDJ/\u6210\u4EA4\u91CF\u7B49\u6307\u6807 + 100\u5206\u7EFC\u5408\u8BC4\u5206 + 6\u7EA7\u4E70\u5356\u4FE1\u53F7 + \u8D8B\u52BF/\u504F\u79BB\u5EA6/\u652F\u6491\u538B\u529B\u4F4D\uFF1B\u591A\u5468\u671F\u5171\u632F\u65F6 resonance.direction \u2208 aligned_bullish/aligned_bearish/divergent\uFF09\u3002\u4E2A\u80A1\u6280\u672F\u9762\u7EFC\u5408\u5224\u65AD\u4E0E\u4E70\u5356\u65F6\u673A\u5206\u6790\u7684\u9996\u9009\uFF1B\u53EA\u8981\u5747\u7EBF\u6570\u503C\u6216\u81EA\u5B9A\u4E49\u5468\u671F\u7528 calculate_ma\uFF0C\u4E13\u95EE\u91CF\u4EF7\u7528 get_volume_analysis\uFF0C\u626B\u5F53\u65E5\u5F02\u52A8\u7528 detect_anomaly",
|
|
174
179
|
parameters: {
|
|
175
180
|
symbol: { type: "string", required: true, description: "\u80A1\u7968\u4EE3\u7801\uFF08A\u80A1\u5982600519\uFF0C\u7F8E\u80A1\u5982AAPL\uFF0C\u6E2F\u80A1\u598200700.HK\uFF09" },
|
|
176
181
|
period: {
|
|
@@ -178,17 +183,25 @@ function apply(ctx) {
|
|
|
178
183
|
enum: ["daily", "weekly", "monthly"],
|
|
179
184
|
description: "\u5206\u6790\u5468\u671F\uFF0C\u9ED8\u8BA4 daily"
|
|
180
185
|
},
|
|
181
|
-
count: { type: "number", description: "\u7528\u4E8E\u8BA1\u7B97\u6307\u6807\u7684K\u7EBF\u6761\u6570\uFF0C\u9ED8\u8BA4 120" }
|
|
186
|
+
count: { type: "number", description: "\u7528\u4E8E\u8BA1\u7B97\u6307\u6807\u7684K\u7EBF\u6761\u6570\uFF0C\u9ED8\u8BA4 120" },
|
|
187
|
+
periods: {
|
|
188
|
+
type: "string",
|
|
189
|
+
description: '\u591A\u5468\u671F\u5171\u632F\u5206\u6790\uFF0C\u9017\u53F7\u5206\u9694\u7684\u5468\u671F\u5217\u8868\uFF0C\u5982 "daily,weekly"\uFF1B\u4E0D\u4F20\u5219\u53EA\u5206\u6790 period \u6307\u5B9A\u7684\u5355\u5468\u671F'
|
|
190
|
+
}
|
|
182
191
|
},
|
|
183
192
|
script: "technical.py",
|
|
184
|
-
argv: (p) =>
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
193
|
+
argv: (p) => {
|
|
194
|
+
const args = [
|
|
195
|
+
"analyze",
|
|
196
|
+
p.symbol,
|
|
197
|
+
"--period",
|
|
198
|
+
p.period ?? "daily",
|
|
199
|
+
"--count",
|
|
200
|
+
String(p.count ?? 120)
|
|
201
|
+
];
|
|
202
|
+
if (p.periods) args.push("--periods", p.periods);
|
|
203
|
+
return args;
|
|
204
|
+
}
|
|
192
205
|
})
|
|
193
206
|
);
|
|
194
207
|
ctx.tools.register(
|
|
@@ -379,6 +392,29 @@ function apply(ctx) {
|
|
|
379
392
|
argv: (p) => ["hot_stocks", "--top", String(p.top ?? 20)]
|
|
380
393
|
})
|
|
381
394
|
);
|
|
395
|
+
ctx.tools.register(
|
|
396
|
+
pyTool({
|
|
397
|
+
name: "get_margin_trading",
|
|
398
|
+
description: "\u83B7\u53D6A\u80A1\u4E2A\u80A1\u878D\u8D44\u878D\u5238\u660E\u7EC6\uFF08\u878D\u8D44\u4F59\u989D/\u878D\u8D44\u4E70\u5165\u989D/\u878D\u5238\u4F59\u91CF\u7B49\uFF0C\u4E0A\u4EA4\u6240/\u6DF1\u4EA4\u6240\u5B98\u65B9\u6570\u636E\u6309\u4EA4\u6613\u6240\u5206\u6D41\uFF09\uFF0C\u8FD4\u56DE\u6700\u8FD1N\u4E2A\u4EA4\u6613\u65E5\u5E8F\u5217\uFF08\u6700\u65B0\u5728\u524D\uFF09\u3002\u91D1\u989D\u5355\u4F4D\u4E3A\u5143\uFF0Cshort_*_shares \u5355\u4F4D\u4E3A\u80A1\u3002\u4EC5\u4E24\u878D\u6807\u7684\u6709\u6570\u636E\uFF0C\u975E\u4E24\u878D\u6807\u7684\u8FD4\u56DE\u9519\u8BEF",
|
|
399
|
+
parameters: {
|
|
400
|
+
symbol: { type: "string", required: true, description: "A\u80A1\u80A1\u7968\u4EE3\u7801\uFF0C\u5982 600519" },
|
|
401
|
+
days: { type: "number", description: "\u8FD4\u56DE\u6700\u8FD1N\u4E2A\u4EA4\u6613\u65E5\uFF0C\u9ED8\u8BA4 10" }
|
|
402
|
+
},
|
|
403
|
+
script: "stock_data.py",
|
|
404
|
+
argv: (p) => ["margin_trading", p.symbol, "--days", String(p.days ?? 10)]
|
|
405
|
+
})
|
|
406
|
+
);
|
|
407
|
+
ctx.tools.register(
|
|
408
|
+
pyTool({
|
|
409
|
+
name: "get_northbound_flow",
|
|
410
|
+
description: "\u83B7\u53D6\u5317\u5411\u8D44\u91D1\u5E02\u573A\u7EA7\u51C0\u4E70\u5165\u5E8F\u5217\uFF08\u6700\u65B0\u5728\u524D\uFF0C\u5355\u4F4D\u4EBF\u5143\uFF09\u3002\u6570\u636E\u53E3\u5F84\uFF1A\u4E1C\u65B9\u8D22\u5BCC\u6CAA\u6DF1\u6E2F\u901A\u5386\u53F2\u6570\u636E\uFF1B2024-08-16 \u8D77\u4EA4\u6613\u6240\u505C\u6B62\u62AB\u9732\u65E5\u5EA6\u51C0\u4E70\u989D\uFF0C\u4EC5 2024-08 \u4E4B\u524D\u5386\u53F2\u6570\u636E\u53EF\u67E5\uFF08\u8FD1\u671F\u5C0F days \u7A97\u53E3\u4F1A\u8FD4\u56DE\u505C\u62AB\u9519\u8BEF\uFF0C\u52A0\u5927 days \u53EF\u53D6\u5386\u53F2\uFF09",
|
|
411
|
+
parameters: {
|
|
412
|
+
days: { type: "number", description: "\u8FD4\u56DE\u6700\u8FD1N\u4E2A\u4EA4\u6613\u65E5\uFF0C\u9ED8\u8BA4 10" }
|
|
413
|
+
},
|
|
414
|
+
script: "stock_data.py",
|
|
415
|
+
argv: (p) => ["northbound_flow", "--days", String(p.days ?? 10)]
|
|
416
|
+
})
|
|
417
|
+
);
|
|
382
418
|
ctx.tools.register(
|
|
383
419
|
pyTool({
|
|
384
420
|
name: "get_fundamental_context",
|
|
@@ -812,22 +848,39 @@ function apply(ctx) {
|
|
|
812
848
|
ctx.tools.register(
|
|
813
849
|
pyTool({
|
|
814
850
|
name: "render_market_report",
|
|
815
|
-
description: "\u5927\u76D8\u590D\u76D8\u62A5\u544A\u6E32\u67D3 \u2014 \u5C06\u7ED3\u6784\u5316\u62A5\u544A JSON \u901A\u8FC7 j2 \u6A21\u677F\u6E32\u67D3\u4E3A Markdown\u3002report \u5B57\u6BB5\u4EE5 schemas/market_review_schema.json \u4E3A\u51C6\
|
|
851
|
+
description: "\u5927\u76D8\u590D\u76D8\u62A5\u544A\u6E32\u67D3 \u2014 \u5C06\u7ED3\u6784\u5316\u62A5\u544A JSON \u901A\u8FC7 j2 \u6A21\u677F\u6E32\u67D3\u4E3A Markdown\u3002report \u5B57\u6BB5\u4EE5 schemas/market_review_schema.json \u4E3A\u51C6\u3002save=true \u65F6\u628A\u62A5\u544A\u5BF9\u8C61\u8FFD\u52A0\u5F52\u6863\u5230\u672C\u5730 JSONL\uFF08\u9ED8\u8BA4\u4E0D\u4FDD\u5B58\u4E0D\u63A8\u9001\uFF09\uFF0C\u7EB5\u5411\u5BF9\u6BD4\u7528 get_review_history",
|
|
816
852
|
parameters: {
|
|
817
853
|
report: {
|
|
818
854
|
type: "object",
|
|
819
855
|
additionalProperties: true,
|
|
820
856
|
required: true,
|
|
821
857
|
description: "\u7ED3\u6784\u5316\u5E02\u573A\u590D\u76D8"
|
|
858
|
+
},
|
|
859
|
+
save: {
|
|
860
|
+
type: "boolean",
|
|
861
|
+
description: "\u662F\u5426\u5F52\u6863\u5230\u672C\u5730\u590D\u76D8 JSONL \u5B58\u50A8\uFF0C\u9ED8\u8BA4 false"
|
|
822
862
|
}
|
|
823
863
|
},
|
|
824
864
|
script: "report_renderer.py",
|
|
825
865
|
argv: (p) => {
|
|
826
866
|
const b64 = Buffer.from(JSON.stringify(p.report), "utf-8").toString("base64");
|
|
827
|
-
|
|
867
|
+
const args = ["market", "--input-b64", b64];
|
|
868
|
+
if (p.save) args.push("--save");
|
|
869
|
+
return args;
|
|
828
870
|
}
|
|
829
871
|
})
|
|
830
872
|
);
|
|
873
|
+
ctx.tools.register(
|
|
874
|
+
pyTool({
|
|
875
|
+
name: "get_review_history",
|
|
876
|
+
description: "\u590D\u76D8\u5F52\u6863\u5386\u53F2 \u2014 \u8BFB\u53D6\u672C\u5730 JSONL \u5F52\u6863\u7684\u6700\u8FD1 N \u6761\u5E02\u573A\u590D\u76D8\uFF08\u6700\u65B0\u5728\u524D\uFF09\uFF0C\u7528\u4E8E\u7EB5\u5411\u5BF9\u6BD4\uFF08\u6E29\u5EA6/\u59FF\u6001/\u4E3B\u7EBF\u53D8\u5316\uFF09\u3002\u5F52\u6863\u7531 render_market_report \u7684 save=true \u5199\u5165\uFF0C\u7A7A\u5B58\u6863\u8FD4\u56DE\u7A7A\u5217\u8868",
|
|
877
|
+
parameters: {
|
|
878
|
+
limit: { type: "number", description: "\u8FD4\u56DE\u6761\u6570\uFF0C\u9ED8\u8BA4 10" }
|
|
879
|
+
},
|
|
880
|
+
script: "market_review.py",
|
|
881
|
+
argv: (p) => ["history", "--limit", String(p.limit ?? 10)]
|
|
882
|
+
})
|
|
883
|
+
);
|
|
831
884
|
ctx.tools.register(
|
|
832
885
|
pyTool({
|
|
833
886
|
name: "build_watchlist_context",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@weaxs/dsh-stock-analysis",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.3",
|
|
4
4
|
"description": "DeepSeek Harness (dsh) plugin for stock analysis, screening, and strategy backtesting across A/HK/US/JP/KR/TW markets",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"license": "MIT",
|
|
46
46
|
"peerDependencies": {
|
|
47
47
|
"@deepseek-ai/cordis": "^4.0.1",
|
|
48
|
-
"@deepseek-ai/dsh-skill": "^0.0.1-rc.1",
|
|
49
|
-
"@deepseek-ai/dsh-tools": "^0.0.1-rc.1"
|
|
48
|
+
"@deepseek-ai/dsh-skill": "^0.0.1-rc.1 || ^0.1.7-rc.1 || ^0.2.0-rc.2",
|
|
49
|
+
"@deepseek-ai/dsh-tools": "^0.0.1-rc.1 || ^0.1.7-rc.1 || ^0.2.0-rc.2"
|
|
50
50
|
}
|
|
51
51
|
}
|
|
@@ -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
|
|
@@ -26,7 +26,8 @@ entry:
|
|
|
26
26
|
exit:
|
|
27
27
|
conditions:
|
|
28
28
|
- indicator: "ma_diff"
|
|
29
|
-
|
|
29
|
+
fast_period: 5
|
|
30
|
+
slow_period: 10
|
|
30
31
|
operator: "cross_below"
|
|
31
32
|
value: 0
|
|
32
33
|
- indicator: "rsi"
|
|
@@ -37,6 +38,11 @@ exit:
|
|
|
37
38
|
stop_loss: "{stop_loss}"
|
|
38
39
|
take_profit: "{take_profit}"
|
|
39
40
|
|
|
41
|
+
simulation:
|
|
42
|
+
slippage: 0.001 # 滑点(买卖双边)
|
|
43
|
+
commission: 0.00025 # 佣金(买卖双边,A股常见万2.5)
|
|
44
|
+
stamp_tax: 0.0005 # 印花税(A股卖出单边;其他市场按当下实际费率,无则删除本行)
|
|
45
|
+
|
|
40
46
|
position:
|
|
41
47
|
size: 0.8
|
|
42
48
|
max_positions: 1
|
package/tools/_subproc.py
CHANGED
|
@@ -6,8 +6,12 @@ so this resolves both when a tool runs as a script (sys.path[0] = tools/) and wh
|
|
|
6
6
|
pytest imports it as tools.*.
|
|
7
7
|
"""
|
|
8
8
|
|
|
9
|
+
import contextlib
|
|
9
10
|
import json
|
|
11
|
+
import math
|
|
10
12
|
import os
|
|
13
|
+
import re
|
|
14
|
+
import socket
|
|
11
15
|
import subprocess
|
|
12
16
|
import sys
|
|
13
17
|
|
|
@@ -44,3 +48,48 @@ def run_tool(script: str, args: list, timeout: int = 30, parse_json: bool = True
|
|
|
44
48
|
except Exception:
|
|
45
49
|
pass
|
|
46
50
|
return None
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def utf8_stdio() -> None:
|
|
54
|
+
"""Force UTF-8 stdio. Windows defaults stdio to a legacy code page (cp1252)
|
|
55
|
+
that cannot encode the Chinese text these tools emit — call at CLI entry."""
|
|
56
|
+
for s in (sys.stdout, sys.stderr):
|
|
57
|
+
if hasattr(s, "reconfigure"):
|
|
58
|
+
s.reconfigure(encoding="utf-8")
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
@contextlib.contextmanager
|
|
62
|
+
def socket_timeout(seconds: float):
|
|
63
|
+
"""Bound every blocking socket op for the wrapped chain's duration: akshare/efinance
|
|
64
|
+
leave requests timeout-less, so on a blackholed network a leg hangs until the kernel
|
|
65
|
+
TCP timeout (~2min) and the chain would overrun the caller's subprocess budget before
|
|
66
|
+
ever reaching the plain-HTTPS legs. try/finally always restores the previous default
|
|
67
|
+
(no global-state leak); explicit per-request timeouts (tencent/sina legs) still win."""
|
|
68
|
+
old_timeout = socket.getdefaulttimeout()
|
|
69
|
+
socket.setdefaulttimeout(seconds)
|
|
70
|
+
try:
|
|
71
|
+
yield
|
|
72
|
+
finally:
|
|
73
|
+
socket.setdefaulttimeout(old_timeout)
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
_SECRET_PARAM_RE = re.compile(r"(?i)((?:api[_-]?key|token|secret|access[_-]?token)=)[^&\s]+")
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def scrub_secrets(msg: str) -> str:
|
|
80
|
+
"""Error text may embed request URLs (requests connection errors) — never leak keys
|
|
81
|
+
into stdout JSON."""
|
|
82
|
+
return _SECRET_PARAM_RE.sub(r"\1***", msg)
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def json_safe(obj):
|
|
86
|
+
"""Replace non-finite floats (inf/-inf/nan, e.g. an all-flat P&L profit_loss_ratio)
|
|
87
|
+
with None so json.dumps never emits the non-standard Infinity/NaN tokens that
|
|
88
|
+
break strict JSON.parse hosts."""
|
|
89
|
+
if isinstance(obj, float):
|
|
90
|
+
return obj if math.isfinite(obj) else None
|
|
91
|
+
if isinstance(obj, dict):
|
|
92
|
+
return {k: json_safe(v) for k, v in obj.items()}
|
|
93
|
+
if isinstance(obj, list):
|
|
94
|
+
return [json_safe(v) for v in obj]
|
|
95
|
+
return obj
|