"Vibe-Trading: Your Personal Trading Agent"
Python ai-agentalgorithmic-tradingbacktestingfintechllmmcpmulti-agentpythonquantitative-financetrading
fix(grounding): keep checking asserted forex quotes, mask only conversions
Haozhe Wu35f7e11223e9
diff --git a/agent/src/agent/grounding.py b/agent/src/agent/grounding.pyindex be5b1c431..8b695207d 100644--- a/agent/src/agent/grounding.py+++ b/agent/src/agent/grounding.py@@ -319,10 +319,16 @@ _LINE_REFERENCE_RE = re.compile(_NUMBERED_HEADING_RE = re.compile(r"(?m)^\s*#{1,6}\s*\d+(?:[.、.])?\s*")# A ratio ("6:1 折算", "10:1") names a conversion basis, not a quote price._RATIO_RE = re.compile(r"\d+(?:\.\d+)?\s*[::]\s*\d+(?:\.\d+)?")-# A forex pair and its rate ("USD/CAD≈1.36") names a currency conversion, not-# an instrument quote. The plain 汇率/“exchange rate” form is the same class.+# A currency conversion cited inside a report ("USD/CAD≈1.36") is a basis, not+# an instrument quote. But `EUR/USD` IS this project's canonical forex symbol+# (``backtest/engines/forex.py``, and akshare_loader accepts the slash form), so+# masking every ``AAA/BBB <number>`` would stop checking real FX quotes on a+# first-class market — an invented rate would pass. The pair form therefore+# requires an approximation marker, which a conversion basis carries and a quote+# does not: "USD/CAD≈1.36" is masked, bare "USD/CAD 1.36" stays checked. The+# labelled 汇率 / "exchange rate" form is unambiguous and needs no marker._FX_RATE_RE = re.compile(- r"[A-Z]{3}\s*/\s*[A-Z]{3}\s*(?:≈|~|=|约|为)?\s*\d+(?:\.\d+)?"+ r"[A-Z]{3}\s*/\s*[A-Z]{3}\s*(?:≈|~|约)\s*\d+(?:\.\d+)?"r"|(?:汇率|FX\s*rate|exchange\s+rate)\s*(?:≈|~|=|为|是)?\s*\d+(?:\.\d+)?",re.IGNORECASE,)diff --git a/agent/tests/test_agent_grounding.py b/agent/tests/test_agent_grounding.pyindex c7ea600e6..6f4539865 100644--- a/agent/tests/test_agent_grounding.py+++ b/agent/tests/test_agent_grounding.py@@ -1443,8 +1443,13 @@ _RATIO_AND_FX_SEGMENTS = [("TO 报价实际是按 6:1 平价锚定的", []),("25/25 行 OHLCV、25/25 项派生百分比、7/7 日 CDR 6:1 折算", []),("远小于当前 USD/CAD≈1.36 的量级", []),- ("usd/cad=1.36", []),("汇率 1.36", []),+ # `EUR/USD` is this project's canonical forex symbol, so an asserted pair+ # rate is a quote and stays checked; only an approximated conversion basis+ # is masked. Masking both would let an invented FX rate through the gate.+ ("usd/cad=1.36", [1.36]),+ ("USD/CAD 1.36", [1.36]),+ ("USD/CAD ≈ 1.36", []),]