From 2ab2913bb0b808d7a28abcbf26629c9307bf16bd Mon Sep 17 00:00:00 2001 From: Claude Date: Thu, 14 May 2026 04:48:35 +0000 Subject: [PATCH] fix(main): pe_ttm in raw_metrics still used eps_diluted (PR #49 missed consumer) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Final audit of post-PR-#49 production output revealed PE distribution median was 77.8 — virtually unchanged from the pre-fix 77.5. PR #49 fixed `pe_ratio` (Value pillar), `_build_universe_metrics` (peer median), `multiples_pe_fair_price` (fair-price method), and `graham_number` — but missed THIS one: `_build_raw_metrics` in compute/main.py builds the RawMetrics object that surfaces in the StockSummary / StockDetail JSON output, and it was still computing: pe_ttm = current_price / snapshot.eps_diluted # single-period bug This is the field that shows up as `raw_metrics.pe_ratio_ttm` in the public JSON the frontend renders. With this missed consumer, the production output kept shipping inflated PEs even after PR #49 merged (AAPL 61.6 vs correct 35.7, TSLA 3425 vs correct 432, ABBV 534 vs correct 105, ... 88.6% of universe). Fix: route through `NI_TTM / shares_outstanding`, matching the same formula in the other 4 already-fixed consumers. Validation pending workflow_dispatch re-run + audit. Expected: production median PE drops 77.8 → ~26 (target). Other corruption fixes already taking effect post-PR-#49 confirmed: - NVDA $215.9B revenue ✓ - AVB $3.1B (was $7M) ✓ - WMT 7.97B shares post-split ✓ - META 2.564B shares (was None) ✓ - BKNG NI $6.2B (was None) ✓ - WFC $85B / GS $60B / DUK $33B revenue ✓ - Beneish coverage 6.8% → 31.9% ✓ (5x improvement) - |NI|>|rev| corruption: 17 → 4 tickers ✓ This PR closes the last loose end of the audit-#6 deep-clean cycle. Full offline suite: 646 / 646 pass. https://claude.ai/code/session_015649aRyi2bvciQYZVNACd2 --- compute/main.py | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/compute/main.py b/compute/main.py index 78b54fa17..0eb9a86f8 100644 --- a/compute/main.py +++ b/compute/main.py @@ -238,11 +238,22 @@ def _build_raw_metrics( if snapshot.shares_outstanding is not None else None ) - pe_ttm = ( - current_price / snapshot.eps_diluted - if snapshot.eps_diluted is not None and snapshot.eps_diluted > 0 - else None - ) + # PE shown in raw_metrics.pe_ratio_ttm — derive TTM EPS from + # NI_TTM / shares_outstanding rather than snap.eps_diluted (single- + # period). Audit #6 follow-up: this _build_raw_metrics helper was + # missed in PR #49 — production median PE stayed at 77.5 (broken) + # instead of dropping to ~26 (correct) until this fix lands. + pe_ttm: float | None = None + if ( + snapshot.net_income is not None + and snapshot.net_income > 0 + and snapshot.shares_outstanding is not None + and snapshot.shares_outstanding > 0 + and current_price > 0 + ): + ttm_eps = snapshot.net_income / snapshot.shares_outstanding + if ttm_eps > 0: + pe_ttm = current_price / ttm_eps return RawMetrics( revenue=snapshot.revenue, net_income=snapshot.net_income,