Skip to content

"Vibe-Trading: Your Personal Trading Agent"

fix(rigor): omit earnings and FCF yield when the price is zero

Rudy Celekli4dc13b3dcc82
diff --git a/agent/src/tools/financial_rigor_tool.py b/agent/src/tools/financial_rigor_tool.py
index 2c8af2573..c15495d24 100644
--- a/agent/src/tools/financial_rigor_tool.py
+++ b/agent/src/tools/financial_rigor_tool.py
@@ -192,7 +192,9 @@ def verify_valuation(
"""Derive valuation ratios from raw per-share inputs (exact decimal).
Each optional input, when supplied and non-zero, contributes its metric(s).
- ROE additionally requires both ``eps`` and ``bvps``.
+ ROE additionally requires both ``eps`` and ``bvps``. Earnings yield and
+ FCF yield also need a non-zero price; a zero price omits them, the same
+ way dividend yield already does, instead of raising.
Args:
price: Current share price.
@@ -212,7 +214,8 @@ def verify_valuation(
e = _exact(eps)
if e != 0:
metrics["PE"] = float(_CTX.divide(p, e))
- metrics["earnings_yield_pct"] = float(_CTX.divide(e, p) * 100)
+ if p != 0:
+ metrics["earnings_yield_pct"] = float(_CTX.divide(e, p) * 100)
if bvps is not None:
b = _exact(bvps)
if b != 0:
@@ -223,7 +226,8 @@ def verify_valuation(
f = _exact(fcf_per_share)
if f != 0:
metrics["P_FCF"] = float(_CTX.divide(p, f))
- metrics["FCF_yield_pct"] = float(_CTX.divide(f, p) * 100)
+ if p != 0:
+ metrics["FCF_yield_pct"] = float(_CTX.divide(f, p) * 100)
if dividend is not None:
d = _exact(dividend)
if p != 0:
diff --git a/agent/tests/test_financial_rigor_tool.py b/agent/tests/test_financial_rigor_tool.py
index 101b3f4f6..f705a016d 100644
--- a/agent/tests/test_financial_rigor_tool.py
+++ b/agent/tests/test_financial_rigor_tool.py
@@ -135,6 +135,21 @@ def test_valuation_skips_zero_and_missing_inputs() -> None:
assert verify_valuation(price=100, eps=0, bvps=None)["metrics"] == {}
+def test_yields_are_omitted_when_the_price_is_zero() -> None:
+ # Earnings yield and FCF yield divide by price. A zero price used to raise
+ # decimal.DivisionByZero; dividend yield already omitted itself.
+ metrics = verify_valuation(
+ price=0, eps=2, bvps=10, fcf_per_share=1, dividend=0.5, revenue_per_share=8,
+ )["metrics"]
+ assert "earnings_yield_pct" not in metrics
+ assert "FCF_yield_pct" not in metrics
+ assert "dividend_yield_pct" not in metrics
+ assert metrics["PE"] == 0
+ assert metrics["P_FCF"] == 0
+ assert metrics["PS"] == 0
+ assert metrics["ROE_pct"] == pytest.approx(20)
+
+
# ── cross_validate ────────────────────────────────────────────────────────