stock-analysis-plugin 0.2.11 → 0.2.13
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 +234 -382
- package/docs/mcp.md +60 -0
- package/hermes/__init__.py +35 -0
- package/hermes/plugin.yaml +132 -0
- package/hermes/schemas.py +6 -0
- package/hermes/tools.py +647 -0
- package/mcp_host/__init__.py +1 -0
- package/mcp_host/__main__.py +3 -0
- package/mcp_host/server.py +222 -0
- package/package.json +7 -1
- package/pi/index.ts +52 -2906
- package/scripts/cli-json.mjs +23 -0
- package/scripts/exec-process.mjs +89 -0
- package/scripts/setup-python.mjs +37 -4
- package/scripts/tool-calls.mjs +493 -0
- package/skills/bull-trend/SKILL.md +2 -2
- package/skills/bull-trend/references/fat-tails.md +76 -3
- package/skills/bull-trend/scripts/tail_analysis.py +92 -3
- package/skills/event-driven/SKILL.md +2 -2
- package/skills/growth-quality/SKILL.md +1 -1
- package/skills/market-review/SKILL.md +1 -0
- package/skills/stock-analysis/SKILL.md +12 -7
- package/skills/stock-analysis/references/stateless-analysis.md +9 -1
- package/skills/stock-screener/SKILL.md +1 -1
- package/skills/strategy-backtest/SKILL.md +1 -1
- package/tools/_cache.py +13 -0
- package/tools/_subproc.py +46 -0
- package/tools/alert_rules.py +2 -2
- package/tools/backtest.py +3 -3
- package/tools/capabilities.py +33 -9
- package/tools/cli_budgets.json +1 -0
- package/tools/credit_data.py +293 -0
- package/tools/diagnostics.py +3 -4
- package/tools/gather.py +2 -6
- package/tools/import_parser.py +3 -4
- package/tools/lixinger.py +119 -27
- package/tools/market_regime.py +5 -2
- package/tools/market_review.py +5 -6
- package/tools/name_resolver.py +45 -33
- package/tools/report_renderer.py +3 -3
- package/tools/requirements.txt +5 -4
- package/tools/risk_screening.py +3 -2
- package/tools/screener.py +41 -30
- package/tools/search_intel.py +79 -10
- package/tools/sec_edgar.py +268 -1
- package/tools/sec_holders.py +6 -0
- package/tools/signal_tracker.py +5 -5
- package/tools/stateless_analysis.py +132 -19
- package/tools/stock_data.py +1020 -817
- package/tools/tiaa_disclosures.py +4 -0
- package/tools/tool_schemas.json +2734 -0
- package/tools/trading_calendar.py +65 -30
- package/tools/value_data.py +423 -175
- package/tools/watchlist.py +43 -5
|
@@ -10,10 +10,23 @@ from zoneinfo import ZoneInfo
|
|
|
10
10
|
|
|
11
11
|
sys.path.insert(0, str(Path(__file__).resolve().parent))
|
|
12
12
|
from _cache import DAY, cached
|
|
13
|
-
from _subproc import socket_timeout, utf8_stdio
|
|
13
|
+
from _subproc import error_message, socket_timeout, utf8_stdio
|
|
14
14
|
|
|
15
15
|
# Supported markets. argparse uses type=str.upper so lowercase input is accepted too.
|
|
16
16
|
MARKETS = ["CN", "HK", "US", "JP", "KR", "TW"]
|
|
17
|
+
_MARKET_TZ = {
|
|
18
|
+
"CN": "Asia/Shanghai",
|
|
19
|
+
"HK": "Asia/Hong_Kong",
|
|
20
|
+
"US": "America/New_York",
|
|
21
|
+
"JP": "Asia/Tokyo",
|
|
22
|
+
"KR": "Asia/Seoul",
|
|
23
|
+
"TW": "Asia/Taipei",
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def market_now(market: str) -> datetime:
|
|
28
|
+
"""Naive market-local wall clock; "today" must not follow the host timezone (often UTC)."""
|
|
29
|
+
return datetime.now(ZoneInfo(_MARKET_TZ.get(market.upper(), "Asia/Shanghai"))).replace(tzinfo=None)
|
|
17
30
|
|
|
18
31
|
|
|
19
32
|
def _is_weekend(d: datetime) -> bool:
|
|
@@ -40,7 +53,8 @@ def cn_trade_dates(year: int) -> set[str]:
|
|
|
40
53
|
import akshare as ak
|
|
41
54
|
|
|
42
55
|
with socket_timeout(25):
|
|
43
|
-
|
|
56
|
+
# akshare 1.20.45 renamed it; py3.10 stays below 1.20.40 with the old name.
|
|
57
|
+
df = (getattr(ak, "calendar_trade_date_hist_sina", None) or ak.tool_trade_date_hist_sina)()
|
|
44
58
|
if df is None or df.empty:
|
|
45
59
|
return []
|
|
46
60
|
return sorted({date.fromisoformat(str(value)[:10]).isoformat() for value in df.iloc[:, 0]})
|
|
@@ -139,7 +153,7 @@ def is_trading_day(market: str, date_str: str = None) -> dict:
|
|
|
139
153
|
if date_str:
|
|
140
154
|
d = datetime.strptime(date_str, "%Y-%m-%d")
|
|
141
155
|
else:
|
|
142
|
-
d =
|
|
156
|
+
d = market_now(market)
|
|
143
157
|
date_str = d.strftime("%Y-%m-%d")
|
|
144
158
|
|
|
145
159
|
market = market.upper()
|
|
@@ -149,7 +163,7 @@ def is_trading_day(market: str, date_str: str = None) -> dict:
|
|
|
149
163
|
|
|
150
164
|
if market == "CN":
|
|
151
165
|
trading_dates = cn_trade_dates(d.year)
|
|
152
|
-
if trading_dates:
|
|
166
|
+
if trading_dates and min(trading_dates) <= date_str <= max(trading_dates):
|
|
153
167
|
is_td = date_str in trading_dates
|
|
154
168
|
return {
|
|
155
169
|
"date": date_str,
|
|
@@ -157,6 +171,18 @@ def is_trading_day(market: str, date_str: str = None) -> dict:
|
|
|
157
171
|
"is_trading_day": is_td,
|
|
158
172
|
"reason": "trading_day" if is_td else "holiday",
|
|
159
173
|
}
|
|
174
|
+
# A partial year must not make out-of-coverage weekdays look like confirmed holidays.
|
|
175
|
+
try:
|
|
176
|
+
is_td = _is_exchange_trading_day("XSHG", date_str)
|
|
177
|
+
return {
|
|
178
|
+
"date": date_str,
|
|
179
|
+
"market": market,
|
|
180
|
+
"is_trading_day": is_td,
|
|
181
|
+
"reason": "trading_day" if is_td else "holiday",
|
|
182
|
+
"source": "exchange-calendars",
|
|
183
|
+
}
|
|
184
|
+
except Exception:
|
|
185
|
+
pass # beyond the years XSHG records (or not installed): label the weekday guess
|
|
160
186
|
return {
|
|
161
187
|
"date": date_str,
|
|
162
188
|
"market": market,
|
|
@@ -177,13 +203,18 @@ def is_trading_day(market: str, date_str: str = None) -> dict:
|
|
|
177
203
|
except Exception:
|
|
178
204
|
pass
|
|
179
205
|
trading_dates = cn_trade_dates(d.year)
|
|
180
|
-
if trading_dates:
|
|
206
|
+
if trading_dates and min(trading_dates) <= date_str <= max(trading_dates):
|
|
181
207
|
is_td = date_str in trading_dates
|
|
182
208
|
return {
|
|
183
209
|
"date": date_str,
|
|
184
210
|
"market": market,
|
|
185
211
|
"is_trading_day": is_td,
|
|
186
|
-
"reason":
|
|
212
|
+
"reason": (
|
|
213
|
+
"assumed_trading_day (approx, based on CN calendar)"
|
|
214
|
+
if is_td
|
|
215
|
+
else "assumed_holiday (approx, based on CN calendar)"
|
|
216
|
+
),
|
|
217
|
+
"source": "cn-calendar-approximation",
|
|
187
218
|
}
|
|
188
219
|
return {"date": date_str, "market": market, "is_trading_day": True, "reason": "assumed_trading_day"}
|
|
189
220
|
|
|
@@ -201,7 +232,12 @@ def is_trading_day(market: str, date_str: str = None) -> dict:
|
|
|
201
232
|
pass
|
|
202
233
|
if (d.month, d.day) in _us_holidays(d.year):
|
|
203
234
|
return {"date": date_str, "market": market, "is_trading_day": False, "reason": "US_holiday"}
|
|
204
|
-
return {
|
|
235
|
+
return {
|
|
236
|
+
"date": date_str,
|
|
237
|
+
"market": market,
|
|
238
|
+
"is_trading_day": True,
|
|
239
|
+
"reason": "assumed_trading_day (rule-based US calendar)",
|
|
240
|
+
}
|
|
205
241
|
|
|
206
242
|
elif market in ("JP", "KR", "TW"):
|
|
207
243
|
exchange_map = {"JP": "XTKS", "KR": "XKRX", "TW": "XTAI"}
|
|
@@ -226,34 +262,31 @@ def is_trading_day(market: str, date_str: str = None) -> dict:
|
|
|
226
262
|
return {"date": date_str, "market": market, "error": f"Unknown market: {market}"}
|
|
227
263
|
|
|
228
264
|
|
|
229
|
-
def
|
|
230
|
-
|
|
231
|
-
|
|
265
|
+
def _walk_trading_days(market: str, count: int, d: datetime, step: timedelta, assumed: list | None) -> list[str]:
|
|
266
|
+
if count <= 0:
|
|
267
|
+
return []
|
|
232
268
|
result = []
|
|
233
|
-
max_search = count * 4
|
|
269
|
+
max_search = count * 4 + 20 # CN Golden Week / Spring Festival close up to 9 days in a row
|
|
234
270
|
for _ in range(max_search):
|
|
235
|
-
d +=
|
|
271
|
+
d += step
|
|
236
272
|
info = is_trading_day(market, d.strftime("%Y-%m-%d"))
|
|
237
273
|
if info.get("is_trading_day"):
|
|
238
274
|
result.append(d.strftime("%Y-%m-%d"))
|
|
275
|
+
if assumed is not None and info.get("reason", "").startswith("assumed_trading_day"):
|
|
276
|
+
assumed.append(result[-1]) # counted as a session only because no calendar covered it
|
|
239
277
|
if len(result) >= count:
|
|
240
278
|
break
|
|
241
279
|
return result
|
|
242
280
|
|
|
243
281
|
|
|
244
|
-
def
|
|
245
|
-
d = datetime.strptime(from_date, "%Y-%m-%d") if from_date else
|
|
282
|
+
def next_trading_days(market: str, count: int = 5, from_date: str = None, assumed: list | None = None) -> list[str]:
|
|
283
|
+
d = datetime.strptime(from_date, "%Y-%m-%d") if from_date else market_now(market)
|
|
284
|
+
return _walk_trading_days(market, count, d, timedelta(days=1), assumed)
|
|
246
285
|
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
info = is_trading_day(market, d.strftime("%Y-%m-%d"))
|
|
252
|
-
if info.get("is_trading_day"):
|
|
253
|
-
result.append(d.strftime("%Y-%m-%d"))
|
|
254
|
-
if len(result) >= count:
|
|
255
|
-
break
|
|
256
|
-
return result
|
|
286
|
+
|
|
287
|
+
def prev_trading_days(market: str, count: int = 5, from_date: str = None, assumed: list | None = None) -> list[str]:
|
|
288
|
+
d = datetime.strptime(from_date, "%Y-%m-%d") if from_date else market_now(market)
|
|
289
|
+
return _walk_trading_days(market, count, d, timedelta(days=-1), assumed)
|
|
257
290
|
|
|
258
291
|
|
|
259
292
|
def cmd_check(args):
|
|
@@ -298,11 +331,11 @@ def market_phase(market: str, at: str = None) -> dict:
|
|
|
298
331
|
try:
|
|
299
332
|
tz, sessions = _market_sessions(market)
|
|
300
333
|
except Exception as e:
|
|
301
|
-
return {"market": market, "error": f"exchange calendar unavailable: {e}"}
|
|
334
|
+
return {"market": market, "error": f"exchange calendar unavailable: {error_message(e)}"}
|
|
302
335
|
try:
|
|
303
336
|
naive = datetime.strptime(at, "%Y-%m-%dT%H:%M:%S") if at else None
|
|
304
337
|
except ValueError as e:
|
|
305
|
-
return {"market": market, "error": f"invalid --at (want YYYY-MM-DDTHH:MM:SS): {e}"}
|
|
338
|
+
return {"market": market, "error": f"invalid --at (want YYYY-MM-DDTHH:MM:SS): {error_message(e)}"}
|
|
306
339
|
local = datetime.now(tz) if naive is None else naive.replace(tzinfo=tz)
|
|
307
340
|
date_str = local.strftime("%Y-%m-%d")
|
|
308
341
|
is_td = bool(is_trading_day(market, date_str).get("is_trading_day"))
|
|
@@ -342,13 +375,15 @@ def market_phase(market: str, at: str = None) -> dict:
|
|
|
342
375
|
|
|
343
376
|
|
|
344
377
|
def cmd_next(args):
|
|
345
|
-
|
|
346
|
-
|
|
378
|
+
assumed = []
|
|
379
|
+
days = next_trading_days(args.market, args.count, args.date, assumed)
|
|
380
|
+
return {"market": args.market, "next_trading_days": days, "assumed_trading_days": assumed}
|
|
347
381
|
|
|
348
382
|
|
|
349
383
|
def cmd_prev(args):
|
|
350
|
-
|
|
351
|
-
|
|
384
|
+
assumed = []
|
|
385
|
+
days = prev_trading_days(args.market, args.count, args.date, assumed)
|
|
386
|
+
return {"market": args.market, "prev_trading_days": days, "assumed_trading_days": assumed}
|
|
352
387
|
|
|
353
388
|
|
|
354
389
|
def cmd_phase(args):
|