"Vibe-Trading: Your Personal Trading Agent"
Python ai-agentalgorithmic-tradingbacktestingfintechllmmcpmulti-agentpythonquantitative-financetrading
fix(paper-trade): detect 3:2 splits quantized just inside the neutral band (#1985)
Rudy Celekli6ccfd1b76f5e
diff --git a/agent/src/tools/paper_trade/corporate_actions.py b/agent/src/tools/paper_trade/corporate_actions.pyindex e93e9a146..f817ce3fd 100644--- a/agent/src/tools/paper_trade/corporate_actions.py+++ b/agent/src/tools/paper_trade/corporate_actions.py@@ -183,10 +183,6 @@ def classify_boundary(observed = dec_after / dec_before # Decimal division (28-digit context)price_ratio = Fraction(dec_after) / Fraction(dec_before) # exact, for gates- # Candidate band: outside (2/3, 3/2). ratio == 1 is inside → no event.- if _BAND_LOW < price_ratio < _BAND_HIGH:- return BoundaryVerdict(KIND_NONE, observed_ratio=observed)-# Price gate: does the ratio match 1/mult for a frozen clean multiplier?matched: Fraction | None = Nonefor mult in CLEAN_QTY_MULTIPLIERS:@@ -194,6 +190,12 @@ def classify_boundary(if abs(price_ratio - clean_price) <= PRICE_RATIO_REL_TOL * clean_price:matched = multbreak++ # Candidate band: outside (2/3, 3/2). ratio == 1 is inside → no event.+ # A 3:2 or 2:3 ratio quantized to just inside a bound is still a match.+ if matched is None and _BAND_LOW < price_ratio < _BAND_HIGH:+ return BoundaryVerdict(KIND_NONE, observed_ratio=observed)+if matched is None:# Candidate but no clean ratio explains it → fail-closed unresolved.return BoundaryVerdict(KIND_UNRESOLVED, observed_ratio=observed)diff --git a/agent/tests/test_paper_trade_corporate_actions.py b/agent/tests/test_paper_trade_corporate_actions.pyindex cf09438c2..bf744fdad 100644--- a/agent/tests/test_paper_trade_corporate_actions.py+++ b/agent/tests/test_paper_trade_corporate_actions.py@@ -192,6 +192,21 @@ def test_neutral_band_moves_are_not_candidates(before: float, after: float) -> Nassert verdict.kind == corporate_actions.KIND_NONE[email protected](("before", "after", "vol_before", "vol_after", "mult"), [+ (30.0, 20.01, 1000.0, 1500.0, Fraction(3, 2)), # 3:2 split, ratio 0.667+ (20.0, 29.98, 1500.0, 1000.0, Fraction(2, 3)), # 2:3 reverse, ratio 1.499+])+def test_quantized_three_two_ratio_just_inside_the_band_is_still_a_candidate(+ before: float, after: float, vol_before: float, vol_after: float, mult: Fraction) -> None:+ kwargs = dict(close_before=before, close_after=after,+ volume_before=vol_before, volume_after=vol_after)+ flat = corporate_actions.classify_boundary(qty=Decimal(0), **kwargs)+ assert flat.kind == corporate_actions.KIND_CLEAN+ assert flat.qty_multiplier == mult+ held = corporate_actions.classify_boundary(qty=Decimal(100), **kwargs)+ assert held.kind == corporate_actions.KIND_UNRESOLVED++@pytest.mark.parametrize(("before", "after"), [(0.0, 100.0), (-5.0, 100.0), (float("nan"), 100.0), (100.0, float("nan")), (100.0, 0.0),])