"Vibe-Trading: Your Personal Trading Agent"
Python ai-agentalgorithmic-tradingbacktestingfintechllmmcpmulti-agentpythonquantitative-financetrading
fix(backtest): extract product code from digit-prefixed currency futures
Lanre Shittu04b32ffd9c3d
diff --git a/agent/backtest/engines/global_futures.py b/agent/backtest/engines/global_futures.pyindex 9b7666e20..d4c545bbd 100644--- a/agent/backtest/engines/global_futures.py+++ b/agent/backtest/engines/global_futures.py@@ -104,26 +104,30 @@ def _extract_product(symbol: str) -> str:- Product.exchange: ES.CME- Bare product: ES+ CME currency futures (6E, 6J, 6B, 6A, 6C) start with a digit, so the+ product group also accepts a single leading digit followed by one+ letter (e.g. 6EZ4 -> 6E), on top of the plain 2-4 letter form.+Args:symbol: Futures symbol string.Returns:- Product code (e.g. 'ES', 'CL', 'GC').+ Product code (e.g. 'ES', 'CL', 'GC', '6E')."""code = symbol.split(".")[0].upper()- # Pattern 1: product + month-code + year (ESZ4, CLF25, GCM2025)- m = re.match(r"([A-Z]{2,4})([FGHJKMNQUVXZ])(\d{1,4})$", code)+ # Pattern 1: product + month-code + year (ESZ4, CLF25, GCM2025, 6EZ4)+ m = re.match(r"(\d[A-Z]|[A-Z]{2,4})([FGHJKMNQUVXZ])(\d{1,4})$", code)if m:return m.group(1)- # Pattern 2: product + YYMM (NQ2503, CL2412)- m = re.match(r"([A-Z]+)(\d{4})$", code)+ # Pattern 2: product + YYMM (NQ2503, CL2412, 6EH25)+ m = re.match(r"(\d?[A-Z]+)(\d{4})$", code)if m:return m.group(1)# Pattern 3: bare product or fallback- m = re.match(r"([A-Z]+)", code)+ m = re.match(r"(\d?[A-Z]+)", code)return m.group(1) if m else codediff --git a/agent/tests/test_global_futures_engine.py b/agent/tests/test_global_futures_engine.pyindex f0fea8c9a..d914687f9 100644--- a/agent/tests/test_global_futures_engine.py+++ b/agent/tests/test_global_futures_engine.py@@ -65,6 +65,10 @@ class TestExtractProduct:("NQ2503", "NQ"),("ES.CME", "ES"),("ZCH4", "ZC"),+ ("6EZ4", "6E"),+ ("6JH25", "6J"),+ ("6B", "6B"),+ ("6A.CME", "6A"),],)def test_extract(self, symbol: str, expected: str) -> None:@@ -198,6 +202,9 @@ class TestContractMultiplier:("ZCH4", 50),("ZBM5", 1000),("MESZ4", 5),+ ("6EZ4", 125000),+ ("6JH25", 12500000),+ ("6B", 62500),],)def test_multipliers(self, symbol: str, expected: float) -> None: