@weaxs/openclaw-stock-analysis 0.2.4 → 0.2.5
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/dist/index.js +90 -7
- package/index.ts +95 -6
- package/openclaw.plugin.json +7 -1
- package/package.json +1 -1
- package/skills/event-driven/SKILL.md +6 -0
- package/skills/growth-quality/SKILL.md +6 -0
- package/skills/stock-analysis/SKILL.md +22 -0
- package/skills/stock-screener/SKILL.md +18 -0
- package/skills/strategy-backtest/SKILL.md +2 -0
- package/tools/_cache.py +61 -0
- package/tools/capabilities.py +9 -0
- package/tools/diagnostics.py +6 -0
- package/tools/screener.py +54 -2
- package/tools/stock_data.py +241 -99
- package/tools/value_data.py +1368 -0
package/dist/index.js
CHANGED
|
@@ -4456,9 +4456,88 @@ var index_default = definePluginEntry({
|
|
|
4456
4456
|
return isWin ? "python" : "python3";
|
|
4457
4457
|
};
|
|
4458
4458
|
const runPy = (script, args) => executor(pythonBin(), [join(toolsDir, script), ...args]);
|
|
4459
|
+
api.registerTool({
|
|
4460
|
+
name: "get_valuation_history",
|
|
4461
|
+
description: "\u67E5\u8BE2A/HK\u80A1\u7968\u5386\u53F2 PE-TTM/PB\u3001\u5F53\u524D\u6B63\u503C\u5206\u4F4D\u548C10/25/50/75/90\u5206\u4F4D Band\uFF0C\u8FD4\u56DE\u5B9E\u9645\u91C7\u6837\u533A\u95F4\uFF1B\u4E8F\u635F\u4F30\u503C\u5206\u4F4D\u4E3Anull\u3002years=1..10\uFF0C\u6570\u636E\u6309\u5929\u7F13\u5B58\u3002",
|
|
4462
|
+
parameters: typebox_exports.Object({
|
|
4463
|
+
symbol: typebox_exports.String({ description: "A\u80A1\u4EE3\u7801\u6216\u6E2F\u80A1.HK\u4EE3\u7801" }),
|
|
4464
|
+
years: typebox_exports.Optional(typebox_exports.Number({ description: "\u5386\u53F2\u7A97\u53E3\u5E74\u65701..10\uFF0C\u9ED8\u8BA45" }))
|
|
4465
|
+
}),
|
|
4466
|
+
async execute(_id, p) {
|
|
4467
|
+
const out = await runPy("value_data.py", ["valuation_history", p.symbol, "--years", String(p.years ?? 5)]);
|
|
4468
|
+
return asText(out);
|
|
4469
|
+
}
|
|
4470
|
+
});
|
|
4471
|
+
api.registerTool({
|
|
4472
|
+
name: "get_index_valuation",
|
|
4473
|
+
description: "\u67E5\u8BE2\u4E2D\u56FD\u6307\u6570\u4F30\u503C\u5386\u53F2\u5206\u4F4D\u4E0EBand\uFF1B\u4E50\u5495\u4E50\u80A1PE/PB\u4F18\u5148\uFF0C\u4E2D\u8BC1\u5B98\u65B9\u5386\u53F2\u8865\u5145\u6EDA\u52A8PE\u5E76\u4FDD\u7559\u8FD1\u671FPE1\u53E3\u5F84\u3002\u7F3APB\u65F6\u53EF\u7528LIXINGER_TOKEN\u8865\u5145\u7406\u674F\u4EC1mcw\u5386\u53F2\uFF0C\u6765\u6E90\u4E0E\u7B97\u6CD5\u5206\u522B\u6807\u660E\uFF0C\u4E0D\u6DF7\u63A5\u540C\u4E00\u6307\u6807\u3002",
|
|
4474
|
+
parameters: typebox_exports.Object({
|
|
4475
|
+
symbol: typebox_exports.String({ description: "\u6307\u6570\u4EE3\u7801\u6216\u540D\u79F0\uFF0C\u5982000300\u3001\u6CAA\u6DF1300\u3001000985" }),
|
|
4476
|
+
years: typebox_exports.Optional(typebox_exports.Number({ description: "\u5386\u53F2\u7A97\u53E3\u5E74\u65701..10\uFF0C\u9ED8\u8BA45" }))
|
|
4477
|
+
}),
|
|
4478
|
+
async execute(_id, p) {
|
|
4479
|
+
const out = await runPy("value_data.py", ["index_valuation", p.symbol, "--years", String(p.years ?? 5)]);
|
|
4480
|
+
return asText(out);
|
|
4481
|
+
}
|
|
4482
|
+
});
|
|
4483
|
+
api.registerTool({
|
|
4484
|
+
name: "get_earnings_calendar",
|
|
4485
|
+
description: "\u67E5\u8BE2\u8D22\u62A5\u65E5\u5386\uFF1AA\u80A1report_date\u5FC5\u586B\u5B63\u5EA6\u671F\u672B\uFF0C\u8FD4\u56DE\u9884\u7EA6/\u4FEE\u8BA2/\u5B9E\u9645\u62AB\u9732\u4E0E\u4E1A\u7EE9\u9884\u544A\uFF1BHK\u9700symbol\uFF0C\u4F18\u5148HKEX\u5DF2\u516C\u544A\u4E1A\u7EE9\u5BA1\u6279\u8463\u4E8B\u4F1A\u6392\u671F\uFF08\u4E0D\u662F\u5B9E\u9645\u62AB\u9732\u65E5\uFF09\uFF0C\u7F3A\u5931\u65F6\u8FD4\u56DE\u4F9B\u5E94\u5546\u65E5\u671F\u3002HK\u53EF\u6309\u5DF2\u77E5\u8D22\u653F\u671F\u672B\u8FC7\u6EE4\uFF0C\u672A\u77E5\u671F\u6B21\u53E6\u5217\u3002",
|
|
4486
|
+
parameters: typebox_exports.Object({
|
|
4487
|
+
report_date: typebox_exports.Optional(typebox_exports.String({ description: "A\u80A1\u5FC5\u586B\u5B63\u5EA6\u671F\u672BYYYY-MM-DD\uFF1BHK\u53EF\u9009\u5DF2\u516C\u544A\u8D22\u653F\u671F\u672B\uFF0C\u672A\u77E5\u671F\u6B21\u53E6\u5217" })),
|
|
4488
|
+
symbol: typebox_exports.Optional(typebox_exports.String({ description: "A\u80A1\u4EE3\u7801\u53EF\u9009\uFF08\u7701\u7565\u67E5\u5168\u5E02\u573A\uFF09\uFF1BHK\u5FC5\u987B\u63D0\u4F9B\u6E2F\u80A1.HK\u4EE3\u7801" })),
|
|
4489
|
+
top: typebox_exports.Optional(typebox_exports.Number({ description: "\u6BCF\u7C7B\u6700\u591A\u8FD4\u56DE\u6761\u65701..500\uFF0C\u9ED8\u8BA450" }))
|
|
4490
|
+
}),
|
|
4491
|
+
async execute(_id, p) {
|
|
4492
|
+
const out = await runPy("value_data.py", ["earnings_calendar", "--report-date", p.report_date ?? "", "--symbol", p.symbol ?? "", "--top", String(p.top ?? 50)]);
|
|
4493
|
+
return asText(out);
|
|
4494
|
+
}
|
|
4495
|
+
});
|
|
4496
|
+
api.registerTool({
|
|
4497
|
+
name: "get_shareholder_structure",
|
|
4498
|
+
description: "\u67E5\u8BE2A\u80A1\u80A1\u4E1C\u6237\u6570\u3001\u5341\u5927\u6D41\u901A\u80A1\u4E1C\u53D8\u5316\u53CA\u6CAA\u6DF1\u4EA4\u6613\u6240\u5B63\u5EA6\u5317\u5411\u5408\u8BA1\u6301\u80A1\uFF1B\u5B98\u65B9\u603B\u91CF\u4F18\u5148\uFF0C\u5341\u5927HKSCC\u540D\u4E49\u6301\u80A1\u4EC5\u515C\u5E95\u4E14\u6807\u660E\u53E3\u5F84\u3002HK\u8FD4\u56DE\u6E2F\u4EA4\u6240\u5357\u5411\u8BB0\u5F55\u3002\u7F3A\u5931\u4E0D\u5F53\u96F6\uFF0C\u671F\u672B\u4E0D\u7B49\u4E8E\u5DF2\u516C\u5E03\u3002",
|
|
4499
|
+
parameters: typebox_exports.Object({
|
|
4500
|
+
symbol: typebox_exports.String({ description: "A\u80A1\u4EE3\u7801\u6216\u6E2F\u80A1.HK\u4EE3\u7801" }),
|
|
4501
|
+
report_date: typebox_exports.Optional(typebox_exports.String({ description: "A\u80A1\u62A5\u544A\u671FYYYY-MM-DD\uFF1B\u7701\u7565\u65F6\u5317\u5411\u4F7F\u7528\u6700\u65B0\u5DF2\u516C\u5E03\u5B63\u5EA6\uFF0C\u5341\u5927\u80A1\u4E1C\u4F7F\u7528\u6700\u65B0\u8D22\u62A5\u671F\uFF1BHK\u5FFD\u7565" }))
|
|
4502
|
+
}),
|
|
4503
|
+
async execute(_id, p) {
|
|
4504
|
+
const out = await runPy("value_data.py", ["shareholder_structure", p.symbol, "--report-date", p.report_date ?? ""]);
|
|
4505
|
+
return asText(out);
|
|
4506
|
+
}
|
|
4507
|
+
});
|
|
4508
|
+
api.registerTool({
|
|
4509
|
+
name: "get_etf_details",
|
|
4510
|
+
description: "\u67E5\u8BE2A\u80A1ETF\u51C0\u503C\u6298\u6EA2\u4EF7\u3001\u89C4\u6A21\u3001\u62AB\u9732\u6301\u4ED3\u53CA\u6CAA\u6DF1\u5B8C\u6574PCF\u7533\u8D4E\u7BEE\u5B50\uFF1B\u7BEE\u5B50\u4E0D\u662F\u5B9E\u9645\u6301\u4ED3\u3002include_full_holdings=true\u53E6\u53D6\u6700\u8FD1\u53EF\u5F97\u534A\u5E74\u5EA6/\u5E74\u5EA6\u62AB\u9732\u80A1\u7968\u8868\uFF0C\u542B\u6570\u91CF/\u5E02\u503C/\u62A5\u544A\u671F\uFF0C\u975E\u5B9E\u65F6\u5168\u8D44\u4EA7\u7EC4\u5408\uFF1Bbenchmark\u7528\u4E8E\u8DDF\u8E2A\u8BEF\u5DEE\u3002",
|
|
4511
|
+
parameters: typebox_exports.Object({
|
|
4512
|
+
include_full_holdings: typebox_exports.Optional(typebox_exports.Boolean({ description: "\u8BF7\u6C42\u534A\u5E74\u5EA6/\u5E74\u5EA6\u62AB\u9732\u80A1\u7968\u8868\uFF0C\u9ED8\u8BA4false" })),
|
|
4513
|
+
symbol: typebox_exports.String({ description: "A\u80A1ETF\u4EE3\u7801\uFF0C\u5982510300" }),
|
|
4514
|
+
benchmark: typebox_exports.Optional(typebox_exports.String({ description: "\u53EF\u9009\u57FA\u51C6\u4EE3\u7801\uFF0C\u5982sh000300\uFF1B\u4E0D\u731C\u6D4B\u57FA\u51C6" })),
|
|
4515
|
+
days: typebox_exports.Optional(typebox_exports.Number({ description: "\u51C0\u503C\u7A97\u53E3\u4EA4\u6613\u65E5\u657010..252\uFF0C\u9ED8\u8BA460" }))
|
|
4516
|
+
}),
|
|
4517
|
+
async execute(_id, p) {
|
|
4518
|
+
const out = await runPy("value_data.py", ["etf_details", p.symbol, "--benchmark", p.benchmark ?? "", "--days", String(p.days ?? 60), ...p.include_full_holdings ? ["--include-full-holdings"] : []]);
|
|
4519
|
+
return asText(out);
|
|
4520
|
+
}
|
|
4521
|
+
});
|
|
4522
|
+
api.registerTool({
|
|
4523
|
+
name: "get_dividends",
|
|
4524
|
+
description: "\u67E5\u8BE2A/HK\u5206\u7EA2\u5386\u53F2\u3001\u9664\u606F\u65E5\u5386\u3001\u5DF2\u5B9E\u65BDTTM\u80A1\u606F\u4E0E\u8FDE\u7EED\u5E74\u6570\u3002mode=ranking\u7701\u7565symbol\uFF0Cmarket=A\u67E5\u62A5\u544A\u671F\u6392\u884C\uFF0Cmarket=HK\u67E5HKEX/LSEG\u5E74\u5EA6\u80A1\u606F\u7387\u6392\u884C\uFF08report_date\u987B\u5E74\u672B\uFF09\uFF1B\u6392\u884C\u5747\u975E\u5F53\u524DTTM\u6536\u76CA\u7387\u3002\u7F3A\u5931\u4E0D\u6309\u96F6\u3002",
|
|
4525
|
+
parameters: typebox_exports.Object({
|
|
4526
|
+
market: typebox_exports.Optional(typebox_exports.Union([typebox_exports.Literal("A"), typebox_exports.Literal("HK")], { description: "\u4EC5ranking\u9009\u62E9\u5E02\u573A\uFF0C\u9ED8\u8BA4A" })),
|
|
4527
|
+
symbol: typebox_exports.Optional(typebox_exports.String({ description: "history/calendar\u5FC5\u586BA\u80A1\u6216\u6E2F\u80A1.HK\u4EE3\u7801\uFF1Branking\u7701\u7565" })),
|
|
4528
|
+
mode: typebox_exports.Optional(typebox_exports.Union([typebox_exports.Literal("history"), typebox_exports.Literal("calendar"), typebox_exports.Literal("ranking")], { description: "history\u9ED8\u8BA4\uFF1Bcalendar\u672A\u6765\u5DF2\u516C\u5E03\u9664\u606F\u4E8B\u4EF6\uFF1Branking\u6309market\u67E5\u8BE2A/HK\u6392\u884C" })),
|
|
4529
|
+
report_date: typebox_exports.Optional(typebox_exports.String({ description: "ranking\u62A5\u544A\u671FYYYY-MM-DD\uFF0C\u9ED8\u8BA4\u4E0A\u4E00\u5E74\u5E74\u672B\uFF1BHK\u4EC5\u5E74\u5EA6\u5E74\u672B\u65E5\u671F" })),
|
|
4530
|
+
years: typebox_exports.Optional(typebox_exports.Number({ description: "\u5386\u53F2\u7A97\u53E3\u5E74\u65701..20\uFF0C\u9ED8\u8BA410" })),
|
|
4531
|
+
top: typebox_exports.Optional(typebox_exports.Number({ description: "\u6392\u540D\u6761\u65701..500\uFF0C\u9ED8\u8BA420" }))
|
|
4532
|
+
}),
|
|
4533
|
+
async execute(_id, p) {
|
|
4534
|
+
const out = await runPy("value_data.py", ["dividends", "--market", p.market ?? "A", "--symbol", p.symbol ?? "", "--mode", p.mode ?? "history", "--report-date", p.report_date ?? "", "--years", String(p.years ?? 10), "--top", String(p.top ?? 20)]);
|
|
4535
|
+
return asText(out);
|
|
4536
|
+
}
|
|
4537
|
+
});
|
|
4459
4538
|
api.registerTool({
|
|
4460
4539
|
name: "get_kline",
|
|
4461
|
-
description: "\u83B7\u53D6\u80A1\u7968K\u7EBF\u6570\u636E\uFF08OHLCV\uFF09\u3002\u652F\u6301A\u80A1\uFF08\u5982600519\uFF09\u3001\u6E2F\u80A1\uFF08\u598200700.HK\uFF09\u3001\u7F8E\u80A1\uFF08\u5982AAPL\uFF09\u3001\u65E5\u80A1\uFF08\u59827203.T\uFF09\u3001\u97E9\u80A1\uFF08\u5982005930.KS\uFF09\u3001\u53F0\u80A1\uFF08\u59822330.TW\uFF09\u53CAA\u80A1ETF\
|
|
4540
|
+
description: "\u83B7\u53D6\u80A1\u7968K\u7EBF\u6570\u636E\uFF08OHLCV\uFF09\u3002\u652F\u6301A\u80A1\uFF08\u5982600519\uFF09\u3001\u6E2F\u80A1\uFF08\u598200700.HK\uFF09\u3001\u7F8E\u80A1\uFF08\u5982AAPL\uFF09\u3001\u65E5\u80A1\uFF08\u59827203.T\uFF09\u3001\u97E9\u80A1\uFF08\u5982005930.KS\uFF09\u3001\u53F0\u80A1\uFF08\u59822330.TW\uFF09\u53CAA\u80A1ETF\u3002A\u80A1\u80A1\u7968/ETF\u8FD4\u56DE\u524D\u590D\u6743\u4EF7\u683C\uFF0C\u6BCF\u6761\u8BB0\u5F55 adjusted=qfq\uFF1Bsh000xxx/sz399xxx \u6307\u6570\u8FD4\u56DE\u539F\u59CB\u70B9\u4F4D\uFF0Cadjusted=none\u3002\u9700\u8981\u5386\u53F2\u4EF7\u683C\u81EA\u884C\u8BA1\u7B97\u6216\u753B\u56FE\u65F6\u7528\uFF1B\u53EA\u95EE\u6307\u6807\u7528 get_technical_analysis\uFF0C\u53EA\u95EE\u73B0\u4EF7\u7528 get_quote",
|
|
4462
4541
|
parameters: typebox_exports.Object({
|
|
4463
4542
|
symbol: typebox_exports.String({
|
|
4464
4543
|
description: "\u80A1\u7968\u4EE3\u7801\uFF0C\u5982 600519\uFF08A\u80A1\uFF09\u300100700.HK\uFF08\u6E2F\u80A1\uFF09\u3001AAPL\uFF08\u7F8E\u80A1\uFF09\u30017203.T\uFF08\u65E5\u80A1\uFF09\u3001005930.KS\uFF08\u97E9\u80A1\uFF09\u30012330.TW\uFF08\u53F0\u80A1\uFF09"
|
|
@@ -4541,16 +4620,18 @@ var index_default = definePluginEntry({
|
|
|
4541
4620
|
});
|
|
4542
4621
|
api.registerTool({
|
|
4543
4622
|
name: "get_financials",
|
|
4544
|
-
description: "\u83B7\u53D6\u80A1\u7968\u8D22\u52A1\u6458\u8981\
|
|
4623
|
+
description: "\u83B7\u53D6\u80A1\u7968\u8D22\u52A1\u6458\u8981\u53CA\u5386\u53F2\u8D8B\u52BF\uFF0C\u6309\u5929\u7F13\u5B58\u3002A\u80A1\u8FD4\u56DEROE/\u6BDB\u5229\u7387/\u51C0\u5229\u7387\u7B49\uFF1Bannual=true\u4E0Eperiods=10\u53D6\u5341\u5E74\u5E74\u62A5\uFF0C\u6E2F\u80A1\u5E74\u5EA6\u5386\u53F2\u6309\u6570\u636E\u6E90\u5B9E\u9645\u53EF\u5F97\u671F\u6570\u8FD4\u56DE\u3002\u4F30\u503C\u5386\u53F2\u7528get_valuation_history\uFF0C\u62AB\u9732\u6392\u671F\u7528get_earnings_calendar",
|
|
4545
4624
|
parameters: typebox_exports.Object({
|
|
4546
4625
|
symbol: typebox_exports.String({ description: "\u80A1\u7968\u4EE3\u7801\uFF08A\u80A1\u5982600519\uFF0C\u7F8E\u80A1\u5982AAPL\uFF0C\u6E2F\u80A1\u598200700.HK\uFF09" }),
|
|
4626
|
+
annual: typebox_exports.Optional(typebox_exports.Boolean({ description: "\u53EA\u53D6\u5E74\u5EA6\u62A5\u544A\uFF0C\u9ED8\u8BA4false" })),
|
|
4547
4627
|
periods: typebox_exports.Optional(
|
|
4548
|
-
typebox_exports.Number({ description: "\u8FD4\u56DE\u6700\u8FD1N\u4E2A\u62A5\u544A\
|
|
4628
|
+
typebox_exports.Number({ description: "\u8FD4\u56DE\u6700\u8FD1N\u4E2A\u62A5\u544A\u671F1..40\uFF0C\u9ED8\u8BA41\uFF1Bannual=true\u65F6periods=10\u8BF7\u6C4210\u5E74\u5E74\u62A5" })
|
|
4549
4629
|
)
|
|
4550
4630
|
}),
|
|
4551
4631
|
async execute(_id, params) {
|
|
4552
4632
|
const args = ["financials", params.symbol];
|
|
4553
|
-
if (params.periods && params.periods
|
|
4633
|
+
if (params.periods !== void 0 && params.periods !== 1) args.push("--periods", String(params.periods));
|
|
4634
|
+
if (params.annual) args.push("--annual");
|
|
4554
4635
|
const out = await runPy("stock_data.py", args);
|
|
4555
4636
|
return asText(out);
|
|
4556
4637
|
}
|
|
@@ -4671,7 +4752,7 @@ var index_default = definePluginEntry({
|
|
|
4671
4752
|
});
|
|
4672
4753
|
api.registerTool({
|
|
4673
4754
|
name: "get_sector_constituents",
|
|
4674
|
-
description: "\u67E5\u8BE2A\u80A1\u677F\u5757\u6210\u5206\u80A1\uFF08\u6B63\u5411\u6620\u5C04\uFF1A\u677F\u5757\u2192\u80A1\u7968\u5217\u8868\uFF09\u3002\u677F\u5757\u540D\u652F\u6301\u6A21\u7CCA\u5339\u914D\uFF08\u5982\u300C\u521B\u65B0\u836F\u300D\u81EA\u52A8\u89E3\u6790\u5230\u7CBE\u786E\u677F\u5757\u540D\uFF09\uFF0C\u4E1C\u8D22\u884C\u4E1A/\u6982\u5FF5 + \u65B0\u6D6A\u591A\u6E90 failover\uFF0C\u7ED3\u679C\u7F13\
|
|
4755
|
+
description: "\u67E5\u8BE2A\u80A1\u677F\u5757\u6210\u5206\u80A1\uFF08\u6B63\u5411\u6620\u5C04\uFF1A\u677F\u5757\u2192\u80A1\u7968\u5217\u8868\uFF09\u3002\u677F\u5757\u540D\u652F\u6301\u6A21\u7CCA\u5339\u914D\uFF08\u5982\u300C\u521B\u65B0\u836F\u300D\u81EA\u52A8\u89E3\u6790\u5230\u7CBE\u786E\u677F\u5757\u540D\uFF09\uFF0C\u4E1C\u8D22\u884C\u4E1A/\u6982\u5FF5 + \u65B0\u6D6A\u591A\u6E90 failover\uFF0C\u7ED3\u679C\u6309\u7528\u6237\u76EE\u5F55\u7F13\u5B587\u5929\u3002\u4EC5\u652F\u6301A\u80A1\uFF1B\u53CD\u5411\u67E5\u4E2A\u80A1\u6240\u5C5E\u677F\u5757\u7528 resolve_stock_sectors",
|
|
4675
4756
|
parameters: typebox_exports.Object({
|
|
4676
4757
|
sector: typebox_exports.String({ description: "\u677F\u5757\u540D\u79F0\uFF08\u53EF\u6A21\u7CCA\uFF0C\u5982 \u521B\u65B0\u836F\u3001\u534A\u5BFC\u4F53\uFF09" }),
|
|
4677
4758
|
board_type: typebox_exports.Optional(
|
|
@@ -4796,9 +4877,10 @@ var index_default = definePluginEntry({
|
|
|
4796
4877
|
});
|
|
4797
4878
|
api.registerTool({
|
|
4798
4879
|
name: "get_margin_trading",
|
|
4799
|
-
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",
|
|
4880
|
+
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\u3002include_ratio=true\u8FFD\u52A0\u540C\u65E5\u878D\u8D44\u4E70\u5165/\u6210\u4EA4\u989D\u767E\u5206\u6BD4\uFF08margin_buy_ratio_pct\uFF09\uFF0C\u7F3A\u5C11\u540C\u65E5\u5143\u53E3\u5F84\u6210\u4EA4\u989D\u5219\u4E3Anull\u3002\u4EC5\u4E24\u878D\u6807\u7684\u6709\u6570\u636E\uFF0C\u975E\u4E24\u878D\u6807\u7684\u8FD4\u56DE\u9519\u8BEF",
|
|
4800
4881
|
parameters: typebox_exports.Object({
|
|
4801
4882
|
symbol: typebox_exports.String({ description: "A\u80A1\u80A1\u7968\u4EE3\u7801\uFF0C\u5982 600519" }),
|
|
4883
|
+
include_ratio: typebox_exports.Optional(typebox_exports.Boolean({ description: "\u8FFD\u52A0\u540C\u65E5\u878D\u8D44\u4E70\u5165\u5360\u6BD4\uFF0C\u9ED8\u8BA4false" })),
|
|
4802
4884
|
days: typebox_exports.Optional(
|
|
4803
4885
|
typebox_exports.Number({ description: "\u8FD4\u56DE\u6700\u8FD1N\u4E2A\u4EA4\u6613\u65E5\uFF0C\u9ED8\u8BA4 10" })
|
|
4804
4886
|
)
|
|
@@ -4808,7 +4890,8 @@ var index_default = definePluginEntry({
|
|
|
4808
4890
|
"margin_trading",
|
|
4809
4891
|
params.symbol,
|
|
4810
4892
|
"--days",
|
|
4811
|
-
String(params.days ?? 10)
|
|
4893
|
+
String(params.days ?? 10),
|
|
4894
|
+
...params.include_ratio ? ["--include-ratio"] : []
|
|
4812
4895
|
]);
|
|
4813
4896
|
return asText(out);
|
|
4814
4897
|
}
|
package/index.ts
CHANGED
|
@@ -55,10 +55,95 @@ export default definePluginEntry({
|
|
|
55
55
|
executor(pythonBin(), [join(toolsDir, script), ...args]);
|
|
56
56
|
// --- Data Tools ---
|
|
57
57
|
|
|
58
|
+
api.registerTool({
|
|
59
|
+
name: "get_valuation_history",
|
|
60
|
+
description: "查询A/HK股票历史 PE-TTM/PB、当前正值分位和10/25/50/75/90分位 Band,返回实际采样区间;亏损估值分位为null。years=1..10,数据按天缓存。",
|
|
61
|
+
parameters: Type.Object({
|
|
62
|
+
symbol: Type.String({ description: "A股代码或港股.HK代码" }),
|
|
63
|
+
years: Type.Optional(Type.Number({ description: "历史窗口年数1..10,默认5" })),
|
|
64
|
+
}),
|
|
65
|
+
async execute(_id, p) {
|
|
66
|
+
const out = await runPy("value_data.py", ["valuation_history", p.symbol, "--years", String(p.years ?? 5)]);
|
|
67
|
+
return asText(out);
|
|
68
|
+
},
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
api.registerTool({
|
|
72
|
+
name: "get_index_valuation",
|
|
73
|
+
description: "查询中国指数估值历史分位与Band;乐咕乐股PE/PB优先,中证官方历史补充滚动PE并保留近期PE1口径。缺PB时可用LIXINGER_TOKEN补充理杏仁mcw历史,来源与算法分别标明,不混接同一指标。",
|
|
74
|
+
parameters: Type.Object({
|
|
75
|
+
symbol: Type.String({ description: "指数代码或名称,如000300、沪深300、000985" }),
|
|
76
|
+
years: Type.Optional(Type.Number({ description: "历史窗口年数1..10,默认5" })),
|
|
77
|
+
}),
|
|
78
|
+
async execute(_id, p) {
|
|
79
|
+
const out = await runPy("value_data.py", ["index_valuation", p.symbol, "--years", String(p.years ?? 5)]);
|
|
80
|
+
return asText(out);
|
|
81
|
+
},
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
api.registerTool({
|
|
85
|
+
name: "get_earnings_calendar",
|
|
86
|
+
description: "查询财报日历:A股report_date必填季度期末,返回预约/修订/实际披露与业绩预告;HK需symbol,优先HKEX已公告业绩审批董事会排期(不是实际披露日),缺失时返回供应商日期。HK可按已知财政期末过滤,未知期次另列。",
|
|
87
|
+
parameters: Type.Object({
|
|
88
|
+
report_date: Type.Optional(Type.String({ description: "A股必填季度期末YYYY-MM-DD;HK可选已公告财政期末,未知期次另列" })),
|
|
89
|
+
symbol: Type.Optional(Type.String({ description: "A股代码可选(省略查全市场);HK必须提供港股.HK代码" })),
|
|
90
|
+
top: Type.Optional(Type.Number({ description: "每类最多返回条数1..500,默认50" })),
|
|
91
|
+
}),
|
|
92
|
+
async execute(_id, p) {
|
|
93
|
+
const out = await runPy("value_data.py", ["earnings_calendar", "--report-date", p.report_date ?? "", "--symbol", p.symbol ?? "", "--top", String(p.top ?? 50)]);
|
|
94
|
+
return asText(out);
|
|
95
|
+
},
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
api.registerTool({
|
|
99
|
+
name: "get_shareholder_structure",
|
|
100
|
+
description: "查询A股股东户数、十大流通股东变化及沪深交易所季度北向合计持股;官方总量优先,十大HKSCC名义持股仅兜底且标明口径。HK返回港交所南向记录。缺失不当零,期末不等于已公布。",
|
|
101
|
+
parameters: Type.Object({
|
|
102
|
+
symbol: Type.String({ description: "A股代码或港股.HK代码" }),
|
|
103
|
+
report_date: Type.Optional(Type.String({ description: "A股报告期YYYY-MM-DD;省略时北向使用最新已公布季度,十大股东使用最新财报期;HK忽略" })),
|
|
104
|
+
}),
|
|
105
|
+
async execute(_id, p) {
|
|
106
|
+
const out = await runPy("value_data.py", ["shareholder_structure", p.symbol, "--report-date", p.report_date ?? ""]);
|
|
107
|
+
return asText(out);
|
|
108
|
+
},
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
api.registerTool({
|
|
112
|
+
name: "get_etf_details",
|
|
113
|
+
description: "查询A股ETF净值折溢价、规模、披露持仓及沪深完整PCF申赎篮子;篮子不是实际持仓。include_full_holdings=true另取最近可得半年度/年度披露股票表,含数量/市值/报告期,非实时全资产组合;benchmark用于跟踪误差。",
|
|
114
|
+
parameters: Type.Object({
|
|
115
|
+
include_full_holdings: Type.Optional(Type.Boolean({ description: "请求半年度/年度披露股票表,默认false" })),
|
|
116
|
+
symbol: Type.String({ description: "A股ETF代码,如510300" }),
|
|
117
|
+
benchmark: Type.Optional(Type.String({ description: "可选基准代码,如sh000300;不猜测基准" })),
|
|
118
|
+
days: Type.Optional(Type.Number({ description: "净值窗口交易日数10..252,默认60" })),
|
|
119
|
+
}),
|
|
120
|
+
async execute(_id, p) {
|
|
121
|
+
const out = await runPy("value_data.py", ["etf_details", p.symbol, "--benchmark", p.benchmark ?? "", "--days", String(p.days ?? 60), ...(p.include_full_holdings ? ["--include-full-holdings"] : [])]);
|
|
122
|
+
return asText(out);
|
|
123
|
+
},
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
api.registerTool({
|
|
127
|
+
name: "get_dividends",
|
|
128
|
+
description: "查询A/HK分红历史、除息日历、已实施TTM股息与连续年数。mode=ranking省略symbol,market=A查报告期排行,market=HK查HKEX/LSEG年度股息率排行(report_date须年末);排行均非当前TTM收益率。缺失不按零。",
|
|
129
|
+
parameters: Type.Object({
|
|
130
|
+
market: Type.Optional(Type.Union([Type.Literal("A"), Type.Literal("HK")], { description: "仅ranking选择市场,默认A" })),
|
|
131
|
+
symbol: Type.Optional(Type.String({ description: "history/calendar必填A股或港股.HK代码;ranking省略" })),
|
|
132
|
+
mode: Type.Optional(Type.Union([Type.Literal("history"), Type.Literal("calendar"), Type.Literal("ranking")], { description: "history默认;calendar未来已公布除息事件;ranking按market查询A/HK排行" })),
|
|
133
|
+
report_date: Type.Optional(Type.String({ description: "ranking报告期YYYY-MM-DD,默认上一年年末;HK仅年度年末日期" })),
|
|
134
|
+
years: Type.Optional(Type.Number({ description: "历史窗口年数1..20,默认10" })),
|
|
135
|
+
top: Type.Optional(Type.Number({ description: "排名条数1..500,默认20" })),
|
|
136
|
+
}),
|
|
137
|
+
async execute(_id, p) {
|
|
138
|
+
const out = await runPy("value_data.py", ["dividends", "--market", p.market ?? "A", "--symbol", p.symbol ?? "", "--mode", p.mode ?? "history", "--report-date", p.report_date ?? "", "--years", String(p.years ?? 10), "--top", String(p.top ?? 20)]);
|
|
139
|
+
return asText(out);
|
|
140
|
+
},
|
|
141
|
+
});
|
|
142
|
+
|
|
58
143
|
api.registerTool({
|
|
59
144
|
name: "get_kline",
|
|
60
145
|
description:
|
|
61
|
-
"获取股票K线数据(OHLCV)。支持A股(如600519)、港股(如00700.HK)、美股(如AAPL)、日股(如7203.T)、韩股(如005930.KS)、台股(如2330.TW)及A股ETF
|
|
146
|
+
"获取股票K线数据(OHLCV)。支持A股(如600519)、港股(如00700.HK)、美股(如AAPL)、日股(如7203.T)、韩股(如005930.KS)、台股(如2330.TW)及A股ETF。A股股票/ETF返回前复权价格,每条记录 adjusted=qfq;sh000xxx/sz399xxx 指数返回原始点位,adjusted=none。需要历史价格自行计算或画图时用;只问指标用 get_technical_analysis,只问现价用 get_quote",
|
|
62
147
|
parameters: Type.Object({
|
|
63
148
|
symbol: Type.String({
|
|
64
149
|
description: "股票代码,如 600519(A股)、00700.HK(港股)、AAPL(美股)、7203.T(日股)、005930.KS(韩股)、2330.TW(台股)",
|
|
@@ -146,16 +231,18 @@ export default definePluginEntry({
|
|
|
146
231
|
|
|
147
232
|
api.registerTool({
|
|
148
233
|
name: "get_financials",
|
|
149
|
-
description: "
|
|
234
|
+
description: "获取股票财务摘要及历史趋势,按天缓存。A股返回ROE/毛利率/净利率等;annual=true与periods=10取十年年报,港股年度历史按数据源实际可得期数返回。估值历史用get_valuation_history,披露排期用get_earnings_calendar",
|
|
150
235
|
parameters: Type.Object({
|
|
151
236
|
symbol: Type.String({ description: "股票代码(A股如600519,美股如AAPL,港股如00700.HK)" }),
|
|
237
|
+
annual: Type.Optional(Type.Boolean({description: "只取年度报告,默认false"})),
|
|
152
238
|
periods: Type.Optional(
|
|
153
|
-
Type.Number({ description: "返回最近N
|
|
239
|
+
Type.Number({ description: "返回最近N个报告期1..40,默认1;annual=true时periods=10请求10年年报" })
|
|
154
240
|
),
|
|
155
241
|
}),
|
|
156
242
|
async execute(_id, params) {
|
|
157
243
|
const args = ["financials", params.symbol];
|
|
158
|
-
if (params.periods && params.periods
|
|
244
|
+
if (params.periods !== undefined && params.periods !== 1) args.push("--periods", String(params.periods));
|
|
245
|
+
if (params.annual) args.push("--annual");
|
|
159
246
|
const out = await runPy("stock_data.py", args);
|
|
160
247
|
return asText(out);
|
|
161
248
|
},
|
|
@@ -290,7 +377,7 @@ export default definePluginEntry({
|
|
|
290
377
|
api.registerTool({
|
|
291
378
|
name: "get_sector_constituents",
|
|
292
379
|
description:
|
|
293
|
-
"查询A股板块成分股(正向映射:板块→股票列表)。板块名支持模糊匹配(如「创新药」自动解析到精确板块名),东财行业/概念 + 新浪多源 failover
|
|
380
|
+
"查询A股板块成分股(正向映射:板块→股票列表)。板块名支持模糊匹配(如「创新药」自动解析到精确板块名),东财行业/概念 + 新浪多源 failover,结果按用户目录缓存7天。仅支持A股;反向查个股所属板块用 resolve_stock_sectors",
|
|
294
381
|
parameters: Type.Object({
|
|
295
382
|
sector: Type.String({ description: "板块名称(可模糊,如 创新药、半导体)" }),
|
|
296
383
|
board_type: Type.Optional(
|
|
@@ -430,9 +517,10 @@ export default definePluginEntry({
|
|
|
430
517
|
api.registerTool({
|
|
431
518
|
name: "get_margin_trading",
|
|
432
519
|
description:
|
|
433
|
-
"获取A股个股融资融券明细(融资余额/融资买入额/融券余量等,上交所/深交所官方数据按交易所分流),返回最近N个交易日序列(最新在前)。金额单位为元,short_*_shares
|
|
520
|
+
"获取A股个股融资融券明细(融资余额/融资买入额/融券余量等,上交所/深交所官方数据按交易所分流),返回最近N个交易日序列(最新在前)。金额单位为元,short_*_shares 单位为股。include_ratio=true追加同日融资买入/成交额百分比(margin_buy_ratio_pct),缺少同日元口径成交额则为null。仅两融标的有数据,非两融标的返回错误",
|
|
434
521
|
parameters: Type.Object({
|
|
435
522
|
symbol: Type.String({ description: "A股股票代码,如 600519" }),
|
|
523
|
+
include_ratio: Type.Optional(Type.Boolean({description: "追加同日融资买入占比,默认false"})),
|
|
436
524
|
days: Type.Optional(
|
|
437
525
|
Type.Number({ description: "返回最近N个交易日,默认 10" })
|
|
438
526
|
),
|
|
@@ -443,6 +531,7 @@ export default definePluginEntry({
|
|
|
443
531
|
params.symbol,
|
|
444
532
|
"--days",
|
|
445
533
|
String(params.days ?? 10),
|
|
534
|
+
...(params.include_ratio ? ["--include-ratio"] : []),
|
|
446
535
|
]);
|
|
447
536
|
return asText(out);
|
|
448
537
|
},
|
package/openclaw.plugin.json
CHANGED
|
@@ -54,7 +54,13 @@
|
|
|
54
54
|
"evaluate_signals",
|
|
55
55
|
"get_signal_summary",
|
|
56
56
|
"get_review_history",
|
|
57
|
-
"parse_stock_list"
|
|
57
|
+
"parse_stock_list",
|
|
58
|
+
"get_valuation_history",
|
|
59
|
+
"get_index_valuation",
|
|
60
|
+
"get_earnings_calendar",
|
|
61
|
+
"get_shareholder_structure",
|
|
62
|
+
"get_etf_details",
|
|
63
|
+
"get_dividends"
|
|
58
64
|
]
|
|
59
65
|
},
|
|
60
66
|
"activation": {
|
package/package.json
CHANGED
|
@@ -87,3 +87,9 @@ gather 工具返回:
|
|
|
87
87
|
5. 触发、失效、时间止损、潜在收益/R 与风险提示
|
|
88
88
|
|
|
89
89
|
完成标准:区分“已确认事实”“推断的影响路径”和“待验证项”,并为交易计划给出可观察的失效条件。
|
|
90
|
+
|
|
91
|
+
财报季排期使用 `get_earnings_calendar(report_date="YYYY-MM-DD", symbol=...)`:最新预约/修订日期是计划,实际披露日期是实绩时间,业绩预告是已公告预估。除息事件用 `get_dividends(mode="calendar", symbol=...)`;不补造未公告日期或把分红预案计入已支付现金。
|
|
92
|
+
|
|
93
|
+
### 补充数据覆盖
|
|
94
|
+
|
|
95
|
+
get_earnings_calendar 查询 A 股仍需 report_date;HK 提供 symbol,可选财政期末 report_date;优先 HKEX 已公告业绩审批董事会排期 confirmation=official_board_meeting_notice、date_kind=scheduled_board_meeting,不能称实际披露日。供应商备选日期为 provider_only,未知期次在请求特定报告期时另列 unverified_schedules,不能强行匹配。
|
|
@@ -77,3 +77,9 @@ gather 工具返回:
|
|
|
77
77
|
5. 投资建议与关注风险点
|
|
78
78
|
|
|
79
79
|
只有收入、利润、现金流和 ROE 均有可比多期数据时,才可给出“优质”结论;否则完成标准是给出已验证项、缺失项和最小补证建议。
|
|
80
|
+
|
|
81
|
+
用户要求长期质量、五到十年财报或 ROE/利润率趋势时,补充 `get_financials(symbol, periods=10, annual=true)`;逐年比较同口径年报,实际可得年份不足时明确标注,不以最近十个季度代替十年。结合 `get_valuation_history` 检查估值分位,分位窗口以实际返回数据为准。
|
|
82
|
+
|
|
83
|
+
### 补充数据覆盖
|
|
84
|
+
|
|
85
|
+
指数估值可用 get_index_valuation;中证补充多年滚动 PE,配置 LIXINGER_TOKEN 可补理杏仁 mcw 历史 PB。每个指标按其来源/口径使用,不把缺失 PB 或近期 PE1 当长期数据。
|
|
@@ -77,6 +77,7 @@ python3 scripts/gather.py <symbol>
|
|
|
77
77
|
- 信号持久化在本地 JSONL(`$STOCK_SIGNAL_STORE` 或 `~/.stock-analysis/signals.jsonl`);是否记录由宿主 Agent 决定,不阻塞报告输出。
|
|
78
78
|
|
|
79
79
|
## 注意事项
|
|
80
|
+
- `get_kline` 的 A 股股票/ETF 数据为前复权,每条记录 `adjusted="qfq"`;显式指数 `sh000xxx` / `sz399xxx` 为原始点位,`adjusted="none"`。复权数据源全部失败时说明数据缺失,不用未复权价格补算指标或信号。
|
|
80
81
|
- 始终提供风险提示
|
|
81
82
|
- 不做绝对化的涨跌预测
|
|
82
83
|
- 建议用户结合自身风险偏好做决策
|
|
@@ -84,3 +85,24 @@ python3 scripts/gather.py <symbol>
|
|
|
84
85
|
- 如果风险筛查返回 veto_buy=true,必须醒目标注并建议谨慎
|
|
85
86
|
|
|
86
87
|
完成标准:每个买卖建议都对应可观察的触发条件和失效条件,且所有缺失数据及其影响已说明。
|
|
88
|
+
|
|
89
|
+
## 低频价投数据
|
|
90
|
+
|
|
91
|
+
按用户问题选择数据,完整说明口径、采样覆盖和缺失项:
|
|
92
|
+
|
|
93
|
+
- 判断估值贵贱:`get_valuation_history(symbol, years=5)` 的 PE-TTM/PB 历史正值分位与 Band;亏损 PE 不计算分位,实际采样不足五年必须说明。
|
|
94
|
+
- 读多年财报:`get_financials(symbol, periods=10, annual=true)`;A 股按年报筛选,港股按源实际可得年度数返回。财报期不等于公告日,年报历史不能用于假定当时已知信息的回测。
|
|
95
|
+
- 财报季排期:`get_earnings_calendar(report_date="YYYY-MM-DD", symbol=...)`,区分最新预约日期、实际披露日期和已公告业绩预告,不把预告当业绩实绩。
|
|
96
|
+
- 股东变化:`get_shareholder_structure`。A 股北向值是财报十大流通股东中的 HKSCC 名义持股,缺席不等于零,不能当成日度北向买卖;港股南向值按港交所披露日期使用。
|
|
97
|
+
- 大盘估值:`get_index_valuation(symbol="000300", years=5)`;中证近期 PE1 不冒充 PE-TTM、PB 或多年分位。
|
|
98
|
+
- ETF:`get_etf_details(symbol="510300", benchmark="sh000300")`。折溢价须看净值/行情日期;披露持仓不是完整实时申赎篮子,指数成分与基金持仓分别呈现。跟踪误差必须给出用户认可的基准。
|
|
99
|
+
- 股息:`get_dividends` 区分历史、未来已公布除息日历和 A 股报告期排行;预案不计入已实现 TTM 股息。名义每股现金未重算送转股口径,遇送转股时不得据此精确比较持有收益。
|
|
100
|
+
- 两融:`get_margin_trading(include_ratio=true)` 的 `margin_buy_ratio_pct` 只使用同日成交额;null 表示不可计算。
|
|
101
|
+
|
|
102
|
+
慢变数据存于 `~/.stock-analysis/cache`:财报、基本信息及新历史数据按天,板块映射按周;行情仍实时查询。输出中的报告期/数据日期决定能否用于判断,缓存命中不代表数据已更新。
|
|
103
|
+
|
|
104
|
+
### 补充数据覆盖
|
|
105
|
+
|
|
106
|
+
get_shareholder_structure 的 northbound 优先使用沪深官方季度总量;northbound_nominee 只是十大股东推断,不能混同。get_etf_details 的 basket 是完整已发布 PCF,对价数量/现金替代规则不是基金实际持仓或NAV权重。HK 股息排行使用 get_dividends(mode=ranking, market=HK),年度口径不能称 TTM。
|
|
107
|
+
|
|
108
|
+
实际披露股票持仓可用 get_etf_details(include_full_holdings=true) 获取半年度/年度表;按 as_of 解释,数量为股、市值为人民币元。默认不取大量明细;不是实时全资产组合,不与 PCF 对价数量混同。
|
|
@@ -73,3 +73,21 @@ python3 tools/screener.py screen --market A --top 20
|
|
|
73
73
|
- **成长型**:中等PE + 高营收增长 + 高换手率
|
|
74
74
|
- **趋势型**:放量突破 + 均线多头 + 高量比
|
|
75
75
|
- **低估反转**:超跌 + 低PB + 资金净流入
|
|
76
|
+
|
|
77
|
+
## 股息因子(A股,可选)
|
|
78
|
+
|
|
79
|
+
配置 `filters.dividend_yield_min` / `dividend_yield_max` 或 `sort_by: dividend_score` / `dividend_yield` 时才拉取股息数据。`dividend_report_date` 可指定报告期,默认上一年年末。这里使用已实施方案的**报告期股息率**(百分数),不是滚动十二个月股息率;缺失为未知,使用股息阈值时排除。启用后 value 分项加入股息横截面评分,未启用时不增加股息请求。
|
|
80
|
+
|
|
81
|
+
```yaml
|
|
82
|
+
filters:
|
|
83
|
+
dividend_yield_min: 3
|
|
84
|
+
sort_by: dividend_score
|
|
85
|
+
sort_order: desc
|
|
86
|
+
dividend_report_date: "2025-12-31"
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
筛选结果仍需用 `get_dividends(mode="history", symbol=...)` 核查已实施现金分红、连续支付年数与除息时间,不能把高股息直接解释为低风险。
|
|
90
|
+
|
|
91
|
+
### 补充数据覆盖
|
|
92
|
+
|
|
93
|
+
股息筛选支持 A/HK:A 股为报告期已实施方案股息率,HK 为 HKEX/LSEG 年度股息率。两者都不是当前价 TTM;使用结果的 yield_basis 和 report_date,缺失不当零。
|
package/tools/_cache.py
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"""TTL cache for slow public datasets; live quotes and errors are never stored."""
|
|
2
|
+
|
|
3
|
+
import contextlib
|
|
4
|
+
import hashlib
|
|
5
|
+
import json
|
|
6
|
+
import os
|
|
7
|
+
import tempfile
|
|
8
|
+
import time
|
|
9
|
+
from pathlib import Path
|
|
10
|
+
|
|
11
|
+
CACHE_DIR = Path.home() / ".stock-analysis" / "cache"
|
|
12
|
+
DAY = 86400
|
|
13
|
+
WEEK = 7 * DAY
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def _namespace_prefix(namespace):
|
|
17
|
+
return hashlib.sha256(namespace.encode()).hexdigest()[:12]
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def _read(path, ttl):
|
|
21
|
+
try:
|
|
22
|
+
entry = json.loads(path.read_text(encoding="utf-8"))
|
|
23
|
+
if 0 <= time.time() - entry["fetched_at"] < ttl:
|
|
24
|
+
return entry
|
|
25
|
+
except (OSError, ValueError, KeyError, TypeError):
|
|
26
|
+
pass
|
|
27
|
+
return None
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def cached_values(namespace, ttl):
|
|
31
|
+
for path in CACHE_DIR.glob(f"{_namespace_prefix(namespace)}-*.json"):
|
|
32
|
+
entry = _read(path, ttl)
|
|
33
|
+
if entry and str(entry.get("key", "")).startswith(namespace + ":"):
|
|
34
|
+
yield entry.get("data")
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def cached(key: str, ttl: int, fetch):
|
|
38
|
+
path = CACHE_DIR / f"{_namespace_prefix(key.partition(':')[0])}-{hashlib.sha256(key.encode()).hexdigest()}.json"
|
|
39
|
+
entry = _read(path, ttl)
|
|
40
|
+
if entry and "data" in entry:
|
|
41
|
+
return entry["data"]
|
|
42
|
+
result = fetch()
|
|
43
|
+
rows = result if isinstance(result, list) else [result]
|
|
44
|
+
if not result or any(isinstance(row, dict) and (row.get("error") or row.get("warnings")) for row in rows):
|
|
45
|
+
return result
|
|
46
|
+
tmp = None
|
|
47
|
+
try:
|
|
48
|
+
CACHE_DIR.mkdir(parents=True, exist_ok=True)
|
|
49
|
+
with tempfile.NamedTemporaryFile(mode="w", encoding="utf-8", dir=CACHE_DIR, delete=False) as stream:
|
|
50
|
+
tmp = stream.name
|
|
51
|
+
json.dump(
|
|
52
|
+
{"key": key, "fetched_at": time.time(), "data": result}, stream, ensure_ascii=False, allow_nan=False
|
|
53
|
+
)
|
|
54
|
+
os.replace(tmp, path)
|
|
55
|
+
except (OSError, ValueError, TypeError):
|
|
56
|
+
pass
|
|
57
|
+
finally:
|
|
58
|
+
if tmp:
|
|
59
|
+
with contextlib.suppress(OSError):
|
|
60
|
+
Path(tmp).unlink(missing_ok=True)
|
|
61
|
+
return result
|
package/tools/capabilities.py
CHANGED
|
@@ -18,6 +18,15 @@ ALL_MARKETS = ["A", "HK", "US", "JP", "KR", "TW"]
|
|
|
18
18
|
|
|
19
19
|
# tool_name -> {markets: [supported markets], reason: str for unsupported}
|
|
20
20
|
TOOL_MATRIX = {
|
|
21
|
+
"get_valuation_history": {"markets": ["A", "HK"], "reason": "A/HK historical valuation providers only"},
|
|
22
|
+
"get_index_valuation": {"markets": ["A"], "reason": "Chinese index valuation only"},
|
|
23
|
+
"get_earnings_calendar": {
|
|
24
|
+
"markets": ["A", "HK"],
|
|
25
|
+
"reason": "A-share disclosed calendar / HK single-symbol provider schedule",
|
|
26
|
+
},
|
|
27
|
+
"get_shareholder_structure": {"markets": ["A", "HK"], "reason": "A-share shareholder reports / HK southbound only"},
|
|
28
|
+
"get_etf_details": {"markets": ["A"], "reason": "A-share ETF portfolio/NAV/size only"},
|
|
29
|
+
"get_dividends": {"markets": ["A", "HK"], "reason": "A/HK dividend history and report-year ranking"},
|
|
21
30
|
"get_kline": {"markets": ALL_MARKETS, "reason": None},
|
|
22
31
|
"get_quote": {"markets": ALL_MARKETS, "reason": None},
|
|
23
32
|
"get_news": {"markets": ALL_MARKETS, "reason": None},
|
package/tools/diagnostics.py
CHANGED
|
@@ -27,6 +27,12 @@ PROVIDERS = {
|
|
|
27
27
|
# see stock_data._kline_tushare) — the tushare package is not in requirements,
|
|
28
28
|
# so availability is the token, not a package probe
|
|
29
29
|
"tushare": ("requests", ["TUSHARE_TOKEN"], ["A"], "pure-HTTP API (api.tushare.pro); no tushare package needed"),
|
|
30
|
+
"lixinger": (
|
|
31
|
+
"requests",
|
|
32
|
+
["LIXINGER_TOKEN"],
|
|
33
|
+
["A"],
|
|
34
|
+
"optional index PE/PB history; subscription permissions not probed",
|
|
35
|
+
),
|
|
30
36
|
"efinance": ("efinance", [], ["A"], None),
|
|
31
37
|
"tencent": ("requests", [], ["A"], "qt.gtimg.cn quote/kline, no auth (issue #25)"),
|
|
32
38
|
"sina": (
|
package/tools/screener.py
CHANGED
|
@@ -73,6 +73,13 @@ def merge_filters(config: dict | None) -> dict:
|
|
|
73
73
|
|
|
74
74
|
def apply_filters(df: pd.DataFrame, filters: dict) -> pd.DataFrame:
|
|
75
75
|
conditions = []
|
|
76
|
+
for bound, op in [("dividend_yield_min", "min"), ("dividend_yield_max", "max")]:
|
|
77
|
+
if bound in filters:
|
|
78
|
+
if "dividend_yield" not in df.columns:
|
|
79
|
+
return df.iloc[0:0].copy()
|
|
80
|
+
conditions.append(
|
|
81
|
+
df["dividend_yield"] >= filters[bound] if op == "min" else df["dividend_yield"] <= filters[bound]
|
|
82
|
+
)
|
|
76
83
|
if "pe" in df.columns:
|
|
77
84
|
conditions.append(df["pe"] >= filters["pe_min"])
|
|
78
85
|
conditions.append(df["pe"] <= filters["pe_max"])
|
|
@@ -121,7 +128,10 @@ def compute_scores(df: pd.DataFrame) -> pd.DataFrame:
|
|
|
121
128
|
value_parts.append(100 - _minmax(df["pe"]))
|
|
122
129
|
if "pb" in df.columns:
|
|
123
130
|
value_parts.append(100 - _minmax(df["pb"]))
|
|
124
|
-
|
|
131
|
+
if "dividend_yield" in df.columns:
|
|
132
|
+
df["dividend_score"] = _minmax(df["dividend_yield"])
|
|
133
|
+
value_parts.append(df["dividend_score"])
|
|
134
|
+
df["value_score"] = pd.concat(value_parts, axis=1).mean(axis=1) if value_parts else 0.0
|
|
125
135
|
|
|
126
136
|
# Momentum: higher change_pct and volume_ratio → higher score
|
|
127
137
|
mom_parts = []
|
|
@@ -304,6 +314,20 @@ def _apply_l2(candidates: list, market: str, multiplier: float) -> None:
|
|
|
304
314
|
|
|
305
315
|
|
|
306
316
|
def screen(market: str, top: int, config: dict | None, l2: bool = False) -> dict:
|
|
317
|
+
filters = merge_filters(config)
|
|
318
|
+
dividend_requested = any(k.startswith("dividend_yield_") for k in filters) or (config or {}).get("sort_by") in (
|
|
319
|
+
"dividend_yield",
|
|
320
|
+
"dividend_score",
|
|
321
|
+
)
|
|
322
|
+
if dividend_requested and market not in ("A", "HK"):
|
|
323
|
+
return {"error": "dividend screening currently covers A/HK only", "market": market}
|
|
324
|
+
for key in ("dividend_yield_min", "dividend_yield_max"):
|
|
325
|
+
if key in filters and (
|
|
326
|
+
isinstance(filters[key], bool)
|
|
327
|
+
or not isinstance(filters[key], (int, float))
|
|
328
|
+
or not np.isfinite(filters[key])
|
|
329
|
+
):
|
|
330
|
+
return {"error": f"{key} must be a finite number in percent units", "market": market}
|
|
307
331
|
raw = fetch_snapshot(market)
|
|
308
332
|
if isinstance(raw, dict) and "error" in raw:
|
|
309
333
|
return raw
|
|
@@ -330,7 +354,30 @@ def screen(market: str, top: int, config: dict | None, l2: bool = False) -> dict
|
|
|
330
354
|
if existing:
|
|
331
355
|
df = df.dropna(subset=existing)
|
|
332
356
|
|
|
333
|
-
|
|
357
|
+
dividend_meta = {}
|
|
358
|
+
if dividend_requested:
|
|
359
|
+
try:
|
|
360
|
+
from value_data import dividend_ranking
|
|
361
|
+
|
|
362
|
+
ranked = dividend_ranking(report_date=(config or {}).get("dividend_report_date", ""), market=market)
|
|
363
|
+
|
|
364
|
+
def dividend_key(symbol):
|
|
365
|
+
return symbol.split(".")[0].lstrip("0") if market == "HK" else symbol
|
|
366
|
+
|
|
367
|
+
yields = {dividend_key(r["symbol"]): r["dividend_yield"] for r in ranked["items"]}
|
|
368
|
+
df["dividend_yield"] = df["symbol"].map(dividend_key).map(yields)
|
|
369
|
+
dividend_meta = {
|
|
370
|
+
"dividend_factor": {
|
|
371
|
+
"report_date": ranked["report_date"],
|
|
372
|
+
"yield_basis": ranked.get("yield_basis", "provider report-period cash dividend yield, percent"),
|
|
373
|
+
"missing": "unknown; excluded by dividend filters",
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
except Exception:
|
|
377
|
+
return {
|
|
378
|
+
"error": "dividend data unavailable; requested dividend criterion was not applied",
|
|
379
|
+
"market": market,
|
|
380
|
+
}
|
|
334
381
|
df = apply_filters(df, filters)
|
|
335
382
|
filtered_count = len(df)
|
|
336
383
|
|
|
@@ -344,6 +391,7 @@ def screen(market: str, top: int, config: dict | None, l2: bool = False) -> dict
|
|
|
344
391
|
"candidates": [],
|
|
345
392
|
"market_sentiment": sentiment,
|
|
346
393
|
"l2_enabled": l2_enabled,
|
|
394
|
+
**dividend_meta,
|
|
347
395
|
}
|
|
348
396
|
|
|
349
397
|
df = compute_scores(df)
|
|
@@ -374,6 +422,7 @@ def screen(market: str, top: int, config: dict | None, l2: bool = False) -> dict
|
|
|
374
422
|
"pb",
|
|
375
423
|
"market_cap",
|
|
376
424
|
"volume_ratio",
|
|
425
|
+
"dividend_yield",
|
|
377
426
|
]:
|
|
378
427
|
v = _finite(row.get(field))
|
|
379
428
|
if v is not None:
|
|
@@ -386,6 +435,8 @@ def screen(market: str, top: int, config: dict | None, l2: bool = False) -> dict
|
|
|
386
435
|
"composite": None if composite is None else round(composite, 1),
|
|
387
436
|
"final": None if composite is None else round(composite * multiplier, 1),
|
|
388
437
|
}
|
|
438
|
+
if "dividend_score" in row:
|
|
439
|
+
entry["scores"]["dividend"] = _finite(round(float(row["dividend_score"]), 1))
|
|
389
440
|
candidates.append(entry)
|
|
390
441
|
|
|
391
442
|
if l2_enabled:
|
|
@@ -403,6 +454,7 @@ def screen(market: str, top: int, config: dict | None, l2: bool = False) -> dict
|
|
|
403
454
|
"candidates": candidates,
|
|
404
455
|
"market_sentiment": sentiment,
|
|
405
456
|
"l2_enabled": l2_enabled,
|
|
457
|
+
**dividend_meta,
|
|
406
458
|
}
|
|
407
459
|
|
|
408
460
|
|