"Vibe-Trading: Your Personal Trading Agent"
Python ai-agentalgorithmic-tradingbacktestingfintechllmmcpmulti-agentpythonquantitative-financetrading
fix(journal): read European 1.234,56 amounts instead of 1.23456
Rudy Celeklidcbf583c8dcd
diff --git a/agent/src/tools/trade_journal_parsers.py b/agent/src/tools/trade_journal_parsers.pyindex 05e316544..7eacbd72b 100644--- a/agent/src/tools/trade_journal_parsers.py+++ b/agent/src/tools/trade_journal_parsers.py@@ -318,7 +318,14 @@ def _to_float(val: Any, default: float = 0.0) -> float:return defaulttry:s = str(val).strip().replace("\u2212", "-")- s = _CURRENCY_TOKEN_RE.sub("", s).replace(",", "").strip()+ s = _CURRENCY_TOKEN_RE.sub("", s)+ if "," in s and "." in s and s.rfind(",") > s.rfind("."):+ # "1.234,56": the rightmost separator is the decimal one, so dots+ # group thousands. Stripping only commas read it as 1.23456.+ s = s.replace(".", "").replace(",", ".")+ else:+ s = s.replace(",", "")+ s = s.strip()if not s:return default# Accounting exports write a negative as "(1,234.50)" (optionallydiff --git a/agent/tests/test_trade_journal_parser_european_decimal.py b/agent/tests/test_trade_journal_parser_european_decimal.pynew file mode 100644index 000000000..29e1bb50d--- /dev/null+++ b/agent/tests/test_trade_journal_parser_european_decimal.py@@ -0,0 +1,30 @@+"""European "1.234,56" cells must not be read as 1.23456."""++from __future__ import annotations++import pytest++from src.tools.trade_journal_parsers import _to_float+++ ("raw", "expected"),+ [+ ("1.234,56", 1234.56),+ ("1.234.567,5", 1234567.5),+ ("€1.234,56", 1234.56),+ ("-1.234,56", -1234.56),+ ("(1.234,56)", -1234.56),+ ("12.345,6 EUR", 12345.6),+ ],+)+def test_comma_decimal_with_dot_grouping(raw: str, expected: float) -> None:+ assert _to_float(raw) == pytest.approx(expected)+++ ("raw", "expected"),+ [("1,234.56", 1234.56), ("1,234,567.89", 1234567.89), ("1,234", 1234.0), ("12.5", 12.5), ("$1,000", 1000.0)],+)+def test_us_formats_are_unchanged(raw: str, expected: float) -> None:+ assert _to_float(raw) == pytest.approx(expected)