Upload engine/predict_yearly.py with huggingface_hub
Browse files- engine/predict_yearly.py +22 -8
engine/predict_yearly.py
CHANGED
|
@@ -7401,15 +7401,23 @@ def _peer_comps(ticker, sector, mcap, n=8):
|
|
| 7401 |
try:
|
| 7402 |
import glob as _g
|
| 7403 |
import damodaran_portfolio as _dp
|
| 7404 |
-
|
| 7405 |
-
|
| 7406 |
-
|
| 7407 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7408 |
cur = df[df.week_ending == df.week_ending.max()].copy()
|
| 7409 |
cur = cur[cur.marketcap > 0]
|
| 7410 |
me = cur[cur.ticker == ticker.upper()]
|
| 7411 |
sec = (me.sector.iloc[0] if len(me) else None) or sector
|
| 7412 |
-
|
|
|
|
| 7413 |
if len(pool) < 3:
|
| 7414 |
return None
|
| 7415 |
ref = float(me.marketcap.iloc[0]) if len(me) else float(mcap or pool.marketcap.median())
|
|
@@ -7785,7 +7793,8 @@ Examples:
|
|
| 7785 |
_cats.append({"date": e.get("date"), "event": e.get("event"), "kind": "corporate (recalled)"})
|
| 7786 |
except Exception:
|
| 7787 |
pass
|
| 7788 |
-
|
|
|
|
| 7789 |
all_data["risk_card"] = _risk_card(all_data, _ovs)
|
| 7790 |
if all_data["corp_events"]:
|
| 7791 |
print(" [events] " + " | ".join(f"{e['date']}: {e['event'][:60]}" for e in all_data["corp_events"][:3]))
|
|
@@ -8191,15 +8200,20 @@ Examples:
|
|
| 8191 |
e = (_ld.get(rnd) or {}).get(key) or {}
|
| 8192 |
kps = e.get("key_points") or []
|
| 8193 |
return (kps[0].get("point") if kps and isinstance(kps[0], dict) else None)
|
| 8194 |
-
|
| 8195 |
-
|
|
|
|
| 8196 |
_rd["view_triggers"] = {"more_bearish_if": _bear_pt, "more_bullish_if": _bull_pt}
|
| 8197 |
# provenance
|
| 8198 |
_inc0 = ((all_data.get("income") or {}).get("quarterlyReports") or [{}])[0] or {}
|
| 8199 |
_ov = all_data.get("overview") or {}
|
| 8200 |
_px_asof = str(all_data["daily"].index.max().date()) if all_data.get("daily") is not None else None
|
| 8201 |
_stq = _inc0.get("fiscalDateEnding"); _ovq = _ov.get("LatestQuarter")
|
|
|
|
|
|
|
|
|
|
| 8202 |
_rd["provenance"] = {
|
|
|
|
| 8203 |
"price_as_of": _px_asof, "statements_latest_quarter": _stq, "overview_latest_quarter": _ovq,
|
| 8204 |
"quarter_mismatch": bool(_stq and _ovq and str(_stq)[:7] != str(_ovq)[:7]),
|
| 8205 |
"analysts_in_consensus": int((all_data.get("earnings_estimates_consensus") or {}).get("analyst_count") or 0),
|
|
|
|
| 7401 |
try:
|
| 7402 |
import glob as _g
|
| 7403 |
import damodaran_portfolio as _dp
|
| 7404 |
+
_cols = ["week_ending", "ticker", "sector", "marketcap", "pe", "ev_ebitda",
|
| 7405 |
+
"sales_yield", "fcf_yield", "operating_margin", "gross_margin",
|
| 7406 |
+
"rev_growth_yoy", "net_debt_ebitda", "dividend_yield", "roe", "beta_mkt"]
|
| 7407 |
+
_full = sorted(_g.glob(f"{_dp.PANEL}/*.parquet")) if os.path.isdir(_dp.PANEL) else []
|
| 7408 |
+
if _full:
|
| 7409 |
+
df = pd.read_parquet(_full[-1], columns=_cols)
|
| 7410 |
+
else:
|
| 7411 |
+
# Space: the full panel lives on the research machine; a slim weekly extract of
|
| 7412 |
+
# the peer metrics is vendored alongside the engine.
|
| 7413 |
+
_slim = os.path.join(os.path.dirname(os.path.abspath(__file__)), "peer_metrics.parquet")
|
| 7414 |
+
df = pd.read_parquet(_slim)
|
| 7415 |
cur = df[df.week_ending == df.week_ending.max()].copy()
|
| 7416 |
cur = cur[cur.marketcap > 0]
|
| 7417 |
me = cur[cur.ticker == ticker.upper()]
|
| 7418 |
sec = (me.sector.iloc[0] if len(me) else None) or sector
|
| 7419 |
+
_secn = str(sec or "").strip().lower()
|
| 7420 |
+
pool = cur[(cur.sector.astype(str).str.strip().str.lower() == _secn) & (cur.ticker != ticker.upper())].copy()
|
| 7421 |
if len(pool) < 3:
|
| 7422 |
return None
|
| 7423 |
ref = float(me.marketcap.iloc[0]) if len(me) else float(mcap or pool.marketcap.median())
|
|
|
|
| 7793 |
_cats.append({"date": e.get("date"), "event": e.get("event"), "kind": "corporate (recalled)"})
|
| 7794 |
except Exception:
|
| 7795 |
pass
|
| 7796 |
+
_today = datetime.now().strftime("%Y-%m-%d")
|
| 7797 |
+
all_data["catalysts"] = [c for c in _cats if c.get("kind") == "corporate (recalled)" or (c.get("date") and str(c["date"]) >= _today)]
|
| 7798 |
all_data["risk_card"] = _risk_card(all_data, _ovs)
|
| 7799 |
if all_data["corp_events"]:
|
| 7800 |
print(" [events] " + " | ".join(f"{e['date']}: {e['event'][:60]}" for e in all_data["corp_events"][:3]))
|
|
|
|
| 8200 |
e = (_ld.get(rnd) or {}).get(key) or {}
|
| 8201 |
kps = e.get("key_points") or []
|
| 8202 |
return (kps[0].get("point") if kps and isinstance(kps[0], dict) else None)
|
| 8203 |
+
# Round-1 points stand alone; rebuttal points refer back to the opponent ("Those…").
|
| 8204 |
+
_bear_pt = _first_point("round1", "kimi") or _first_point("round2", "kimi")
|
| 8205 |
+
_bull_pt = _first_point("round1", "gpt") or _first_point("round2", "gpt")
|
| 8206 |
_rd["view_triggers"] = {"more_bearish_if": _bear_pt, "more_bullish_if": _bull_pt}
|
| 8207 |
# provenance
|
| 8208 |
_inc0 = ((all_data.get("income") or {}).get("quarterlyReports") or [{}])[0] or {}
|
| 8209 |
_ov = all_data.get("overview") or {}
|
| 8210 |
_px_asof = str(all_data["daily"].index.max().date()) if all_data.get("daily") is not None else None
|
| 8211 |
_stq = _inc0.get("fiscalDateEnding"); _ovq = _ov.get("LatestQuarter")
|
| 8212 |
+
_gaps = [n for n, k in (("company profile", "overview"), ("income statements", "income"),
|
| 8213 |
+
("balance sheets", "balance"), ("cash-flow statements", "cashflow"),
|
| 8214 |
+
("earnings history", "earnings")) if not all_data.get(k)]
|
| 8215 |
_rd["provenance"] = {
|
| 8216 |
+
"data_gaps": _gaps,
|
| 8217 |
"price_as_of": _px_asof, "statements_latest_quarter": _stq, "overview_latest_quarter": _ovq,
|
| 8218 |
"quarter_mismatch": bool(_stq and _ovq and str(_stq)[:7] != str(_ovq)[:7]),
|
| 8219 |
"analysts_in_consensus": int((all_data.get("earnings_estimates_consensus") or {}).get("analyst_count") or 0),
|