@weaxs/dsh-stock-analysis 0.2.11 → 0.2.12

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.
Files changed (41) hide show
  1. package/README.md +33 -81
  2. package/dist/index.js +3782 -2693
  3. package/dist/web/app.js +38 -6
  4. package/dist/web/style.css +1 -0
  5. package/package.json +1 -1
  6. package/scripts/cli-json.mjs +23 -0
  7. package/scripts/exec-process.mjs +89 -0
  8. package/scripts/setup-python.mjs +37 -4
  9. package/scripts/tool-calls.mjs +489 -0
  10. package/skills/event-driven/SKILL.md +2 -2
  11. package/skills/growth-quality/SKILL.md +1 -1
  12. package/skills/stock-analysis/SKILL.md +8 -6
  13. package/skills/stock-analysis/references/stateless-analysis.md +9 -1
  14. package/tools/_cache.py +13 -0
  15. package/tools/_subproc.py +46 -0
  16. package/tools/alert_rules.py +2 -2
  17. package/tools/backtest.py +3 -3
  18. package/tools/capabilities.py +32 -9
  19. package/tools/cli_budgets.json +2 -0
  20. package/tools/diagnostics.py +3 -4
  21. package/tools/gather.py +2 -6
  22. package/tools/import_parser.py +3 -4
  23. package/tools/lixinger.py +119 -27
  24. package/tools/market_regime.py +5 -2
  25. package/tools/market_review.py +5 -6
  26. package/tools/name_resolver.py +66 -7
  27. package/tools/report_renderer.py +3 -3
  28. package/tools/requirements.txt +5 -4
  29. package/tools/risk_screening.py +3 -2
  30. package/tools/screener.py +6 -4
  31. package/tools/search_intel.py +79 -10
  32. package/tools/sec_edgar.py +266 -0
  33. package/tools/sec_holders.py +6 -0
  34. package/tools/signal_tracker.py +5 -5
  35. package/tools/stateless_analysis.py +115 -0
  36. package/tools/stock_data.py +455 -201
  37. package/tools/tiaa_disclosures.py +4 -0
  38. package/tools/tool_schemas.json +2704 -0
  39. package/tools/trading_calendar.py +65 -30
  40. package/tools/value_data.py +366 -134
  41. package/tools/watchlist.py +43 -5
@@ -24,7 +24,7 @@ from zoneinfo import ZoneInfo
24
24
 
25
25
  sys.path.insert(0, str(Path(__file__).resolve().parent))
26
26
  from _cache import atomic_write, file_lock
27
- from _subproc import command_timeout, run_tool, utf8_stdio # noqa: E402
27
+ from _subproc import command_timeout, error_message, run_tool, utf8_stdio # noqa: E402
28
28
  from stock_data import detect_market # noqa: E402
29
29
 
30
30
  _MARKET_TIMEZONES = {
@@ -183,7 +183,7 @@ def cmd_record(args):
183
183
  _load_records(store, strict=True)
184
184
  _append_record(store, record)
185
185
  except (OSError, ValueError) as e:
186
- return {"error": str(e)}
186
+ return {"error": error_message(e)}
187
187
  return record
188
188
 
189
189
 
@@ -310,7 +310,7 @@ def cmd_evaluate(args):
310
310
  with _store_lock(store):
311
311
  records = _load_records(store, strict=True)
312
312
  except (OSError, ValueError) as e:
313
- return {"error": str(e)}
313
+ return {"error": error_message(e)}
314
314
  results = []
315
315
  evaluated = closed = 0
316
316
  changed = False
@@ -400,7 +400,7 @@ def cmd_evaluate(args):
400
400
  entry.update({key: rec.get(key) for key in ("outcome", "return_pct", "exit_date")})
401
401
  closed += 1
402
402
  except (OSError, ValueError) as e:
403
- return {"error": str(e)}
403
+ return {"error": error_message(e)}
404
404
  return {
405
405
  "evaluated": evaluated,
406
406
  "closed": closed,
@@ -418,7 +418,7 @@ def cmd_summary(args):
418
418
  with _store_lock(store):
419
419
  records = _load_records(store, strict=True)
420
420
  except (OSError, ValueError) as e:
421
- return {"error": str(e)}
421
+ return {"error": error_message(e)}
422
422
  filtered = records
423
423
  if args.source:
424
424
  filtered = [r for r in filtered if r.get("source") == args.source]
@@ -196,6 +196,120 @@ def text(value, name):
196
196
  return value.strip()
197
197
 
198
198
 
199
+ def dcf(p):
200
+ growth = p["revenue_growth"]
201
+ years = len(growth) if isinstance(growth, list) else 0
202
+ if not 1 <= years <= 10:
203
+ raise ValueError("revenue_growth must contain 1..10 years")
204
+
205
+ def series(name, minimum=None, maximum=None):
206
+ values = p[name]
207
+ if not isinstance(values, list) or len(values) != years:
208
+ raise ValueError(f"{name} must match revenue_growth length")
209
+ return [number(value, name, minimum, maximum) for value in values]
210
+
211
+ growth = series("revenue_growth", -0.99, 10)
212
+ margins = series("operating_margin", -10, 1)
213
+ taxes = series("tax_rate", 0, 1)
214
+ waccs = series("wacc", 0, 1)
215
+ revenue = positive(p["base_revenue"], "base_revenue")
216
+ sales_to_capital = positive(p["sales_to_capital"], "sales_to_capital")
217
+ terminal_growth = number(p["terminal_growth"], "terminal_growth", -0.99, 1)
218
+ terminal_wacc = number(p["terminal_wacc"], "terminal_wacc", 0, 1)
219
+ terminal_roic = positive(p["terminal_roic"], "terminal_roic")
220
+ shares = positive(p["diluted_shares"], "diluted_shares")
221
+ if terminal_wacc <= terminal_growth or terminal_growth > terminal_roic:
222
+ raise ValueError("terminal_wacc must exceed terminal_growth and terminal_growth must not exceed terminal_roic")
223
+ claims = {key: number(p.get(key, 0), key, 0) for key in ("cash", "debt", "minority_interests", "other_claims")}
224
+ nonoperating = number(p.get("nonoperating_assets", 0), "nonoperating_assets", 0)
225
+ projections, discount, pv_fcff = [], 1, 0
226
+ for year, (rate, margin, tax, wacc) in enumerate(zip(growth, margins, taxes, waccs), 1):
227
+ previous, revenue = revenue, revenue * (1 + rate)
228
+ ebit = revenue * margin
229
+ nopat = ebit * (1 - tax)
230
+ reinvestment = (revenue - previous) / sales_to_capital
231
+ fcff = nopat - reinvestment
232
+ discount *= 1 + wacc
233
+ present_value = fcff / discount
234
+ pv_fcff += present_value
235
+ projections.append(
236
+ {
237
+ "year": year,
238
+ "revenue": revenue,
239
+ "ebit": ebit,
240
+ "nopat": nopat,
241
+ "reinvestment": reinvestment,
242
+ "fcff": fcff,
243
+ "discount_factor": 1 / discount,
244
+ "present_value": present_value,
245
+ }
246
+ )
247
+
248
+ def value(terminal_wacc_value, terminal_growth_value):
249
+ terminal_nopat = revenue * (1 + terminal_growth_value) * margins[-1] * (1 - taxes[-1])
250
+ reinvestment_rate = terminal_growth_value / terminal_roic
251
+ terminal_fcff = terminal_nopat * (1 - reinvestment_rate)
252
+ terminal_value = terminal_fcff / (terminal_wacc_value - terminal_growth_value)
253
+ enterprise = pv_fcff + terminal_value / discount
254
+ equity = enterprise + claims["cash"] + nonoperating - claims["debt"] - claims["minority_interests"]
255
+ equity -= claims["other_claims"]
256
+ return terminal_nopat, reinvestment_rate, terminal_fcff, terminal_value, enterprise, equity
257
+
258
+ terminal_nopat, reinvestment_rate, terminal_fcff, terminal_value, enterprise, equity = value(
259
+ terminal_wacc, terminal_growth
260
+ )
261
+ per_share = equity / shares
262
+ price = p.get("current_price")
263
+ if price is not None:
264
+ price = positive(price, "current_price")
265
+ sensitivity = []
266
+ for wacc_shift in (-0.01, 0, 0.01):
267
+ for growth_shift in (-0.005, 0, 0.005):
268
+ wacc_value, growth_value = terminal_wacc + wacc_shift, terminal_growth + growth_shift
269
+ valid = 0 <= wacc_value <= 1 and wacc_value > growth_value and growth_value <= terminal_roic
270
+ sensitivity.append(
271
+ {
272
+ "terminal_wacc": wacc_value,
273
+ "terminal_growth": growth_value,
274
+ "value_per_share": value(wacc_value, growth_value)[5] / shares if valid else None,
275
+ }
276
+ )
277
+ return {
278
+ "currency": text(p["currency"], "currency"),
279
+ "units": text(p["units"], "units"),
280
+ "valuation": {
281
+ "enterprise_value": enterprise,
282
+ "equity_value": equity,
283
+ "value_per_share": per_share,
284
+ "upside_pct": (per_share / price - 1) * 100 if price is not None else None,
285
+ "pv_fcff": pv_fcff,
286
+ "pv_terminal_value": terminal_value / discount,
287
+ "terminal_value_pct": terminal_value / discount / enterprise * 100 if enterprise > 0 else None,
288
+ },
289
+ "projections": projections,
290
+ "terminal": {
291
+ "nopat": terminal_nopat,
292
+ "reinvestment_rate": reinvestment_rate,
293
+ "fcff": terminal_fcff,
294
+ "value": terminal_value,
295
+ },
296
+ "sensitivity": sensitivity,
297
+ "assumptions": {
298
+ "model": "FCFF",
299
+ "sales_to_capital": sales_to_capital,
300
+ "terminal_growth": terminal_growth,
301
+ "terminal_wacc": terminal_wacc,
302
+ "terminal_roic": terminal_roic,
303
+ "diluted_shares": shares,
304
+ **claims,
305
+ "nonoperating_assets": nonoperating,
306
+ },
307
+ "warnings": [
308
+ "Input-driven valuation, not a forecast or trade signal. Amounts and shares must use one consistent currency and unit."
309
+ ],
310
+ }
311
+
312
+
199
313
  def rows(value, name, minimum=1, maximum=100):
200
314
  if not isinstance(value, list) or not minimum <= len(value) <= maximum:
201
315
  raise ValueError(f"{name} has invalid row count")
@@ -1136,6 +1250,7 @@ def robustness(p):
1136
1250
 
1137
1251
  COMMANDS = {
1138
1252
  "position_size": position_size,
1253
+ "dcf": dcf,
1139
1254
  "portfolio": portfolio,
1140
1255
  "rebalance": rebalance,
1141
1256
  "peers": peers,