@weaxs/openclaw-stock-analysis 0.2.8 → 0.2.10
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 +3 -1
- package/dist/index.js +154 -20
- package/index.ts +126 -6
- package/openclaw.plugin.json +4 -1
- package/package.json +4 -3
- package/scripts/profile-offline.py +127 -0
- package/scripts/profile-workflows.py +87 -0
- package/scripts/setup-python.mjs +11 -4
- package/scripts/venv-python.mjs +7 -0
- package/skills/event-driven/SKILL.md +2 -0
- package/skills/growth-quality/SKILL.md +2 -0
- package/skills/market-review/SKILL.md +1 -1
- package/skills/sector-rotation/SKILL.md +57 -0
- package/skills/sector-rotation/references/computation.md +83 -0
- package/skills/sector-rotation/references/strategy_rules.md +62 -0
- package/skills/sector-rotation/scripts/rotation_metrics.py +11 -0
- package/skills/stock-analysis/SKILL.md +15 -4
- package/skills/stock-analysis/references/host-workflows.md +45 -0
- package/skills/stock-analysis/references/stateless-analysis.md +16 -2
- package/skills/stock-screener/SKILL.md +6 -0
- package/skills/strategy-backtest/SKILL.md +10 -3
- package/tools/_cache.py +93 -21
- package/tools/_subproc.py +43 -8
- package/tools/anomaly_detect.py +11 -6
- package/tools/backtest.py +225 -70
- package/tools/capabilities.py +3 -0
- package/tools/cli_budgets.json +2 -1
- package/tools/gather.py +63 -8
- package/tools/market_regime.py +26 -15
- package/tools/market_review.py +2 -2
- package/tools/position_context.py +5 -2
- package/tools/report_renderer.py +4 -0
- package/tools/requirements.txt +2 -2
- package/tools/risk_screening.py +40 -15
- package/tools/screener.py +44 -18
- package/tools/search_intel.py +94 -32
- package/tools/sec_holders.py +27 -25
- package/tools/sector_rotation.py +466 -0
- package/tools/signal_tracker.py +100 -49
- package/tools/stateless_analysis.py +600 -33
- package/tools/stock_data.py +111 -26
- package/tools/technical.py +42 -40
- package/tools/trading_calendar.py +26 -21
- package/tools/value_data.py +6 -2
- package/tools/watchlist.py +24 -15
- package/tools/watchlist_context.py +63 -49
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Stock Analysis — OpenClaw Plugin
|
|
2
2
|
|
|
3
|
-
A股 / 港股 / 美股 / 日股 / 韩股 / 台股 行情、技术分析、筛选与回测。OpenClaw Gateway 加载后即可在对话中调用
|
|
3
|
+
A股 / 港股 / 美股 / 日股 / 韩股 / 台股 行情、技术分析、筛选与回测。OpenClaw Gateway 加载后即可在对话中调用 71 个工具。
|
|
4
4
|
|
|
5
5
|
## 安装
|
|
6
6
|
|
|
@@ -35,6 +35,8 @@ npm install
|
|
|
35
35
|
- `analyze_pattern` — 12+ 种 K 线形态识别
|
|
36
36
|
- `calculate_ma` — 独立均线计算
|
|
37
37
|
- `get_volume_analysis` — 量价分析
|
|
38
|
+
- `analyze_portfolio_risk` — 组合敞口、相关性、止损与确定性压力测试
|
|
39
|
+
- `plan_portfolio_rebalance` — 目标权重、整手和现金约束下的调仓清单
|
|
38
40
|
|
|
39
41
|
### 市场全景
|
|
40
42
|
- `get_market_indices` — 主要指数(CN/HK/US/JP/KR/TW)
|
package/dist/index.js
CHANGED
|
@@ -56,7 +56,8 @@ var cli_budgets_default = {
|
|
|
56
56
|
watchlist_item: 480,
|
|
57
57
|
"stateless_analysis.py:event_study": 300,
|
|
58
58
|
"stateless_analysis.py:robustness": 660,
|
|
59
|
-
"trend_strategy.py:fetch": 660
|
|
59
|
+
"trend_strategy.py:fetch": 660,
|
|
60
|
+
"sector_rotation.py:backtest": 300
|
|
60
61
|
};
|
|
61
62
|
|
|
62
63
|
// scripts/cli-timeout.mjs
|
|
@@ -85,11 +86,22 @@ function commandTimeout(script, args) {
|
|
|
85
86
|
return budget * 1e3 + 3e4;
|
|
86
87
|
}
|
|
87
88
|
|
|
88
|
-
//
|
|
89
|
+
// scripts/venv-python.mjs
|
|
89
90
|
import { existsSync } from "node:fs";
|
|
91
|
+
import { join as join2 } from "node:path";
|
|
92
|
+
var isWin = process.platform === "win32";
|
|
93
|
+
function pythonEnvironmentRoot(rootDir) {
|
|
94
|
+
return existsSync(join2(rootDir, "openclaw.plugin.json")) ? join2(rootDir, "node_modules", ".stock-analysis-python") : rootDir;
|
|
95
|
+
}
|
|
96
|
+
function venvPythonPath(rootDir) {
|
|
97
|
+
return join2(rootDir, ".venv", isWin ? "Scripts" : "bin", isWin ? "python.exe" : "python3");
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// openclaw/index.ts
|
|
101
|
+
import { existsSync as existsSync2 } from "node:fs";
|
|
90
102
|
import * as cp from "node:child_process";
|
|
91
103
|
import { promisify } from "node:util";
|
|
92
|
-
import { dirname, join as
|
|
104
|
+
import { dirname, join as join3 } from "node:path";
|
|
93
105
|
import { fileURLToPath } from "node:url";
|
|
94
106
|
|
|
95
107
|
// node_modules/typebox/build/system/memory/memory.mjs
|
|
@@ -4526,28 +4538,39 @@ function __setExecutor(fn) {
|
|
|
4526
4538
|
executor = fn;
|
|
4527
4539
|
}
|
|
4528
4540
|
var here = dirname(fileURLToPath(import.meta.url));
|
|
4529
|
-
var toolsDir =
|
|
4541
|
+
var toolsDir = existsSync2(join3(here, "tools")) ? join3(here, "tools") : join3(here, "..", "tools");
|
|
4530
4542
|
var fallbackRoot = dirname(toolsDir);
|
|
4531
|
-
var
|
|
4532
|
-
var venvBin =
|
|
4543
|
+
var isWin2 = process.platform === "win32";
|
|
4544
|
+
var venvBin = join3(".venv", isWin2 ? "Scripts" : "bin", isWin2 ? "python.exe" : "python3");
|
|
4533
4545
|
function asText(text) {
|
|
4534
4546
|
return { content: [{ type: "text", text }] };
|
|
4535
4547
|
}
|
|
4548
|
+
function asReport(text) {
|
|
4549
|
+
const result = asText(text);
|
|
4550
|
+
try {
|
|
4551
|
+
const report = JSON.parse(text);
|
|
4552
|
+
if (report?.final === true && !Object.hasOwn(report, "error") && report.format === "markdown" && typeof report.content === "string" && report.content.trim()) {
|
|
4553
|
+
return { ...result, details: { sourceReply: { text: report.content } } };
|
|
4554
|
+
}
|
|
4555
|
+
} catch {
|
|
4556
|
+
}
|
|
4557
|
+
return result;
|
|
4558
|
+
}
|
|
4536
4559
|
var index_default = definePluginEntry({
|
|
4537
4560
|
id: "stock-analysis",
|
|
4538
4561
|
name: "Stock Analysis",
|
|
4539
4562
|
description: "Stock analysis, screening, and strategy backtesting across A/HK/US/JP/KR/TW markets",
|
|
4540
4563
|
register(api) {
|
|
4541
4564
|
const repoRoot = api.rootDir || fallbackRoot;
|
|
4542
|
-
const runtimeToolsDir =
|
|
4565
|
+
const runtimeToolsDir = existsSync2(join3(repoRoot, "tools")) ? join3(repoRoot, "tools") : toolsDir;
|
|
4543
4566
|
const pythonBin = () => {
|
|
4544
|
-
const venvPython =
|
|
4545
|
-
if (
|
|
4546
|
-
const parentVenvPython =
|
|
4547
|
-
if (
|
|
4548
|
-
return
|
|
4567
|
+
const venvPython = venvPythonPath(pythonEnvironmentRoot(repoRoot));
|
|
4568
|
+
if (existsSync2(venvPython)) return venvPython;
|
|
4569
|
+
const parentVenvPython = join3(repoRoot, "..", venvBin);
|
|
4570
|
+
if (existsSync2(parentVenvPython)) return parentVenvPython;
|
|
4571
|
+
return isWin2 ? "python" : "python3";
|
|
4549
4572
|
};
|
|
4550
|
-
const runPy = (script, args) => executor(pythonBin(), [
|
|
4573
|
+
const runPy = (script, args) => executor(pythonBin(), [join3(runtimeToolsDir, script), ...args]);
|
|
4551
4574
|
api.registerTool({
|
|
4552
4575
|
name: "compare_stocks",
|
|
4553
4576
|
description: "\u65E0\u72B6\u6001\u540C\u884C\u6307\u6807\u6BD4\u8F83\uFF1A\u5148\u7528\u73B0\u6709\u8D22\u52A1/\u884C\u60C5\u5DE5\u5177\u53D6\u6570\uFF0C\u518D\u4F20companies\uFF1B\u4EC5\u76F8\u540Cunit/basis/period\u53EF\u6392\u5E8F\uFF0C\u7F3A\u5931\u4E0D\u586B\u96F6\uFF0C\u4E0D\u751F\u6210\u4E70\u5356\u7EFC\u5408\u5206\u3002",
|
|
@@ -4604,7 +4627,7 @@ var index_default = definePluginEntry({
|
|
|
4604
4627
|
});
|
|
4605
4628
|
api.registerTool({
|
|
4606
4629
|
name: "analyze_portfolio_risk",
|
|
4607
|
-
description: "\u65E0\u72B6\u6001\u73B0\u8D27\u591A\u5934\u7EC4\u5408\u98CE\u9669\uFF1A\u8F93\u5165\u6301\u4ED3\u3001\u57FA\u51C6\u5E01\u79CD\u73B0\u91D1\u4E0E\u6C47\u7387\uFF0C\u8FD4\u56DE\u96C6\u4E2D\u5EA6\u3001\u5E01\u79CD/\u884C\u4E1A\u655E\u53E3\u3001\u4EF7\u683C\u76C8\u4E8F\
|
|
4630
|
+
description: "\u65E0\u72B6\u6001\u73B0\u8D27\u591A\u5934\u7EC4\u5408\u98CE\u9669\u4E0E\u538B\u529B\u6D4B\u8BD5\uFF1A\u8F93\u5165\u6301\u4ED3\u3001\u57FA\u51C6\u5E01\u79CD\u73B0\u91D1\u4E0E\u6C47\u7387\uFF0C\u8FD4\u56DE\u96C6\u4E2D\u5EA6\u3001\u5E01\u79CD/\u884C\u4E1A\u655E\u53E3\u3001\u4EF7\u683C\u76C8\u4E8F\u3001\u6B62\u635F\u60C5\u666F\u53CA\u53EF\u9009\u5E02\u573A/\u884C\u4E1A/\u4E2A\u80A1/\u6C47\u7387\u51B2\u51FB\u635F\u76CA\u3002\u7F3A\u6C47\u7387\u62A5\u9519\uFF1B\u4E0D\u4FDD\u5B58\u8D26\u6237\u3002",
|
|
4608
4631
|
parameters: typebox_exports.Object({
|
|
4609
4632
|
positions: typebox_exports.Array(typebox_exports.Object({
|
|
4610
4633
|
symbol: typebox_exports.String({ "description": "\u552F\u4E00\u4EE3\u7801\uFF0C\u91CD\u590D\u6301\u4ED3\u5148\u6C47\u603B" }),
|
|
@@ -4628,12 +4651,65 @@ var index_default = definePluginEntry({
|
|
|
4628
4651
|
date: typebox_exports.String({ "description": "YYYY-MM-DD\uFF0C\u552F\u4E00\u65E5\u671F" }),
|
|
4629
4652
|
close: typebox_exports.Number({ "description": "\u6B63\u6709\u9650\u6536\u76D8\u4EF7" })
|
|
4630
4653
|
}, { "additionalProperties": false }), { "description": "\u5B8C\u6574\u65E5K\u6536\u76D8\u5E8F\u5217\uFF0C2..20000\u6761\uFF0C\u4E0D\u5F97\u8DE8\u80A1\u7968\u6216\u6DF7\u7528\u590D\u6743\u53E3\u5F84" })
|
|
4631
|
-
}, { "additionalProperties": false }), { "description": "\u53EF\u9009\u5386\u53F2\uFF0C\u5171\u540C\u65E5\u671F\u672C\u5E01\u4EF7\u683C\u6536\u76CA\u76F8\u5173\u6027\uFF0C\u4E0D\u8BA1\u6C47\u7387" }))
|
|
4654
|
+
}, { "additionalProperties": false }), { "description": "\u53EF\u9009\u5386\u53F2\uFF0C\u5171\u540C\u65E5\u671F\u672C\u5E01\u4EF7\u683C\u6536\u76CA\u76F8\u5173\u6027\uFF0C\u4E0D\u8BA1\u6C47\u7387" })),
|
|
4655
|
+
stress_scenarios: typebox_exports.Optional(typebox_exports.Array(typebox_exports.Object({
|
|
4656
|
+
name: typebox_exports.String({ "description": "\u60C5\u666F\u540D\u79F0" }),
|
|
4657
|
+
market_shock: typebox_exports.Optional(typebox_exports.Number({ "description": "\u5168\u5E02\u573A\u8D44\u4EA7\u4EF7\u683C\u51B2\u51FB\u6BD4\u4F8B\uFF0C\u5982-0.1" })),
|
|
4658
|
+
sector_shocks: typebox_exports.Optional(typebox_exports.Array(typebox_exports.Object({
|
|
4659
|
+
sector: typebox_exports.String({ "description": "\u4E0E\u6301\u4ED3\u4E00\u81F4\u7684\u884C\u4E1A\u540D\u79F0" }),
|
|
4660
|
+
shock: typebox_exports.Number({ "description": "\u884C\u4E1A\u4EF7\u683C\u51B2\u51FB\u6BD4\u4F8B" })
|
|
4661
|
+
}, { "additionalProperties": false }), { "description": "\u53EF\u9009\u884C\u4E1A\u51B2\u51FB" })),
|
|
4662
|
+
symbol_shocks: typebox_exports.Optional(typebox_exports.Array(typebox_exports.Object({
|
|
4663
|
+
symbol: typebox_exports.String({ "description": "\u6301\u4ED3\u6807\u7684\u4EE3\u7801" }),
|
|
4664
|
+
shock: typebox_exports.Number({ "description": "\u6807\u7684\u4EF7\u683C\u51B2\u51FB\u6BD4\u4F8B" })
|
|
4665
|
+
}, { "additionalProperties": false }), { "description": "\u53EF\u9009\u4E2A\u80A1\u51B2\u51FB" })),
|
|
4666
|
+
currency_shocks: typebox_exports.Optional(typebox_exports.Array(typebox_exports.Object({
|
|
4667
|
+
currency: typebox_exports.String({ "description": "\u6301\u4ED3\u4E2D\u7684\u975E\u57FA\u51C6\u5E01\u79CD\uFF1B\u57FA\u51C6\u5E01\u79CD\u4E0D\u53EF\u76F8\u5BF9\u81EA\u8EAB\u51B2\u51FB" }),
|
|
4668
|
+
shock: typebox_exports.Number({ "description": "\u76F8\u5BF9\u57FA\u51C6\u5E01\u79CD\u7684\u6C47\u7387\u51B2\u51FB\u6BD4\u4F8B" })
|
|
4669
|
+
}, { "additionalProperties": false }), { "description": "\u53EF\u9009\u6C47\u7387\u51B2\u51FB" }))
|
|
4670
|
+
}, { "additionalProperties": false }), { "description": "\u53EF\u9009\u538B\u529B\u60C5\u666F\uFF1B\u6240\u6709\u51B2\u51FB\u5747\u4E3A\u6BD4\u4F8B\uFF0C\u7531\u5171\u4EAB\u6838\u5FC3\u8BA1\u7B97" }))
|
|
4632
4671
|
}, { "additionalProperties": false }),
|
|
4633
4672
|
async execute(_id, params) {
|
|
4634
4673
|
return asText(await withJsonInput(params, (path) => runPy("stateless_analysis.py", ["portfolio", "--input", path])));
|
|
4635
4674
|
}
|
|
4636
4675
|
});
|
|
4676
|
+
api.registerTool({
|
|
4677
|
+
name: "plan_portfolio_rebalance",
|
|
4678
|
+
description: "\u65E0\u72B6\u6001\u7EC4\u5408\u8C03\u4ED3\u8BA1\u5212\uFF1A\u6309\u5F53\u524D\u6301\u4ED3\u3001\u76EE\u6807\u6743\u91CD\u3001\u73B0\u91D1\u3001\u6C47\u7387\u3001\u6574\u624B\u3001\u8D39\u7528\u548C\u6362\u624B\u7EA6\u675F\u751F\u6210\u5148\u5356\u540E\u4E70\u6E05\u5355\uFF1B\u4E0D\u4FDD\u5B58\u8D26\u6237\u6216\u63D0\u4EA4\u8BA2\u5355\u3002",
|
|
4679
|
+
parameters: typebox_exports.Object({
|
|
4680
|
+
base_currency: typebox_exports.String({ "description": "\u57FA\u51C6\u5E01\u79CD" }),
|
|
4681
|
+
cash: typebox_exports.Number({ "description": "\u57FA\u51C6\u5E01\u79CD\u73B0\u91D1\uFF0C\u975E\u8D1F" }),
|
|
4682
|
+
positions: typebox_exports.Array(typebox_exports.Object({
|
|
4683
|
+
symbol: typebox_exports.String({ "description": "\u552F\u4E00\u4EE3\u7801\uFF0C\u91CD\u590D\u6301\u4ED3\u5148\u6C47\u603B" }),
|
|
4684
|
+
quantity: typebox_exports.Number({ "description": "\u6B63\u6301\u4ED3\u6570\u91CF" }),
|
|
4685
|
+
price: typebox_exports.Number({ "description": "\u6B63\u73B0\u4EF7" }),
|
|
4686
|
+
currency: typebox_exports.String({ "description": "\u6301\u4ED3\u5E01\u79CD\uFF0C\u5982CNY/USD/HKD" }),
|
|
4687
|
+
cost: typebox_exports.Optional(typebox_exports.Number({ "description": "\u540C\u5E01\u79CD\u6B63\u6210\u672C\u4EF7\uFF0C\u53EF\u9009\uFF1B\u8C03\u4ED3\u8BA1\u7B97\u4E0D\u4F7F\u7528" })),
|
|
4688
|
+
stop_price: typebox_exports.Optional(typebox_exports.Number({ "description": "\u540C\u5E01\u79CD\u6B63\u6B62\u635F\u4EF7\uFF0C\u53EF\u9009\uFF1B\u8C03\u4ED3\u8BA1\u7B97\u4E0D\u4F7F\u7528" })),
|
|
4689
|
+
sector: typebox_exports.Optional(typebox_exports.String({ "description": "\u7EDF\u4E00\u884C\u4E1A\u5206\u7C7B\uFF0C\u53EF\u9009" })),
|
|
4690
|
+
as_of: typebox_exports.Optional(typebox_exports.String({ "description": "\u5B9E\u9645\u4F30\u503C\u65F6\u70B9\uFF0C\u5EFA\u8BAEISO8601" }))
|
|
4691
|
+
}, { "additionalProperties": false }), { "description": "0..100\u4E2A\u73B0\u8D27\u591A\u5934\u6301\u4ED3\uFF0C\u7A7A\u6570\u7EC4\u8868\u793A\u7EAF\u73B0\u91D1\u5EFA\u4ED3" }),
|
|
4692
|
+
targets: typebox_exports.Array(typebox_exports.Object({
|
|
4693
|
+
symbol: typebox_exports.String({ "description": "\u76EE\u6807\u6807\u7684\u4EE3\u7801" }),
|
|
4694
|
+
weight: typebox_exports.Number({ "description": "\u76EE\u6807\u6743\u91CD\uFF1B\u5927\u4E8E0\u65F6lot_size\u5FC5\u586B" }),
|
|
4695
|
+
price: typebox_exports.Optional(typebox_exports.Number({ "description": "\u6B63\u76EE\u6807\u4EF7\u683C\uFF1B\u5F53\u524D\u672A\u6301\u6709\u7684\u65B0\u6807\u7684\u5FC5\u586B" })),
|
|
4696
|
+
currency: typebox_exports.Optional(typebox_exports.String({ "description": "\u76EE\u6807\u5E01\u79CD\uFF1B\u5F53\u524D\u672A\u6301\u6709\u7684\u65B0\u6807\u7684\u5FC5\u586B" })),
|
|
4697
|
+
sector: typebox_exports.Optional(typebox_exports.String({ "description": "\u7EDF\u4E00\u884C\u4E1A\u5206\u7C7B\uFF0C\u53EF\u9009" })),
|
|
4698
|
+
as_of: typebox_exports.Optional(typebox_exports.String({ "description": "\u5B9E\u9645\u4F30\u503C\u65F6\u70B9\uFF0C\u5EFA\u8BAEISO8601" })),
|
|
4699
|
+
lot_size: typebox_exports.Optional(typebox_exports.Number({ "description": "\u6B63\u6574\u6570\u4EA4\u6613\u5355\u4F4D\uFF1Bweight>0\u65F6\u5FC5\u586B" }))
|
|
4700
|
+
}, { "additionalProperties": false }), { "description": "1..100\u4E2A\u76EE\u6807\uFF1B\u65B0\u6807\u7684price/currency\u5FC5\u586B" }),
|
|
4701
|
+
fx_rates: typebox_exports.Optional(typebox_exports.Array(typebox_exports.Object({
|
|
4702
|
+
currency: typebox_exports.String({ "description": "\u552F\u4E00\u975E\u57FA\u51C6\u5E01\u79CD" }),
|
|
4703
|
+
rate: typebox_exports.Number({ "description": "\u4E00\u5355\u4F4D\u8BE5\u5E01\u79CD\u5BF9\u5E94\u591A\u5C11\u57FA\u51C6\u5E01\u79CD\uFF0C\u6B63\u6570" })
|
|
4704
|
+
}, { "additionalProperties": false }), { "description": "\u663E\u5F0F\u73B0\u4EF7\u6C47\u7387\uFF1B\u57FA\u51C6\u5E01\u79CD\u9690\u542B1\uFF0C\u4E0D\u5F97\u91CD\u590D" })),
|
|
4705
|
+
fee_rate: typebox_exports.Optional(typebox_exports.Number({ "description": "\u6BCF\u8FB9\u6BD4\u4F8B\u8D39\u75280..0.1\uFF0C\u9ED8\u8BA40\uFF1B\u4E0D\u542B\u672A\u63D0\u4F9B\u7A0E\u8D39/\u6700\u4F4E\u6536\u8D39" })),
|
|
4706
|
+
slippage_rate: typebox_exports.Optional(typebox_exports.Number({ "description": "\u6BCF\u8FB9\u6ED1\u70B90..0.1\uFF0C\u9ED8\u8BA40" })),
|
|
4707
|
+
max_turnover_fraction: typebox_exports.Optional(typebox_exports.Number({ "description": "\u975E\u8D1F\u6700\u5927\u603B\u6362\u624B\uFF0C\u6309\u4E70\u5356\u53C2\u8003\u91D1\u989D\u5408\u8BA1/\u521D\u59CB\u6743\u76CA\uFF1B\u9ED8\u8BA4\u4E0D\u9650\u5236\uFF0C\u53EF\u5927\u4E8E1" }))
|
|
4708
|
+
}, { "additionalProperties": false }),
|
|
4709
|
+
async execute(_id, params) {
|
|
4710
|
+
return asText(await withJsonInput(params, (path) => runPy("stateless_analysis.py", ["rebalance", "--input", path])));
|
|
4711
|
+
}
|
|
4712
|
+
});
|
|
4637
4713
|
api.registerTool({
|
|
4638
4714
|
name: "calculate_position_size",
|
|
4639
4715
|
description: "\u65E0\u72B6\u6001\u591A\u5934\u4ED3\u4F4D\u9884\u7B97\uFF1A\u540C\u5E01\u79CD\u91D1\u989D\uFF0C\u6309\u73B0\u91D1/\u98CE\u9669\u9884\u7B97/\u6700\u5927\u4ED3\u4F4D/\u4EA4\u6613\u5355\u4F4D\u53D6\u6700\u5C0F\u6570\u91CF\uFF0C\u53CC\u8FB9\u8D39\u7528\u548C\u6ED1\u70B9\u53C2\u4E0E\u6B62\u635F\u60C5\u666F\uFF1B\u4E0D\u6267\u884C\u4EA4\u6613\u3002",
|
|
@@ -5263,6 +5339,56 @@ var index_default = definePluginEntry({
|
|
|
5263
5339
|
return asText(out);
|
|
5264
5340
|
}
|
|
5265
5341
|
});
|
|
5342
|
+
api.registerTool({
|
|
5343
|
+
name: "calculate_rotation_metrics",
|
|
5344
|
+
description: "\u884C\u4E1A\u8F6E\u52A8\u6570\u503C\u590D\u6838\uFF1A\u8F93\u5165\u771F\u5B9EMC-dropout\u6837\u672C\u548C/\u6216\u5386\u53F2\u6210\u4EA4\u8BA1\u6570\uFF0C\u8BA1\u7B97\u96C6\u4E2D\u5EA6\u548C\u539F\u59CB\u914D\u6743\uFF1B\u4E0D\u8BAD\u7EC3\u6A21\u578B\u3001\u4E0D\u751F\u6210\u4E70\u5165\u4FE1\u53F7\uFF0C\u96F6\u5386\u53F2\u4E0D\u8865\u9ED8\u8BA4\u503C\u3002",
|
|
5345
|
+
parameters: typebox_exports.Object({
|
|
5346
|
+
prediction_samples: typebox_exports.Optional(typebox_exports.Array(typebox_exports.Object({
|
|
5347
|
+
symbol: typebox_exports.String({ "description": "\u552F\u4E00\u6807\u7684\u6807\u8BC6" }),
|
|
5348
|
+
samples: typebox_exports.Array(typebox_exports.Number({ "description": "\u540C\u4E00\u6A21\u578B/\u6807\u7684/\u65F6\u95F4\u7684\u6709\u9650\u7EBF\u6027\u8F93\u51FA\uFF0C\u4E0D\u662F\u4EF7\u683C\u6216\u6536\u76CA\u7387" }), { "description": "2..100000\u4E2A\u771F\u5B9EMC-dropout\u9884\u6D4B\uFF1B\u4E0D\u5F97\u7528\u968F\u673A\u6570\u6216\u52A8\u91CF\u4EE3\u66FF" })
|
|
5349
|
+
}, { "additionalProperties": false }), { "description": "1..100\u7EC4\uFF0C\u603B\u6837\u672C<=100000\uFF1B\u548Ctrade_counts\u81F3\u5C11\u63D0\u4F9B\u4E00\u9879" })),
|
|
5350
|
+
trade_counts: typebox_exports.Optional(typebox_exports.Array(typebox_exports.Object({
|
|
5351
|
+
symbol: typebox_exports.String({ "description": "\u552F\u4E00\u6807\u7684\u6807\u8BC6\uFF1B\u4EE3\u7801\u522B\u540D\u987B\u5148\u7EDF\u4E00" }),
|
|
5352
|
+
buys: typebox_exports.Number({ "description": "\u6B64\u524D\u5DF2\u5E73\u4ED3\u4E70\u5165\u5468\u6570\uFF0C\u975E\u8D1F\u6574\u6570" }),
|
|
5353
|
+
wins: typebox_exports.Number({ "description": "\u6B64\u524D\u76C8\u5229\u5E73\u4ED3\u6B21\u6570\uFF0C0..buys" }),
|
|
5354
|
+
streak: typebox_exports.Number({ "description": "\u6B64\u524D\u8FDE\u7EED\u76C8\u5229\u4EA4\u6613\u6B21\u6570\uFF0C0..wins" })
|
|
5355
|
+
}, { "additionalProperties": false }), { "description": "1..100\u6761\u5DF2\u5B8C\u6210\u5386\u53F2\u6210\u4EA4\u8BA1\u6570\uFF1B\u4E0D\u5F97\u4F7F\u7528\u51B3\u7B56\u540E\u7684\u4EA4\u6613" }))
|
|
5356
|
+
}, { "additionalProperties": false }),
|
|
5357
|
+
async execute(_id, params) {
|
|
5358
|
+
return asText(await withJsonInput(params, (path) => runPy("sector_rotation.py", ["analyze", "--input", path])));
|
|
5359
|
+
}
|
|
5360
|
+
});
|
|
5361
|
+
api.registerTool({
|
|
5362
|
+
name: "backtest_rotation_allocation",
|
|
5363
|
+
description: "\u884C\u4E1A\u8F6E\u52A8\u914D\u6743\u5206\u9879\u56DE\u6D4B\uFF1A\u4EE3\u7801\u81EA\u52A8\u53D6\u884C\u60C5\uFF0C\u6216\u4F20\u660E\u786E\u5E01\u79CD/\u590D\u6743OHLCV\uFF1B\u76F8\u540C\u6BCF\u5468\u5168\u6C60\u4E70\u5356\u4E0B\u6BD4\u8F83\u7B49\u6743\u4E0E\u5386\u53F2\u914D\u6743\u3002\u6309\u5E02\u573A\u548C\u62A5\u4EF7\u5E01\u79CD\u72EC\u7ACB\u8D44\u91D1\uFF0C\u652F\u6301A/HK/US/JP/KR/TW\uFF1B\u4E0D\u662F\u5B8C\u6574\u8BBA\u6587\u6DF1\u5EA6\u6A21\u578B\u6216\u8DE8\u5E01\u79CD\u5171\u4EAB\u8D44\u91D1\u56DE\u6D4B\u3002",
|
|
5364
|
+
parameters: typebox_exports.Object({
|
|
5365
|
+
symbols: typebox_exports.Optional(typebox_exports.Array(typebox_exports.String({ "description": "\u552F\u4E00\u80A1\u7968/ETF\u4EE3\u7801\uFF0C\u6309\u63D2\u4EF6\u4EE3\u7801\u683C\u5F0F" }), { "description": "1..20\u53EA\u81EA\u52A8\u53D6\u6570\uFF0C\u4E0Edatasets\u4E92\u65A5\uFF1B\u4EFB\u4E00\u5931\u8D25\u6574\u6C60\u505C\u6B62" })),
|
|
5366
|
+
datasets: typebox_exports.Optional(typebox_exports.Array(typebox_exports.Object({
|
|
5367
|
+
symbol: typebox_exports.String({ "description": "A\u516D\u4F4D\u4EE3\u7801/HK\u59822800.HK/US\u5982XLK/JP\u59821306.T/KR\u5982069500.KS/TW\u59820050.TW" }),
|
|
5368
|
+
currency: typebox_exports.String({ "description": "\u5DF2\u6838\u5B9E\u62A5\u4EF7\u5E01\u79CD\u4E09\u5B57\u6BCD\u4EE3\u7801\uFF0C\u4E0D\u6309\u4E0A\u5E02\u5730\u731C\u6D4B" }),
|
|
5369
|
+
price_basis: typebox_exports.Union([typebox_exports.Literal("qfq"), typebox_exports.Literal("total_return"), typebox_exports.Literal("split_adjusted")], { "description": "\u5DF2\u6838\u5B9E\u4E14\u4E00\u81F4\u7684\u590D\u6743\u53E3\u5F84" }),
|
|
5370
|
+
bars: typebox_exports.Array(typebox_exports.Object({
|
|
5371
|
+
date: typebox_exports.String({ "description": "YYYY-MM-DD" }),
|
|
5372
|
+
open: typebox_exports.Number({ "description": "\u6709\u9650\u6B63OHLC\u4EF7\u683C\uFF1Bvolume\u975E\u8D1F" }),
|
|
5373
|
+
high: typebox_exports.Number({ "description": "\u6709\u9650\u6B63OHLC\u4EF7\u683C\uFF1Bvolume\u975E\u8D1F" }),
|
|
5374
|
+
low: typebox_exports.Number({ "description": "\u6709\u9650\u6B63OHLC\u4EF7\u683C\uFF1Bvolume\u975E\u8D1F" }),
|
|
5375
|
+
close: typebox_exports.Number({ "description": "\u6709\u9650\u6B63OHLC\u4EF7\u683C\uFF1Bvolume\u975E\u8D1F" }),
|
|
5376
|
+
volume: typebox_exports.Number({ "description": "\u6709\u9650\u6B63OHLC\u4EF7\u683C\uFF1Bvolume\u975E\u8D1F" }),
|
|
5377
|
+
adjusted: typebox_exports.Optional(typebox_exports.String({ "description": "\u53EF\u9009\u9010bar\u590D\u6743\u6807\u8BB0\uFF0C\u5B58\u5728\u65F6\u5FC5\u987B\u4E0Eprice_basis\u4E00\u81F4" })),
|
|
5378
|
+
source: typebox_exports.Optional(typebox_exports.String({ "description": "\u53EF\u9009\u884C\u60C5\u6765\u6E90\u6807\u8BC6\uFF0C\u7528\u4E8E\u6570\u636E\u8986\u76D6\u62A5\u544A" }))
|
|
5379
|
+
}, { "additionalProperties": false }), { "description": "\u9012\u589E\u552F\u4E00daily OHLCV\uFF0C2..20000\u884C\uFF0C\u5305\u542B\u8BC4\u4F30\u524D\u9884\u70ED\uFF1B\u603B\u91CF<=100000" })
|
|
5380
|
+
}, { "additionalProperties": false }), { "description": "1..20\u4E2A\u79BB\u7EBF\u6570\u636E\u96C6\uFF0C\u4E0Esymbols\u4E92\u65A5\uFF1B8MiB JSON\u8F93\u5165\u4E0A\u9650" })),
|
|
5381
|
+
start_date: typebox_exports.String({ "description": "\u8BC4\u4F30\u8D77\u59CBYYYY-MM-DD\uFF1B\u8DE8\u8FB9\u754C\u5468\u4E0D\u4EA4\u6613\uFF0C\u4E0D\u80FD\u7528\u8BC4\u4F30\u671F\u6536\u76CA\u521D\u59CB\u5316\u914D\u6743" }),
|
|
5382
|
+
end_date: typebox_exports.String({ "description": "\u5DF2\u6536\u76D8\u622A\u6B62YYYY-MM-DD\uFF1B\u4E0D\u5B8C\u6574\u672B\u5468\u4E0D\u6210\u4EA4" }),
|
|
5383
|
+
history_start_date: typebox_exports.Optional(typebox_exports.String({ "description": "\u4EC5\u4EE3\u7801\u6A21\u5F0F\uFF1B\u9ED8\u8BA4\u8BC4\u4F30\u524D\u4E00\u5E74\uFF0C\u5FC5\u987B\u65E9\u4E8Estart_date" })),
|
|
5384
|
+
warmup_weeks: typebox_exports.Optional(typebox_exports.Number({ "description": "\u8BC4\u4F30\u524D\u5B8C\u6574\u5386\u53F2\u4EA4\u6613\u54681..104\u6574\u6570\uFF0C\u9ED8\u8BA426\uFF1B\u4E0D\u8DB3\u505C\u6B62" })),
|
|
5385
|
+
capital: typebox_exports.Optional(typebox_exports.Number({ "description": "\u6BCF\u5E02\u573A/\u62A5\u4EF7\u5E01\u79CD\u5206\u7EC4\u72EC\u7ACB\u521D\u59CB\u8D44\u91D1\uFF0C\u9ED8\u8BA41000000\uFF0C\u4E0D\u662F\u6DF7\u5408\u6C60\u603B\u989D" })),
|
|
5386
|
+
cost_per_side: typebox_exports.Optional(typebox_exports.Number({ "description": "\u6BCF\u8FB9\u6BD4\u4F8B\u6210\u672C0..0.1\uFF0C\u9ED8\u8BA40.001\uFF1B\u4E70\u5165\u9884\u7B97\u542B\u8D39\u7528" }))
|
|
5387
|
+
}, { "additionalProperties": false }),
|
|
5388
|
+
async execute(_id, params) {
|
|
5389
|
+
return asText(await withJsonInput(params, (path) => runPy("sector_rotation.py", ["backtest", "--input", path])));
|
|
5390
|
+
}
|
|
5391
|
+
});
|
|
5266
5392
|
api.registerTool({
|
|
5267
5393
|
name: "analyze_trend_strategy",
|
|
5268
5394
|
description: "\u6708\u5EA6\u53F3\u4FA7\u8D8B\u52BF\u7B56\u7565\uFF1A\u76F4\u63A5\u4F20\u540C\u5E02\u573AA/HK/US\u80A1\u7968\u4EE3\u7801\uFF0C\u81EA\u52A8\u83B7\u53D6\u65E5K\uFF0C\u8F93\u51FA\u6708\u5EA6\u65B0\u5165/\u6301\u6709/\u9000\u51FA\u4E0E\u9006\u6CE2\u52A8\u9884\u7B97\u3002as_of\u9ED8\u8BA4\u6700\u8FD1\u5DF2\u6536\u76D8\u4EA4\u6613\u65E5\uFF0C\u6301\u4ED3\u53EF\u9009\u4E14\u4E0D\u4FDD\u5B58\uFF0C\u4E0D\u81EA\u52A8\u4E0B\u5355\uFF1B\u8DE8\u6837\u672C\u4ECDnot_validated\u3002",
|
|
@@ -5697,8 +5823,11 @@ var index_default = definePluginEntry({
|
|
|
5697
5823
|
});
|
|
5698
5824
|
api.registerTool({
|
|
5699
5825
|
name: "render_stock_report",
|
|
5700
|
-
description: "\u80A1\u7968\u5206\u6790\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 skill \u63D0\u4F9B\u7684 report_schema \u4E3A\u51C6\uFF0C\u4E0D\u8981\u81EA\u9020\u5B57\u6BB5\u3002template: brief|full\u3002\u5168\u90E8\u5206\u6790\u5B8C\u6210\u540E\u7684\u6700\u540E\u4E00\u6B65\u8C03\u7528\u3002\u4EC5\u6E32\u67D3\uFF0C\
|
|
5826
|
+
description: "\u80A1\u7968\u5206\u6790\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 skill \u63D0\u4F9B\u7684 report_schema \u4E3A\u51C6\uFF0C\u4E0D\u8981\u81EA\u9020\u5B57\u6BB5\u3002template: brief|full\u3002\u5168\u90E8\u5206\u6790\u5B8C\u6210\u540E\u7684\u6700\u540E\u4E00\u6B65\u8C03\u7528\u3002\u9ED8\u8BA4\u4EC5\u6E32\u67D3\uFF1Bfinal=true\u8868\u793A\u6700\u7EC8\u56DE\u590D\uFF0C\u652F\u6301\u76F4\u51FA\u7684\u5BBF\u4E3B\u53EF\u539F\u6837\u4EA4\u4ED8\u5E76\u7ED3\u675F\u672C\u8F6E\u3002report\u53EF\u5305\u542Bevidence\uFF08path/label/value/source/as_of\uFF09\u4E0Edata_quality\uFF08flags/limitations\uFF09\uFF0Cbrief/full\u5747\u5C55\u793A\u8BC1\u636E\u548C\u9650\u5236\u3002",
|
|
5827
|
+
canDeliverSourceReply: true,
|
|
5828
|
+
catalogMode: "direct-only",
|
|
5701
5829
|
parameters: typebox_exports.Object({
|
|
5830
|
+
final: typebox_exports.Optional(typebox_exports.Boolean({ description: "\u6700\u7EC8\u56DE\u590D\u6807\u8BB0\uFF0C\u9ED8\u8BA4false\uFF1B\u4FDD\u5B58\u9644\u4EF6\u6216\u7EE7\u7EED\u5206\u6790\u65F6\u4FDD\u6301false" })),
|
|
5702
5831
|
report: typebox_exports.Object({}, { additionalProperties: true, description: "\u7ED3\u6784\u5316\u80A1\u7968\u62A5\u544A JSON" }),
|
|
5703
5832
|
template: typebox_exports.Optional(
|
|
5704
5833
|
typebox_exports.Union([typebox_exports.Literal("brief"), typebox_exports.Literal("full")], {
|
|
@@ -5713,15 +5842,19 @@ var index_default = definePluginEntry({
|
|
|
5713
5842
|
"--template",
|
|
5714
5843
|
params.template ?? "full",
|
|
5715
5844
|
"--input-b64",
|
|
5716
|
-
b64
|
|
5845
|
+
b64,
|
|
5846
|
+
...params.final ? ["--final"] : []
|
|
5717
5847
|
]);
|
|
5718
|
-
return
|
|
5848
|
+
return asReport(out);
|
|
5719
5849
|
}
|
|
5720
5850
|
});
|
|
5721
5851
|
api.registerTool({
|
|
5722
5852
|
name: "render_market_report",
|
|
5723
|
-
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",
|
|
5853
|
+
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\uFF1Bfinal=true\u4EC5\u7528\u4E8E\u6700\u7EC8\u56DE\u590D\uFF0C\u4FDD\u5B58\u9644\u4EF6\u6216\u7EE7\u7EED\u5206\u6790\u65F6\u4FDD\u6301false",
|
|
5854
|
+
canDeliverSourceReply: true,
|
|
5855
|
+
catalogMode: "direct-only",
|
|
5724
5856
|
parameters: typebox_exports.Object({
|
|
5857
|
+
final: typebox_exports.Optional(typebox_exports.Boolean({ description: "\u6700\u7EC8\u56DE\u590D\u6807\u8BB0\uFF0C\u9ED8\u8BA4false\uFF1B\u4FDD\u5B58\u9644\u4EF6\u6216\u7EE7\u7EED\u5206\u6790\u65F6\u4FDD\u6301false" })),
|
|
5725
5858
|
report: typebox_exports.Object({}, { additionalProperties: true, description: "\u7ED3\u6784\u5316\u5E02\u573A\u590D\u76D8" }),
|
|
5726
5859
|
save: typebox_exports.Optional(typebox_exports.Boolean({ description: "\u662F\u5426\u5F52\u6863\u5230\u672C\u5730\u590D\u76D8 JSONL \u5B58\u50A8\uFF0C\u9ED8\u8BA4 false" }))
|
|
5727
5860
|
}),
|
|
@@ -5731,9 +5864,10 @@ var index_default = definePluginEntry({
|
|
|
5731
5864
|
"market",
|
|
5732
5865
|
"--input-b64",
|
|
5733
5866
|
b64,
|
|
5867
|
+
...params.final ? ["--final"] : [],
|
|
5734
5868
|
...params.save ? ["--save"] : []
|
|
5735
5869
|
]);
|
|
5736
|
-
return
|
|
5870
|
+
return asReport(out);
|
|
5737
5871
|
}
|
|
5738
5872
|
});
|
|
5739
5873
|
api.registerTool({
|
package/index.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { withJsonInput } from "../scripts/json-input.mjs";
|
|
2
2
|
import { commandTimeout } from "../scripts/cli-timeout.mjs";
|
|
3
|
+
import { pythonEnvironmentRoot, venvPythonPath } from "../scripts/venv-python.mjs";
|
|
3
4
|
import { existsSync } from "node:fs";
|
|
4
5
|
import * as cp from "node:child_process";
|
|
5
6
|
import { promisify } from "node:util";
|
|
@@ -47,6 +48,20 @@ function asText(text: string) {
|
|
|
47
48
|
return { content: [{ type: "text" as const, text }] };
|
|
48
49
|
}
|
|
49
50
|
|
|
51
|
+
function asReport(text: string) {
|
|
52
|
+
const result = asText(text);
|
|
53
|
+
try {
|
|
54
|
+
const report = JSON.parse(text);
|
|
55
|
+
if (report?.final === true && !Object.hasOwn(report, "error") && report.format === "markdown"
|
|
56
|
+
&& typeof report.content === "string" && report.content.trim()) {
|
|
57
|
+
return { ...result, details: { sourceReply: { text: report.content } } };
|
|
58
|
+
}
|
|
59
|
+
} catch {
|
|
60
|
+
// Invalid output stays visible to the model and must never end the turn.
|
|
61
|
+
}
|
|
62
|
+
return result;
|
|
63
|
+
}
|
|
64
|
+
|
|
50
65
|
export default definePluginEntry({
|
|
51
66
|
id: "stock-analysis",
|
|
52
67
|
name: "Stock Analysis",
|
|
@@ -57,7 +72,7 @@ export default definePluginEntry({
|
|
|
57
72
|
const repoRoot = api.rootDir || fallbackRoot;
|
|
58
73
|
const runtimeToolsDir = existsSync(join(repoRoot, "tools")) ? join(repoRoot, "tools") : toolsDir;
|
|
59
74
|
const pythonBin = () => {
|
|
60
|
-
const venvPython =
|
|
75
|
+
const venvPython = venvPythonPath(pythonEnvironmentRoot(repoRoot));
|
|
61
76
|
if (existsSync(venvPython)) return venvPython;
|
|
62
77
|
// In a staged dev checkout, the venv still lives at the repo root.
|
|
63
78
|
const parentVenvPython = join(repoRoot, "..", venvBin);
|
|
@@ -127,7 +142,7 @@ export default definePluginEntry({
|
|
|
127
142
|
|
|
128
143
|
api.registerTool({
|
|
129
144
|
name: "analyze_portfolio_risk",
|
|
130
|
-
description: "
|
|
145
|
+
description: "无状态现货多头组合风险与压力测试:输入持仓、基准币种现金与汇率,返回集中度、币种/行业敞口、价格盈亏、止损情景及可选市场/行业/个股/汇率冲击损益。缺汇率报错;不保存账户。",
|
|
131
146
|
parameters: Type.Object({
|
|
132
147
|
positions: Type.Array(Type.Object({
|
|
133
148
|
symbol: Type.String({"description": "唯一代码,重复持仓先汇总"}),
|
|
@@ -152,6 +167,22 @@ export default definePluginEntry({
|
|
|
152
167
|
close: Type.Number({"description": "正有限收盘价"}),
|
|
153
168
|
}, {"additionalProperties": false}), {"description": "完整日K收盘序列,2..20000条,不得跨股票或混用复权口径"}),
|
|
154
169
|
}, {"additionalProperties": false}), {"description": "可选历史,共同日期本币价格收益相关性,不计汇率"})),
|
|
170
|
+
stress_scenarios: Type.Optional(Type.Array(Type.Object({
|
|
171
|
+
name: Type.String({"description": "情景名称"}),
|
|
172
|
+
market_shock: Type.Optional(Type.Number({"description": "全市场资产价格冲击比例,如-0.1"})),
|
|
173
|
+
sector_shocks: Type.Optional(Type.Array(Type.Object({
|
|
174
|
+
sector: Type.String({"description": "与持仓一致的行业名称"}),
|
|
175
|
+
shock: Type.Number({"description": "行业价格冲击比例"}),
|
|
176
|
+
}, {"additionalProperties": false}), {"description": "可选行业冲击"})),
|
|
177
|
+
symbol_shocks: Type.Optional(Type.Array(Type.Object({
|
|
178
|
+
symbol: Type.String({"description": "持仓标的代码"}),
|
|
179
|
+
shock: Type.Number({"description": "标的价格冲击比例"}),
|
|
180
|
+
}, {"additionalProperties": false}), {"description": "可选个股冲击"})),
|
|
181
|
+
currency_shocks: Type.Optional(Type.Array(Type.Object({
|
|
182
|
+
currency: Type.String({"description": "持仓中的非基准币种;基准币种不可相对自身冲击"}),
|
|
183
|
+
shock: Type.Number({"description": "相对基准币种的汇率冲击比例"}),
|
|
184
|
+
}, {"additionalProperties": false}), {"description": "可选汇率冲击"})),
|
|
185
|
+
}, {"additionalProperties": false}), {"description": "可选压力情景;所有冲击均为比例,由共享核心计算"})),
|
|
155
186
|
}, {"additionalProperties": false}),
|
|
156
187
|
async execute(_id, params) {
|
|
157
188
|
return asText(await withJsonInput(params, (path: string) =>
|
|
@@ -159,6 +190,45 @@ export default definePluginEntry({
|
|
|
159
190
|
},
|
|
160
191
|
});
|
|
161
192
|
|
|
193
|
+
api.registerTool({
|
|
194
|
+
name: "plan_portfolio_rebalance",
|
|
195
|
+
description: "无状态组合调仓计划:按当前持仓、目标权重、现金、汇率、整手、费用和换手约束生成先卖后买清单;不保存账户或提交订单。",
|
|
196
|
+
parameters: Type.Object({
|
|
197
|
+
base_currency: Type.String({"description": "基准币种"}),
|
|
198
|
+
cash: Type.Number({"description": "基准币种现金,非负"}),
|
|
199
|
+
positions: Type.Array(Type.Object({
|
|
200
|
+
symbol: Type.String({"description": "唯一代码,重复持仓先汇总"}),
|
|
201
|
+
quantity: Type.Number({"description": "正持仓数量"}),
|
|
202
|
+
price: Type.Number({"description": "正现价"}),
|
|
203
|
+
currency: Type.String({"description": "持仓币种,如CNY/USD/HKD"}),
|
|
204
|
+
cost: Type.Optional(Type.Number({"description": "同币种正成本价,可选;调仓计算不使用"})),
|
|
205
|
+
stop_price: Type.Optional(Type.Number({"description": "同币种正止损价,可选;调仓计算不使用"})),
|
|
206
|
+
sector: Type.Optional(Type.String({"description": "统一行业分类,可选"})),
|
|
207
|
+
as_of: Type.Optional(Type.String({"description": "实际估值时点,建议ISO8601"})),
|
|
208
|
+
}, {"additionalProperties": false}), {"description": "0..100个现货多头持仓,空数组表示纯现金建仓"}),
|
|
209
|
+
targets: Type.Array(Type.Object({
|
|
210
|
+
symbol: Type.String({"description": "目标标的代码"}),
|
|
211
|
+
weight: Type.Number({"description": "目标权重;大于0时lot_size必填"}),
|
|
212
|
+
price: Type.Optional(Type.Number({"description": "正目标价格;当前未持有的新标的必填"})),
|
|
213
|
+
currency: Type.Optional(Type.String({"description": "目标币种;当前未持有的新标的必填"})),
|
|
214
|
+
sector: Type.Optional(Type.String({"description": "统一行业分类,可选"})),
|
|
215
|
+
as_of: Type.Optional(Type.String({"description": "实际估值时点,建议ISO8601"})),
|
|
216
|
+
lot_size: Type.Optional(Type.Number({"description": "正整数交易单位;weight>0时必填"})),
|
|
217
|
+
}, {"additionalProperties": false}), {"description": "1..100个目标;新标的price/currency必填"}),
|
|
218
|
+
fx_rates: Type.Optional(Type.Array(Type.Object({
|
|
219
|
+
currency: Type.String({"description": "唯一非基准币种"}),
|
|
220
|
+
rate: Type.Number({"description": "一单位该币种对应多少基准币种,正数"}),
|
|
221
|
+
}, {"additionalProperties": false}), {"description": "显式现价汇率;基准币种隐含1,不得重复"})),
|
|
222
|
+
fee_rate: Type.Optional(Type.Number({"description": "每边比例费用0..0.1,默认0;不含未提供税费/最低收费"})),
|
|
223
|
+
slippage_rate: Type.Optional(Type.Number({"description": "每边滑点0..0.1,默认0"})),
|
|
224
|
+
max_turnover_fraction: Type.Optional(Type.Number({"description": "非负最大总换手,按买卖参考金额合计/初始权益;默认不限制,可大于1"})),
|
|
225
|
+
}, {"additionalProperties": false}),
|
|
226
|
+
async execute(_id, params) {
|
|
227
|
+
return asText(await withJsonInput(params, (path: string) =>
|
|
228
|
+
runPy("stateless_analysis.py", ["rebalance", "--input", path])));
|
|
229
|
+
},
|
|
230
|
+
});
|
|
231
|
+
|
|
162
232
|
api.registerTool({
|
|
163
233
|
name: "calculate_position_size",
|
|
164
234
|
description: "无状态多头仓位预算:同币种金额,按现金/风险预算/最大仓位/交易单位取最小数量,双边费用和滑点参与止损情景;不执行交易。",
|
|
@@ -851,6 +921,48 @@ export default definePluginEntry({
|
|
|
851
921
|
},
|
|
852
922
|
});
|
|
853
923
|
|
|
924
|
+
api.registerTool({
|
|
925
|
+
name: "calculate_rotation_metrics",
|
|
926
|
+
description: "行业轮动数值复核:输入真实MC-dropout样本和/或历史成交计数,计算集中度和原始配权;不训练模型、不生成买入信号,零历史不补默认值。",
|
|
927
|
+
parameters: Type.Object({prediction_samples: Type.Optional(Type.Array(Type.Object({symbol: Type.String({"description": "唯一标的标识"}),
|
|
928
|
+
samples: Type.Array(Type.Number({"description": "同一模型/标的/时间的有限线性输出,不是价格或收益率"}), {"description": "2..100000个真实MC-dropout预测;不得用随机数或动量代替"})}, {"additionalProperties": false}), {"description": "1..100组,总样本<=100000;和trade_counts至少提供一项"})),
|
|
929
|
+
trade_counts: Type.Optional(Type.Array(Type.Object({symbol: Type.String({"description": "唯一标的标识;代码别名须先统一"}),
|
|
930
|
+
buys: Type.Number({"description": "此前已平仓买入周数,非负整数"}),
|
|
931
|
+
wins: Type.Number({"description": "此前盈利平仓次数,0..buys"}),
|
|
932
|
+
streak: Type.Number({"description": "此前连续盈利交易次数,0..wins"})}, {"additionalProperties": false}), {"description": "1..100条已完成历史成交计数;不得使用决策后的交易"}))}, {"additionalProperties": false}),
|
|
933
|
+
async execute(_id, params) {
|
|
934
|
+
return asText(await withJsonInput(params, (path: string) =>
|
|
935
|
+
runPy("sector_rotation.py", ["analyze", "--input", path])));
|
|
936
|
+
},
|
|
937
|
+
});
|
|
938
|
+
|
|
939
|
+
api.registerTool({
|
|
940
|
+
name: "backtest_rotation_allocation",
|
|
941
|
+
description: "行业轮动配权分项回测:代码自动取行情,或传明确币种/复权OHLCV;相同每周全池买卖下比较等权与历史配权。按市场和报价币种独立资金,支持A/HK/US/JP/KR/TW;不是完整论文深度模型或跨币种共享资金回测。",
|
|
942
|
+
parameters: Type.Object({symbols: Type.Optional(Type.Array(Type.String({"description": "唯一股票/ETF代码,按插件代码格式"}), {"description": "1..20只自动取数,与datasets互斥;任一失败整池停止"})),
|
|
943
|
+
datasets: Type.Optional(Type.Array(Type.Object({symbol: Type.String({"description": "A六位代码/HK如2800.HK/US如XLK/JP如1306.T/KR如069500.KS/TW如0050.TW"}),
|
|
944
|
+
currency: Type.String({"description": "已核实报价币种三字母代码,不按上市地猜测"}),
|
|
945
|
+
price_basis: Type.Union([Type.Literal("qfq"), Type.Literal("total_return"), Type.Literal("split_adjusted")], {"description": "已核实且一致的复权口径"}),
|
|
946
|
+
bars: Type.Array(Type.Object({date: Type.String({"description": "YYYY-MM-DD"}),
|
|
947
|
+
open: Type.Number({"description": "有限正OHLC价格;volume非负"}),
|
|
948
|
+
high: Type.Number({"description": "有限正OHLC价格;volume非负"}),
|
|
949
|
+
low: Type.Number({"description": "有限正OHLC价格;volume非负"}),
|
|
950
|
+
close: Type.Number({"description": "有限正OHLC价格;volume非负"}),
|
|
951
|
+
volume: Type.Number({"description": "有限正OHLC价格;volume非负"}),
|
|
952
|
+
adjusted: Type.Optional(Type.String({"description": "可选逐bar复权标记,存在时必须与price_basis一致"})),
|
|
953
|
+
source: Type.Optional(Type.String({"description": "可选行情来源标识,用于数据覆盖报告"}))}, {"additionalProperties": false}), {"description": "递增唯一daily OHLCV,2..20000行,包含评估前预热;总量<=100000"})}, {"additionalProperties": false}), {"description": "1..20个离线数据集,与symbols互斥;8MiB JSON输入上限"})),
|
|
954
|
+
start_date: Type.String({"description": "评估起始YYYY-MM-DD;跨边界周不交易,不能用评估期收益初始化配权"}),
|
|
955
|
+
end_date: Type.String({"description": "已收盘截止YYYY-MM-DD;不完整末周不成交"}),
|
|
956
|
+
history_start_date: Type.Optional(Type.String({"description": "仅代码模式;默认评估前一年,必须早于start_date"})),
|
|
957
|
+
warmup_weeks: Type.Optional(Type.Number({"description": "评估前完整历史交易周1..104整数,默认26;不足停止"})),
|
|
958
|
+
capital: Type.Optional(Type.Number({"description": "每市场/报价币种分组独立初始资金,默认1000000,不是混合池总额"})),
|
|
959
|
+
cost_per_side: Type.Optional(Type.Number({"description": "每边比例成本0..0.1,默认0.001;买入预算含费用"}))}, {"additionalProperties": false}),
|
|
960
|
+
async execute(_id, params) {
|
|
961
|
+
return asText(await withJsonInput(params, (path: string) =>
|
|
962
|
+
runPy("sector_rotation.py", ["backtest", "--input", path])));
|
|
963
|
+
},
|
|
964
|
+
});
|
|
965
|
+
|
|
854
966
|
api.registerTool({
|
|
855
967
|
name: "analyze_trend_strategy",
|
|
856
968
|
description: "月度右侧趋势策略:直接传同市场A/HK/US股票代码,自动获取日K,输出月度新入/持有/退出与逆波动预算。as_of默认最近已收盘交易日,持仓可选且不保存,不自动下单;跨样本仍not_validated。",
|
|
@@ -1343,8 +1455,11 @@ export default definePluginEntry({
|
|
|
1343
1455
|
api.registerTool({
|
|
1344
1456
|
name: "render_stock_report",
|
|
1345
1457
|
description:
|
|
1346
|
-
"股票分析报告渲染 — 将结构化报告 JSON 通过 j2 模板渲染为 Markdown。report 字段以 skill 提供的 report_schema 为准,不要自造字段。template: brief|full
|
|
1458
|
+
"股票分析报告渲染 — 将结构化报告 JSON 通过 j2 模板渲染为 Markdown。report 字段以 skill 提供的 report_schema 为准,不要自造字段。template: brief|full。全部分析完成后的最后一步调用。默认仅渲染;final=true表示最终回复,支持直出的宿主可原样交付并结束本轮。report可包含evidence(path/label/value/source/as_of)与data_quality(flags/limitations),brief/full均展示证据和限制。",
|
|
1459
|
+
canDeliverSourceReply: true,
|
|
1460
|
+
catalogMode: "direct-only",
|
|
1347
1461
|
parameters: Type.Object({
|
|
1462
|
+
final: Type.Optional(Type.Boolean({ description: "最终回复标记,默认false;保存附件或继续分析时保持false" })),
|
|
1348
1463
|
report: Type.Object({}, { additionalProperties: true, description: "结构化股票报告 JSON" }),
|
|
1349
1464
|
template: Type.Optional(
|
|
1350
1465
|
Type.Union([Type.Literal("brief"), Type.Literal("full")], {
|
|
@@ -1360,16 +1475,20 @@ export default definePluginEntry({
|
|
|
1360
1475
|
params.template ?? "full",
|
|
1361
1476
|
"--input-b64",
|
|
1362
1477
|
b64,
|
|
1478
|
+
...(params.final ? ["--final"] : []),
|
|
1363
1479
|
]);
|
|
1364
|
-
return
|
|
1480
|
+
return asReport(out);
|
|
1365
1481
|
},
|
|
1366
1482
|
});
|
|
1367
1483
|
|
|
1368
1484
|
api.registerTool({
|
|
1369
1485
|
name: "render_market_report",
|
|
1370
1486
|
description:
|
|
1371
|
-
"大盘复盘报告渲染 — 将结构化报告 JSON 通过 j2 模板渲染为 Markdown。report 字段以 schemas/market_review_schema.json 为准。save=true 时把报告对象追加归档到本地 JSONL(默认不保存不推送),纵向对比用 get_review_history",
|
|
1487
|
+
"大盘复盘报告渲染 — 将结构化报告 JSON 通过 j2 模板渲染为 Markdown。report 字段以 schemas/market_review_schema.json 为准。save=true 时把报告对象追加归档到本地 JSONL(默认不保存不推送),纵向对比用 get_review_history;final=true仅用于最终回复,保存附件或继续分析时保持false",
|
|
1488
|
+
canDeliverSourceReply: true,
|
|
1489
|
+
catalogMode: "direct-only",
|
|
1372
1490
|
parameters: Type.Object({
|
|
1491
|
+
final: Type.Optional(Type.Boolean({ description: "最终回复标记,默认false;保存附件或继续分析时保持false" })),
|
|
1373
1492
|
report: Type.Object({}, { additionalProperties: true, description: "结构化市场复盘" }),
|
|
1374
1493
|
save: Type.Optional(Type.Boolean({ description: "是否归档到本地复盘 JSONL 存储,默认 false" })),
|
|
1375
1494
|
}),
|
|
@@ -1379,9 +1498,10 @@ export default definePluginEntry({
|
|
|
1379
1498
|
"market",
|
|
1380
1499
|
"--input-b64",
|
|
1381
1500
|
b64,
|
|
1501
|
+
...(params.final ? ["--final"] : []),
|
|
1382
1502
|
...(params.save ? ["--save"] : []),
|
|
1383
1503
|
]);
|
|
1384
|
-
return
|
|
1504
|
+
return asReport(out);
|
|
1385
1505
|
},
|
|
1386
1506
|
});
|
|
1387
1507
|
|
package/openclaw.plugin.json
CHANGED
|
@@ -67,11 +67,14 @@
|
|
|
67
67
|
"compare_stocks",
|
|
68
68
|
"analyze_disclosure_changes",
|
|
69
69
|
"analyze_portfolio_risk",
|
|
70
|
+
"plan_portfolio_rebalance",
|
|
70
71
|
"calculate_position_size",
|
|
71
72
|
"analyze_event_study",
|
|
72
73
|
"validate_backtest",
|
|
73
74
|
"compare_analysis_snapshots",
|
|
74
|
-
"analyze_trend_strategy"
|
|
75
|
+
"analyze_trend_strategy",
|
|
76
|
+
"calculate_rotation_metrics",
|
|
77
|
+
"backtest_rotation_allocation"
|
|
75
78
|
]
|
|
76
79
|
},
|
|
77
80
|
"activation": {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@weaxs/openclaw-stock-analysis",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.10",
|
|
4
4
|
"description": "OpenClaw plugin for stock analysis, screening, and strategy backtesting across A/HK/US/JP/KR/TW markets",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./index.ts",
|
|
@@ -13,8 +13,8 @@
|
|
|
13
13
|
"minGatewayVersion": "2026.3.24-beta.2"
|
|
14
14
|
},
|
|
15
15
|
"build": {
|
|
16
|
-
"openclawVersion": "2026.
|
|
17
|
-
"pluginSdkVersion": "2026.
|
|
16
|
+
"openclawVersion": "2026.10.9",
|
|
17
|
+
"pluginSdkVersion": "2026.10.9"
|
|
18
18
|
}
|
|
19
19
|
},
|
|
20
20
|
"scripts": {
|
|
@@ -27,6 +27,7 @@
|
|
|
27
27
|
"README.md",
|
|
28
28
|
"tools/",
|
|
29
29
|
"skills/",
|
|
30
|
+
"!skills/**/__pycache__/**",
|
|
30
31
|
"schemas/",
|
|
31
32
|
"templates/",
|
|
32
33
|
"strategies/",
|