dsh-stock-analysis 0.2.3 → 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 +149 -7
- 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
|
@@ -81,10 +81,149 @@ function registerSkills(ctx) {
|
|
|
81
81
|
var name = "stock-analysis";
|
|
82
82
|
var inject = ["tools", "skills"];
|
|
83
83
|
function apply(ctx) {
|
|
84
|
+
ctx.tools.register(
|
|
85
|
+
pyTool({
|
|
86
|
+
name: "get_valuation_history",
|
|
87
|
+
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",
|
|
88
|
+
parameters: {
|
|
89
|
+
"symbol": {
|
|
90
|
+
"type": "string",
|
|
91
|
+
"description": "A\u80A1\u4EE3\u7801\u6216\u6E2F\u80A1.HK\u4EE3\u7801",
|
|
92
|
+
"required": true
|
|
93
|
+
},
|
|
94
|
+
"years": {
|
|
95
|
+
"type": "number",
|
|
96
|
+
"description": "\u5386\u53F2\u7A97\u53E3\u5E74\u65701..10\uFF0C\u9ED8\u8BA45"
|
|
97
|
+
}
|
|
98
|
+
},
|
|
99
|
+
script: "value_data.py",
|
|
100
|
+
argv: (p) => ["valuation_history", p.symbol, "--years", String(p.years ?? 5)]
|
|
101
|
+
})
|
|
102
|
+
);
|
|
103
|
+
ctx.tools.register(
|
|
104
|
+
pyTool({
|
|
105
|
+
name: "get_index_valuation",
|
|
106
|
+
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",
|
|
107
|
+
parameters: {
|
|
108
|
+
"symbol": {
|
|
109
|
+
"type": "string",
|
|
110
|
+
"description": "\u6307\u6570\u4EE3\u7801\u6216\u540D\u79F0\uFF0C\u5982000300\u3001\u6CAA\u6DF1300\u3001000985",
|
|
111
|
+
"required": true
|
|
112
|
+
},
|
|
113
|
+
"years": {
|
|
114
|
+
"type": "number",
|
|
115
|
+
"description": "\u5386\u53F2\u7A97\u53E3\u5E74\u65701..10\uFF0C\u9ED8\u8BA45"
|
|
116
|
+
}
|
|
117
|
+
},
|
|
118
|
+
script: "value_data.py",
|
|
119
|
+
argv: (p) => ["index_valuation", p.symbol, "--years", String(p.years ?? 5)]
|
|
120
|
+
})
|
|
121
|
+
);
|
|
122
|
+
ctx.tools.register(
|
|
123
|
+
pyTool({
|
|
124
|
+
name: "get_earnings_calendar",
|
|
125
|
+
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",
|
|
126
|
+
parameters: {
|
|
127
|
+
"report_date": {
|
|
128
|
+
"type": "string",
|
|
129
|
+
"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"
|
|
130
|
+
},
|
|
131
|
+
"symbol": {
|
|
132
|
+
"type": "string",
|
|
133
|
+
"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"
|
|
134
|
+
},
|
|
135
|
+
"top": {
|
|
136
|
+
"type": "number",
|
|
137
|
+
"description": "\u6BCF\u7C7B\u6700\u591A\u8FD4\u56DE\u6761\u65701..500\uFF0C\u9ED8\u8BA450"
|
|
138
|
+
}
|
|
139
|
+
},
|
|
140
|
+
script: "value_data.py",
|
|
141
|
+
argv: (p) => ["earnings_calendar", "--report-date", p.report_date ?? "", "--symbol", p.symbol ?? "", "--top", String(p.top ?? 50)]
|
|
142
|
+
})
|
|
143
|
+
);
|
|
144
|
+
ctx.tools.register(
|
|
145
|
+
pyTool({
|
|
146
|
+
name: "get_shareholder_structure",
|
|
147
|
+
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",
|
|
148
|
+
parameters: {
|
|
149
|
+
"symbol": {
|
|
150
|
+
"type": "string",
|
|
151
|
+
"description": "A\u80A1\u4EE3\u7801\u6216\u6E2F\u80A1.HK\u4EE3\u7801",
|
|
152
|
+
"required": true
|
|
153
|
+
},
|
|
154
|
+
"report_date": {
|
|
155
|
+
"type": "string",
|
|
156
|
+
"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"
|
|
157
|
+
}
|
|
158
|
+
},
|
|
159
|
+
script: "value_data.py",
|
|
160
|
+
argv: (p) => ["shareholder_structure", p.symbol, "--report-date", p.report_date ?? ""]
|
|
161
|
+
})
|
|
162
|
+
);
|
|
163
|
+
ctx.tools.register(
|
|
164
|
+
pyTool({
|
|
165
|
+
name: "get_etf_details",
|
|
166
|
+
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",
|
|
167
|
+
parameters: {
|
|
168
|
+
"include_full_holdings": { "type": "boolean", "description": "\u663E\u5F0F\u8BF7\u6C42\u534A\u5E74\u5EA6/\u5E74\u5EA6\u5168\u90E8\u62AB\u9732\u80A1\u7968\u8868\uFF0C\u9ED8\u8BA4false\uFF1B\u4E0D\u662F\u5B9E\u65F6\u5168\u8D44\u4EA7\u7EC4\u5408" },
|
|
169
|
+
"symbol": {
|
|
170
|
+
"type": "string",
|
|
171
|
+
"description": "A\u80A1ETF\u4EE3\u7801\uFF0C\u5982510300",
|
|
172
|
+
"required": true
|
|
173
|
+
},
|
|
174
|
+
"benchmark": {
|
|
175
|
+
"type": "string",
|
|
176
|
+
"description": "\u53EF\u9009\u57FA\u51C6\u4EE3\u7801\uFF0C\u5982sh000300\uFF1B\u4E0D\u731C\u6D4B\u57FA\u51C6"
|
|
177
|
+
},
|
|
178
|
+
"days": {
|
|
179
|
+
"type": "number",
|
|
180
|
+
"description": "\u51C0\u503C\u7A97\u53E3\u4EA4\u6613\u65E5\u657010..252\uFF0C\u9ED8\u8BA460"
|
|
181
|
+
}
|
|
182
|
+
},
|
|
183
|
+
script: "value_data.py",
|
|
184
|
+
argv: (p) => ["etf_details", p.symbol, "--benchmark", p.benchmark ?? "", "--days", String(p.days ?? 60), ...p.include_full_holdings ? ["--include-full-holdings"] : []]
|
|
185
|
+
})
|
|
186
|
+
);
|
|
187
|
+
ctx.tools.register(
|
|
188
|
+
pyTool({
|
|
189
|
+
name: "get_dividends",
|
|
190
|
+
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",
|
|
191
|
+
parameters: {
|
|
192
|
+
"market": { "type": "string", "enum": ["A", "HK"], "description": "\u4EC5ranking\u9009\u62E9\u5E02\u573A\uFF0C\u9ED8\u8BA4A\uFF1B\u5386\u53F2/\u9664\u606F\u65E5\u5386\u7531symbol\u51B3\u5B9A" },
|
|
193
|
+
"symbol": {
|
|
194
|
+
"type": "string",
|
|
195
|
+
"description": "history/calendar\u5FC5\u586BA\u80A1\u6216\u6E2F\u80A1.HK\u4EE3\u7801\uFF1Branking\u7701\u7565"
|
|
196
|
+
},
|
|
197
|
+
"mode": {
|
|
198
|
+
"type": "string",
|
|
199
|
+
"description": "history\u9ED8\u8BA4\uFF1Bcalendar\u672A\u6765\u5DF2\u516C\u5E03\u9664\u606F\u4E8B\u4EF6\uFF1Branking\u6309market\u67E5\u8BE2A/HK\u6392\u884C",
|
|
200
|
+
"enum": [
|
|
201
|
+
"history",
|
|
202
|
+
"calendar",
|
|
203
|
+
"ranking"
|
|
204
|
+
]
|
|
205
|
+
},
|
|
206
|
+
"report_date": {
|
|
207
|
+
"type": "string",
|
|
208
|
+
"description": "ranking\u62A5\u544A\u671FYYYY-MM-DD\uFF0C\u9ED8\u8BA4\u4E0A\u4E00\u5E74\u5E74\u672B\uFF1BHK\u4EC5\u5E74\u5EA6\u5E74\u672B\u65E5\u671F"
|
|
209
|
+
},
|
|
210
|
+
"years": {
|
|
211
|
+
"type": "number",
|
|
212
|
+
"description": "\u5386\u53F2\u7A97\u53E3\u5E74\u65701..20\uFF0C\u9ED8\u8BA410"
|
|
213
|
+
},
|
|
214
|
+
"top": {
|
|
215
|
+
"type": "number",
|
|
216
|
+
"description": "\u6392\u540D\u6761\u65701..500\uFF0C\u9ED8\u8BA420"
|
|
217
|
+
}
|
|
218
|
+
},
|
|
219
|
+
script: "value_data.py",
|
|
220
|
+
argv: (p) => ["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)]
|
|
221
|
+
})
|
|
222
|
+
);
|
|
84
223
|
ctx.tools.register(
|
|
85
224
|
pyTool({
|
|
86
225
|
name: "get_kline",
|
|
87
|
-
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\
|
|
226
|
+
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",
|
|
88
227
|
parameters: {
|
|
89
228
|
symbol: {
|
|
90
229
|
type: "string",
|
|
@@ -159,15 +298,17 @@ function apply(ctx) {
|
|
|
159
298
|
ctx.tools.register(
|
|
160
299
|
pyTool({
|
|
161
300
|
name: "get_financials",
|
|
162
|
-
description: "\u83B7\u53D6\u80A1\u7968\u8D22\u52A1\u6458\u8981\
|
|
301
|
+
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",
|
|
163
302
|
parameters: {
|
|
164
303
|
symbol: { type: "string", required: true, description: "\u80A1\u7968\u4EE3\u7801\uFF08A\u80A1\u5982600519\uFF0C\u7F8E\u80A1\u5982AAPL\uFF0C\u6E2F\u80A1\u598200700.HK\uFF09" },
|
|
165
|
-
|
|
304
|
+
annual: { type: "boolean", description: "\u53EA\u53D6\u5E74\u5EA6\u62A5\u544A\uFF0C\u9ED8\u8BA4false" },
|
|
305
|
+
periods: { type: "number", description: "\u8FD4\u56DE\u6700\u8FD1N\u4E2A\u62A5\u544A\u671F1..40\uFF0C\u9ED8\u8BA41\uFF1Bannual=true\u65F6periods=10\u8BF7\u6C4210\u5E74\u5E74\u62A5" }
|
|
166
306
|
},
|
|
167
307
|
script: "stock_data.py",
|
|
168
308
|
argv: (p) => {
|
|
169
309
|
const args = ["financials", p.symbol];
|
|
170
|
-
if (p.periods && p.periods
|
|
310
|
+
if (p.periods !== void 0 && p.periods !== 1) args.push("--periods", String(p.periods));
|
|
311
|
+
if (p.annual) args.push("--annual");
|
|
171
312
|
return args;
|
|
172
313
|
}
|
|
173
314
|
})
|
|
@@ -275,7 +416,7 @@ function apply(ctx) {
|
|
|
275
416
|
ctx.tools.register(
|
|
276
417
|
pyTool({
|
|
277
418
|
name: "get_sector_constituents",
|
|
278
|
-
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\
|
|
419
|
+
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",
|
|
279
420
|
parameters: {
|
|
280
421
|
sector: {
|
|
281
422
|
type: "string",
|
|
@@ -395,13 +536,14 @@ function apply(ctx) {
|
|
|
395
536
|
ctx.tools.register(
|
|
396
537
|
pyTool({
|
|
397
538
|
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",
|
|
539
|
+
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",
|
|
399
540
|
parameters: {
|
|
400
541
|
symbol: { type: "string", required: true, description: "A\u80A1\u80A1\u7968\u4EE3\u7801\uFF0C\u5982 600519" },
|
|
542
|
+
include_ratio: { type: "boolean", description: "\u8FFD\u52A0\u540C\u65E5\u878D\u8D44\u4E70\u5165\u5360\u6BD4\uFF0C\u9ED8\u8BA4false" },
|
|
401
543
|
days: { type: "number", description: "\u8FD4\u56DE\u6700\u8FD1N\u4E2A\u4EA4\u6613\u65E5\uFF0C\u9ED8\u8BA4 10" }
|
|
402
544
|
},
|
|
403
545
|
script: "stock_data.py",
|
|
404
|
-
argv: (p) => ["margin_trading", p.symbol, "--days", String(p.days ?? 10)]
|
|
546
|
+
argv: (p) => ["margin_trading", p.symbol, "--days", String(p.days ?? 10), ...p.include_ratio ? ["--include-ratio"] : []]
|
|
405
547
|
})
|
|
406
548
|
);
|
|
407
549
|
ctx.tools.register(
|
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
|
|