"Vibe-Trading: Your Personal Trading Agent"
Python ai-agentalgorithmic-tradingbacktestingfintechllmmcpmulti-agentpythonquantitative-financetrading
fix(tools): normalize three_scenario growth > 1 as percent
sambazhu93da172460ce
diff --git a/agent/src/tools/financial_rigor_tool.py b/agent/src/tools/financial_rigor_tool.pyindex 44f502f20..2d5a7e0e5 100644--- a/agent/src/tools/financial_rigor_tool.py+++ b/agent/src/tools/financial_rigor_tool.py@@ -401,8 +401,14 @@ def three_scenario_valuation(("bear", growth_pessimistic, pe_pessimistic),]scenarios: list[dict[str, Any]] = []+ normalized: list[str] = []for name, growth, pe in spec:g, target_pe = _exact(growth), _exact(pe)+ # Defensive: LLMs frequently pass "15%" as 15 instead of 0.15. Treat+ # |growth| > 1 (i.e. > 100%) as a percent and normalize, flagging it.+ if abs(float(g)) > 1:+ g = _CTX.divide(g, Decimal("100"))+ normalized.append(name)future_eps = epsfor _ in range(int(years)):future_eps = _CTX.multiply(future_eps, _CTX.add(Decimal("1"), g))@@ -416,7 +422,7 @@ def three_scenario_valuation("target_price": float(target_price),"upside_pct": round(upside, 2),})- return {+ result: dict[str, Any] = {"current_price": float(p),"current_eps": float(eps),"shares_billion": float(shares),@@ -424,6 +430,13 @@ def three_scenario_valuation("currency": currency,"scenarios": scenarios,}+ if normalized:+ result["growth_normalized_from_percent"] = normalized+ result["note"] = (+ f"growth values > 1 (100%) were treated as percentages and divided "+ f"by 100 for scenarios: {normalized}. Pass 0.15 for 15% to avoid this."+ )+ return resultclass FinancialRigorTool(BaseTool):@@ -487,7 +500,7 @@ class FinancialRigorTool(BaseTool):"growth": {"type": "array", "items": {"type": "number"},"minItems": 3, "maxItems": 3,- "description": "three_scenario: annual EPS growth [bull, base, bear].",+ "description": "three_scenario: annual EPS growth as a decimal [bull, base, bear], e.g. 0.15 for 15% (values > 1 are auto-treated as percent).",},"pe": {"type": "array", "items": {"type": "number"},diff --git a/agent/tests/test_financial_rigor_tool.py b/agent/tests/test_financial_rigor_tool.pyindex 0a3bf6121..3792f63ae 100644--- a/agent/tests/test_financial_rigor_tool.py+++ b/agent/tests/test_financial_rigor_tool.py@@ -187,6 +187,23 @@ def test_three_scenario_future_eps_compounding() -> None:assert bear["upside_pct"] < 0 # bear case is below current price+def test_three_scenario_normalizes_percent_growth() -> None:+ # LLMs often pass 15 instead of 0.15; |g| > 1 is treated as a percent.+ out = three_scenario_valuation(+ current_price=510, current_eps=23.5, shares_billion=9.11,+ growth_optimistic=15, growth_neutral=8, growth_pessimistic=0,+ pe_optimistic=25, pe_neutral=20, pe_pessimistic=15, years=3,+ )+ bull = next(s for s in out["scenarios"] if s["scenario"] == "bull")+ assert bull["future_eps"] == pytest.approx(23.5 * 1.15 ** 3) # 15 -> 0.15+ assert bull["annual_growth"] == pytest.approx(0.15)+ assert "bull" in out["growth_normalized_from_percent"]+ # bear g=0 is not normalized (|0| is not > 1).+ bear = next(s for s in out["scenarios"] if s["scenario"] == "bear")+ assert bear["future_eps"] == 23.5+ assert "bear" not in out.get("growth_normalized_from_percent", [])++# ── tool contract ─────────────────────────────────────────────────────────