stock-analysis-plugin 0.2.9 → 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 +29 -24
- package/package.json +11 -8
- package/pi/index.ts +229 -9
- package/scripts/profile-offline.py +127 -0
- package/scripts/profile-workflows.py +87 -0
- package/skills/growth-quality/SKILL.md +2 -0
- package/skills/stock-analysis/SKILL.md +11 -3
- package/skills/stock-analysis/references/stateless-analysis.md +16 -2
- package/skills/stock-screener/SKILL.md +4 -0
- package/skills/strategy-backtest/SKILL.md +8 -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 +1 -0
- 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/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/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
|
@@ -8,15 +8,17 @@ so the host agent can decide what to do next (write daily briefing, dig deeper,
|
|
|
8
8
|
import argparse
|
|
9
9
|
import json
|
|
10
10
|
import sys
|
|
11
|
-
from concurrent.futures import ThreadPoolExecutor, as_completed
|
|
12
11
|
from datetime import datetime, timezone
|
|
13
12
|
from pathlib import Path
|
|
14
13
|
|
|
15
14
|
sys.path.insert(0, str(Path(__file__).resolve().parent))
|
|
16
15
|
from _subproc import run_tool as _run_json # noqa: E402
|
|
17
16
|
from _subproc import scrub_secrets, utf8_stdio
|
|
17
|
+
from anomaly_detect import detect_anomalies # noqa: E402
|
|
18
|
+
from gather import Collection
|
|
19
|
+
from market_review import review_market
|
|
18
20
|
from stock_data import detect_market # noqa: E402
|
|
19
|
-
from watchlist import analyze_watchlist, has_analysis_data
|
|
21
|
+
from watchlist import analyze_watchlist, has_analysis_data
|
|
20
22
|
|
|
21
23
|
|
|
22
24
|
def _suggest_next_tools(market: str, trend: str, anomalies: list, risk_level: str) -> list:
|
|
@@ -38,7 +40,7 @@ def _suggest_next_tools(market: str, trend: str, anomalies: list, risk_level: st
|
|
|
38
40
|
return [t for t in tools if not (t in seen or seen.add(t))]
|
|
39
41
|
|
|
40
42
|
|
|
41
|
-
def _build_item(symbol: str, data: dict | None) -> dict:
|
|
43
|
+
def _build_item(symbol: str, data: dict | None, *, session=None) -> dict:
|
|
42
44
|
if not has_analysis_data(data):
|
|
43
45
|
return {"symbol": symbol, "error": "no data"}
|
|
44
46
|
|
|
@@ -46,7 +48,19 @@ def _build_item(symbol: str, data: dict | None) -> dict:
|
|
|
46
48
|
risk = data.get("risk") or {}
|
|
47
49
|
|
|
48
50
|
# anomalies — separate call (watchlist gather doesn't include them)
|
|
49
|
-
|
|
51
|
+
if "kline" in data and "quote" in data:
|
|
52
|
+
records = data["kline"]
|
|
53
|
+
try:
|
|
54
|
+
anom_result = detect_anomalies(
|
|
55
|
+
symbol,
|
|
56
|
+
records=records[-60:] if isinstance(records, list) else records,
|
|
57
|
+
quote=data["quote"],
|
|
58
|
+
run=session.json if session is not None else None,
|
|
59
|
+
)
|
|
60
|
+
except Exception as exc:
|
|
61
|
+
anom_result = {"error": f"Anomaly analysis failed ({type(exc).__name__})"}
|
|
62
|
+
else:
|
|
63
|
+
anom_result = _run_json("anomaly_detect.py", ["detect", symbol], preserve_errors=True)
|
|
50
64
|
anomaly_ok = (
|
|
51
65
|
isinstance(anom_result, dict) and "error" not in anom_result and isinstance(anom_result.get("anomalies"), list)
|
|
52
66
|
)
|
|
@@ -88,51 +102,51 @@ def _build_item(symbol: str, data: dict | None) -> dict:
|
|
|
88
102
|
|
|
89
103
|
|
|
90
104
|
def build_context(symbols: list[str], include_market_review: bool = False, workers: int = 3) -> dict:
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
105
|
+
items_by_symbol = {}
|
|
106
|
+
with Collection() as session:
|
|
107
|
+
|
|
108
|
+
def ready(symbol, data):
|
|
109
|
+
items_by_symbol[symbol] = _build_item(symbol, data, session=session)
|
|
110
|
+
|
|
111
|
+
raw = analyze_watchlist(symbols, workers=workers, session=session, on_result=ready)
|
|
112
|
+
if "error" in raw:
|
|
113
|
+
return raw
|
|
114
|
+
results = raw.get("results", {})
|
|
115
|
+
# Also supports pre-collected watchlists supplied by callers/tests.
|
|
116
|
+
for symbol in symbols:
|
|
117
|
+
if symbol not in items_by_symbol:
|
|
118
|
+
ready(symbol, results.get(symbol))
|
|
119
|
+
items = [items_by_symbol[symbol] for symbol in symbols]
|
|
120
|
+
|
|
121
|
+
output = {
|
|
122
|
+
"meta": {
|
|
123
|
+
"provider": "watchlist_context",
|
|
124
|
+
"fetched_at": datetime.now(timezone.utc).isoformat(),
|
|
125
|
+
"freshness": "realtime_or_latest_trade_day",
|
|
126
|
+
"fallback_used": False,
|
|
127
|
+
"warnings": [f"{i['symbol']}: {warning}" for i in items for warning in i.get("warnings", [])],
|
|
128
|
+
},
|
|
129
|
+
"summary": {
|
|
130
|
+
"total": len(symbols),
|
|
131
|
+
"success": sum(1 for i in items if "error" not in i and i.get("anomaly_status") == "ok"),
|
|
132
|
+
"partial": sum(1 for i in items if "error" not in i and i.get("anomaly_status") == "unavailable"),
|
|
133
|
+
"failed": sum(1 for i in items if "error" in i),
|
|
134
|
+
"high_risk_count": sum(1 for i in items if i.get("risk_level") == "high"),
|
|
135
|
+
"veto_count": sum(1 for i in items if i.get("veto_buy")),
|
|
136
|
+
},
|
|
137
|
+
"items": items,
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
if include_market_review:
|
|
141
|
+
markets = sorted({i.get("market") for i in items if i.get("market")})
|
|
142
|
+
review = {}
|
|
143
|
+
for m in markets:
|
|
144
|
+
r = review_market(m, run=session.json)
|
|
145
|
+
if r and "error" not in r:
|
|
146
|
+
review[m] = r
|
|
147
|
+
output["market_review"] = review
|
|
148
|
+
|
|
149
|
+
return output
|
|
136
150
|
|
|
137
151
|
|
|
138
152
|
def main():
|