"Vibe-Trading: Your Personal Trading Agent"
Python ai-agentalgorithmic-tradingbacktestingfintechllmmcpmulti-agentpythonquantitative-financetrading
refactor(market-data): scope UK support to LSE (.L) only, drop .IL
cgycorey25538bb478ce
diff --git a/agent/backtest/engines/_market_hooks.py b/agent/backtest/engines/_market_hooks.pyindex 8a13c624e..67145c080 100644--- a/agent/backtest/engines/_market_hooks.py+++ b/agent/backtest/engines/_market_hooks.py@@ -35,9 +35,9 @@ _MARKET_PATTERNS = [# Canada equities: Toronto Stock Exchange (TD.TO) and TSX Venture# (PNG.V). Yahoo carries both suffixes verbatim.(re.compile(r"^[A-Z0-9&.\-]+\.(TO|V)$", re.I), "ca_equity"),- # UK equities: London Stock Exchange (VOD.L, SHEL.L) and Irish Stock- # Exchange (DCC.IL). Yahoo carries both suffixes verbatim.- (re.compile(r"^[A-Z0-9&.\-]+\.(L|IL)$", re.I), "uk_equity"),+ # UK equities: London Stock Exchange (VOD.L, SHEL.L). Yahoo carries the+ # suffix verbatim.+ (re.compile(r"^[A-Z0-9&.\-]+\.L$", re.I), "uk_equity"),# Vietnam equities: HOSE (VIC.VN). Tickers are three letters in practice;# the class stays broad to admit fund certificates and ETF codes.(re.compile(r"^[A-Z0-9]+\.VN$", re.I), "vietnam_equity"),@@ -197,7 +197,7 @@ def _detect_submarket(codes: List[str]) -> str:Returns:``"hk"`` for ``.HK``, ``"ca"`` for ``.TO``/``.V``, ``"uk"`` for- ``.L``/``.IL``, else ``"us"``.+ ``.L``, else ``"us"``."""for code in codes:upper = code.upper()@@ -205,7 +205,7 @@ def _detect_submarket(codes: List[str]) -> str:return "hk"if upper.endswith((".TO", ".V")):return "ca"- if upper.endswith((".L", ".IL")):+ if upper.endswith(".L"):return "uk"return "us"diff --git a/agent/backtest/loaders/base.py b/agent/backtest/loaders/base.pyindex bf680bd49..fcd7e3194 100644--- a/agent/backtest/loaders/base.py+++ b/agent/backtest/loaders/base.py@@ -25,20 +25,20 @@ import relogger = logging.getLogger(__name__)-# Yahoo quotes LSE (.L) and GBp-quoted Irish (.IL) equities in pence, not-# pounds: VOD.L is ~117p, HSBA.L ~1500p. `code_currency`/`_MARKET_CURRENCY`+# Yahoo quotes LSE (.L) equities in pence, not pounds: VOD.L is ~117p,+# HSBA.L ~1500p. `code_currency`/`_MARKET_CURRENCY`# declare GBP, so prices must be normalized ÷100 when a source reports the# pence marker (HKUDS/Vibe-Trading#1206). Anything else is left untouched._GBP_PENCE_CURRENCY = "GBp"_PRICE_COLUMNS = ("open", "high", "low", "close")-_UK_EQUITY_PATTERN = re.compile(r"^[A-Z0-9&.\-]+\.(L|IL)$", re.I)+_UK_EQUITY_PATTERN = re.compile(r"^[A-Z0-9&.\-]+\.L$", re.I)def is_gbp_pence_symbol(code: str) -> bool:"""Return whether a project symbol quotes in GBp (LSE/ISE UK names).- Both Yahoo sources (direct chart + yfinance) serve ``.L`` (always) and- ``.IL`` (for GBp-quoted Irish listings) in pence. The engine-side+ Both Yahoo sources (direct chart + yfinance) serve ``.L`` names in pence.+ The engine-side``code_currency`` resolves these to GBP, so any loader emitting them mustnormalize ÷100 — callers with chart meta (Yahoo) pass the ``"GBp"``currency directly; sources without per-symbol meta (yfinance) fall back to@@ -293,7 +293,7 @@ _LOADER_CACHE_TRUE_VALUES = {"1", "true", "yes", "on"}# simply never matched (old files become unreachable garbage, safe to delete).# v4: baostock volume normalized from shares to lots (#1062) — entries cached# under the pre-normalization unit must never be served again.-# v5: UK (.L/.IL) prices normalized from GBp to GBP (÷100) (#1206) — entries+# v5: UK (.L) prices normalized from GBp to GBP (÷100) (#1206) — entries# cached under the pre-normalization pence values must never be served again._LOADER_CACHE_VERSION = 5diff --git a/agent/backtest/loaders/yahoo_loader.py b/agent/backtest/loaders/yahoo_loader.pyindex 0d8e88024..c725b14a3 100644--- a/agent/backtest/loaders/yahoo_loader.py+++ b/agent/backtest/loaders/yahoo_loader.py@@ -54,14 +54,14 @@ def _is_supported(code: str) -> bool:Covers US/HK/India/Korea/Canada/Vietnam/UK equities plus Yahoo's ownfutures (``GC=F``) and forex (``EURUSD=X``) suffix conventions, which thepublic chart endpoint serves verbatim (the code is used as-is in the- request URL, no conversion) (#718). UK ``.L``/``.IL`` comes in GBp and is+ request URL, no conversion) (#718). UK ``.L`` quotes in GBp and isnormalized to GBP at fetch time (#1206)."""upper = code.strip().upper()return upper.endswith((".US", ".HK", ".NS", ".BO", ".KS", ".KQ", ".TO", ".V", ".VN",- ".L", ".IL", "=F", "=X",+ ".L", "=F", "=X",))diff --git a/agent/backtest/loaders/yfinance_loader.py b/agent/backtest/loaders/yfinance_loader.pyindex 64849d4f1..d7d65c432 100644--- a/agent/backtest/loaders/yfinance_loader.py+++ b/agent/backtest/loaders/yfinance_loader.py@@ -330,7 +330,7 @@ class DataLoader:logger.warning("yfinance returned no usable data for %s", symbol)continue- # Yahoo-family data: .L/.IL UK names quote in GBp (pence).+ # Yahoo-family data: .L UK names quote in GBp (pence).# Normalize ÷100 so code_currency's GBP matches the values.if is_gbp_pence_symbol(symbol):normalized, _ = scale_pence_to_currency(normalized, "GBp")diff --git a/agent/mcp_server.py b/agent/mcp_server.pyindex ccb952598..04ddb3fdf 100644--- a/agent/mcp_server.py+++ b/agent/mcp_server.py@@ -2169,7 +2169,7 @@ def get_options_chain(ticker: str, expiration: int | None = None) -> str:@mcp.tooldef get_stock_profile(ticker: str, sections: _lenient_str_list_opt = None) -> str:- """Fetch a read-only company profile for a US, HK, or UK/Irish listing (Yahoo Finance).+ """Fetch a read-only company profile for a US, HK, or UK (LSE .L) listing (Yahoo Finance).Returns valuation key statistics, analyst price targets andearnings/revenue estimates, institutional and insider ownership, and the@@ -2178,7 +2178,7 @@ def get_stock_profile(ticker: str, sections: _lenient_str_list_opt = None) -> stArgs:ticker: US (bare or .US suffix), HK (zero-padded .HK code), or- UK/Irish (.L or .IL, e.g. VOD.L) symbol.+ UK (LSE .L, e.g. VOD.L) symbol.sections: Profile sections to return, any of: key_stats, financials,earnings_trend, institution_ownership, insider_holders,recommendation_trend. Defaults to all sections.diff --git a/agent/src/market_data.py b/agent/src/market_data.pyindex 4b35afeb4..02ea01bc7 100644--- a/agent/src/market_data.py+++ b/agent/src/market_data.py@@ -28,10 +28,10 @@ _SOURCE_PATTERNS = [(re.compile(r"^[A-Z0-9&.\-]+\.(NS|BO)$", re.I), "yahoo"),# Canada: Toronto Stock Exchange (TD.TO) / TSX Venture (PNG.V).(re.compile(r"^[A-Z0-9&.\-]+\.(TO|V)$", re.I), "yahoo"),- # UK: London Stock Exchange (VOD.L, SHEL.L) / Irish (DCC.IL). Yahoo serves- # both suffixes verbatim; without this they fell through to the tushare- # default and were routed to China-market loaders that cannot resolve them.- (re.compile(r"^[A-Z0-9&.\-]+\.(L|IL)$", re.I), "yahoo"),+ # UK: London Stock Exchange (VOD.L, SHEL.L). Yahoo serves the suffix+ # verbatim; without this they fell through to the tushare default and were+ # routed to China-market loaders that cannot resolve them.+ (re.compile(r"^[A-Z0-9&.\-]+\.L$", re.I), "yahoo"),# Yahoo futures (GC=F, CL=F) and forex (EURUSD=X) suffix conventions —# served verbatim by Yahoo's public chart endpoint (#718). Without these,# such symbols fell through to the ``tushare`` default and were routed todiff --git a/agent/src/skills/yfinance/references/tool_get_stock_profile.md b/agent/src/skills/yfinance/references/tool_get_stock_profile.mdindex c3b575852..84ac5244d 100644--- a/agent/src/skills/yfinance/references/tool_get_stock_profile.md+++ b/agent/src/skills/yfinance/references/tool_get_stock_profile.md@@ -21,7 +21,7 @@ The tool selects the right Yahoo quoteSummary modules, unwraps YahooName | Type | Required | Description---- | ---- | -------- | ------------ticker | str | Y | US (`AAPL` or `AAPL.US`), HK (`00700.HK`, zero-padded), or UK/Irish (`VOD.L`, `DCC.IL`) symbol.+ticker | str | Y | US (`AAPL` or `AAPL.US`), HK (`00700.HK`, zero-padded), or UK LSE (`VOD.L`) symbol.sections | list[str] | N | Which sections to return (one or more of the section names below). Defaults to all sections. Unknown names return an error envelope.Section name → underlying Yahoo module:@@ -49,7 +49,7 @@ On success:"data": {"ticker": "<input>", "sections": {"<name>": <shaped>}}}```-`market` is `hk` when the ticker ends `.HK`, `uk` when it ends `.L`/`.IL`,+`market` is `hk` when the ticker ends `.HK`, `uk` when it ends `.L`,else `us`. Scalar sections(`key_stats`, `financials`) shape to a flat dict; list sections(`earnings_trend`, `institution_ownership`, `insider_holders`,diff --git a/agent/src/tools/financial_statements_tool.py b/agent/src/tools/financial_statements_tool.pyindex f32491dff..386bdc267 100644--- a/agent/src/tools/financial_statements_tool.py+++ b/agent/src/tools/financial_statements_tool.py@@ -291,7 +291,7 @@ def _fetch_eastmoney_statement(# Yahoo quoteSummary module + result-key per (statement, cadence). UK-# (.L/.IL) names have no Eastmoney or SEC filing pipeline; Yahoo's+# (.L) names have no Eastmoney or SEC filing pipeline; Yahoo's# crumb-gated quoteSummary serves annual and quarterly histories for# LSE/ISE tickers (UK parity, #1206)._YAHOO_STATEMENT_MODULES: dict[tuple[str, str], tuple[str, str]] = {@@ -328,10 +328,10 @@ def _yahoo_value(value: Any) -> Any:def _fetch_yahoo_statement(code: str, *, statement: str, period: str) -> dict[str, Any]:- """Fetch one UK (.L/.IL) statement/indicators from Yahoo quoteSummary.+ """Fetch one UK (.L) statement/indicators from Yahoo quoteSummary.Args:- code: UK symbol (e.g. ``"VOD.L"`` or ``"DCC.IL"``).+ code: UK symbol (e.g. ``"VOD.L"``).statement: One of :data:`_VALID_STATEMENTS`.period: ``"annual"`` or ``"quarter"`` — selects the correspondinghistory module; both exist for LSE/ISE tickers.@@ -674,7 +674,7 @@ def _classify_market(code: str) -> str | None:return "us"if suffix == "HK":return "hk"- if suffix in ("L", "IL"):+ if suffix == "L":# London Stock Exchange / Irish Stock Exchange (#1206).return "uk"return None@@ -688,7 +688,7 @@ class FinancialStatementsTool(BaseTool):"Fetch a single stock's financial statements: balance sheet, income ""statement, cash-flow statement, or key per-period indicators (margins, ""ROE, EPS, etc.). Markets: A-share (.SH/.SZ/.BJ), US (.US), "- "Hong Kong (.HK) and UK/Irish (.L/.IL). US uses SEC EDGAR companyfacts; "+ "Hong Kong (.HK) and UK LSE (.L). US uses SEC EDGAR companyfacts; ""A-share and HK use Eastmoney; UK uses Yahoo quoteSummary (annual ""history). Reports come back newest-first as flat per-period rows. Use "'this to read fundamentals before building a valuation or screen. Example: '@@ -768,7 +768,7 @@ class FinancialStatementsTool(BaseTool):market = _classify_market(code)if market is None:return _error(- "code must carry a supported suffix: .SH/.SZ/.BJ, .US, .HK, or .L/.IL"+ "code must carry a supported suffix: .SH/.SZ/.BJ, .US, .HK, or .L")if market == "us":diff --git a/agent/src/tools/stock_profile_tool.py b/agent/src/tools/stock_profile_tool.pyindex 7b94d3f88..33a681dc8 100644--- a/agent/src/tools/stock_profile_tool.py+++ b/agent/src/tools/stock_profile_tool.py@@ -230,7 +230,7 @@ def _market_for(ticker: str) -> str:upper = ticker.strip().upper()if upper.endswith(".HK"):return "hk"- if upper.endswith((".L", ".IL")):+ if upper.endswith(".L"):return "uk"return "us"@@ -256,7 +256,7 @@ class StockProfileTool(BaseTool):"description": ("US, HK, or UK/Irish symbol. US uses a bare or .US suffix ""(AAPL or AAPL.US); HK uses a zero-padded .HK code "- "(00700.HK); UK/Irish uses .L or .IL (VOD.L)."+ "(00700.HK); UK uses the .L suffix (VOD.L)."),},"sections": {diff --git a/agent/src/tools/trade_journal_parsers.py b/agent/src/tools/trade_journal_parsers.pyindex 140bef687..eae0b4875 100644--- a/agent/src/tools/trade_journal_parsers.py+++ b/agent/src/tools/trade_journal_parsers.py@@ -527,8 +527,8 @@ def _infer_market_from_symbol(symbol: str) -> str:s = symbol.upper()if s.endswith(".HK"):return "hk"- if s.endswith(".L") or s.endswith(".IL"):- # LSE/ISE UK/Irish names (#1206); without this they landed in "other"+ if s.endswith(".L"):+ # LSE names (#1206); without this they landed in "other"# and shadow analysis silently degraded to NaN.return "uk"if s.endswith(".SH") or s.endswith(".SZ") or s.endswith(".BJ"):diff --git a/agent/tests/test_financial_statements_tool.py b/agent/tests/test_financial_statements_tool.pyindex f2d8fef18..0308bf910 100644--- a/agent/tests/test_financial_statements_tool.py+++ b/agent/tests/test_financial_statements_tool.py@@ -362,7 +362,7 @@ class TestErrorEnvelope:class TestUKYahooStatements:- """UK (.L/.IL) routes to Yahoo quoteSummary with flattened raw values."""+ """UK (.L) routes to Yahoo quoteSummary with flattened raw values."""_INCOME_PAYLOAD = {"incomeStatementHistory": {@@ -446,9 +446,9 @@ class TestUKYahooStatements:return_value=self._INCOME_PAYLOAD,) as mock_qs:FinancialStatementsTool().execute(- code="DCC.IL", statement="income", period="annual"+ code="BARC.L", statement="income", period="annual")- assert mock_qs.call_args.args == ("DCC.IL", ["incomeStatementHistory"])+ assert mock_qs.call_args.args == ("BARC.L", ["incomeStatementHistory"])def test_uk_indicators_flatten_nested_blocks(self) -> None:payload = {diff --git a/agent/tests/test_stock_profile_tool.py b/agent/tests/test_stock_profile_tool.pyindex f3d478994..7dc1ad794 100644--- a/agent/tests/test_stock_profile_tool.py+++ b/agent/tests/test_stock_profile_tool.py@@ -184,7 +184,7 @@ def test_uk_ticker_market_label() -> None:from src.tools.stock_profile_tool import _market_forassert _market_for("VOD.L") == "uk"- assert _market_for("DCC.IL") == "uk"+ assert _market_for("BARC.L") == "uk"assert _market_for("AAPL.US") == "us"assert _market_for("AAPL") == "us"assert _market_for("00700.HK") == "hk"diff --git a/agent/tests/test_trade_journal.py b/agent/tests/test_trade_journal.pyindex 469e72a4a..91f91ae23 100644--- a/agent/tests/test_trade_journal.py+++ b/agent/tests/test_trade_journal.py@@ -121,7 +121,7 @@ def test_normalize_side_rejects_missing_or_unknown(raw: object) -> None:("000001.SZ", "china_a"),("VOD.L", "uk"),("HSBA.L", "uk"),- ("DCC.IL", "uk"),+ ("BARC.L", "uk"),("vod.l", "uk"),("AAPL", "us"),("BTC-USDT", "crypto"),diff --git a/agent/tests/test_uk_equity_support.py b/agent/tests/test_uk_equity_support.pyindex b0cba784a..124c7d64a 100644--- a/agent/tests/test_uk_equity_support.py+++ b/agent/tests/test_uk_equity_support.py@@ -1,4 +1,4 @@-"""Test UK/Irish equity (LSE .L / ISE .IL) market support end to end.+"""Test UK equity (LSE .L) market support end to end.Regression suite for issue #1205: UK symbols used to fall through thesource/market detection tables to the tushare default and the China@@ -24,7 +24,7 @@ class TestUKSourceDetection:assert detect_source("SHEL.L") == "yahoo"def test_ise_routes_to_yahoo(self) -> None:- assert detect_source("DCC.IL") == "yahoo"+ assert detect_source("BARC.L") == "yahoo"def test_lowercase_suffix_routes_to_yahoo(self) -> None:assert detect_source("vod.l") == "yahoo"@@ -36,14 +36,14 @@ class TestUKMarketClassification:assert _detect_market("HSBA.L") == "uk_equity"def test_ise_classifies_as_uk_equity(self) -> None:- assert _detect_market("DCC.IL") == "uk_equity"+ assert _detect_market("BARC.L") == "uk_equity"def test_lowercase_classifies_as_uk_equity(self) -> None:assert _detect_market("shel.l") == "uk_equity"def test_submarket_detects_uk(self) -> None:assert _detect_submarket(["VOD.L", "SHEL.L"]) == "uk"- assert _detect_submarket(["DCC.IL"]) == "uk"+ assert _detect_submarket(["BARC.L"]) == "uk"def test_submarket_still_detects_other_markets(self) -> None:assert _detect_submarket(["AAPL.US"]) == "us"@@ -57,7 +57,7 @@ class TestUKSettlementCurrency:assert code_currency("SHEL.L") == "GBP"def test_ise_settles_in_gbp(self) -> None:- assert code_currency("DCC.IL") == "GBP"+ assert code_currency("BARC.L") == "GBP"def test_uk_market_cost_is_separate_from_cad(self) -> None:# The composite engine refuses mixed-currency sets; UK must not@@ -95,7 +95,7 @@ class TestUKBacktestRouting:assert engine.market == "uk"def test_ise_engine_is_global_equity(self) -> None:- engine = _create_market_engine("auto", {"initial_cash": 100_000}, ["DCC.IL"])+ engine = _create_market_engine("auto", {"initial_cash": 100_000}, ["BARC.L"])assert isinstance(engine, GlobalEquityEngine)assert engine.market == "uk"@@ -142,7 +142,7 @@ class TestGbpPenceNormalization:def test_pence_symbol_detection(self) -> None:assert is_gbp_pence_symbol("VOD.L")- assert is_gbp_pence_symbol("DCC.IL")+ assert is_gbp_pence_symbol("BARC.L")assert is_gbp_pence_symbol("vod.l")assert not is_gbp_pence_symbol("AAPL.US")assert not is_gbp_pence_symbol("0700.HK")diff --git a/agent/tests/test_yahoo_loader.py b/agent/tests/test_yahoo_loader.pyindex fac2097bf..c3dafb162 100644--- a/agent/tests/test_yahoo_loader.py+++ b/agent/tests/test_yahoo_loader.py@@ -306,7 +306,9 @@ class TestFetch:def test_uk_symbols_are_supported(self):assert _is_supported("VOD.L")- assert _is_supported("DCC.IL")+ assert _is_supported("BARC.L")+ # Irish ISE is out of scope; .IL must not be claimed.+ assert not _is_supported("DCC.IL")assert not _is_supported("601398.SH")good_rows = [_row("2024-01-02", 10, 11, 9, 10.5, 1000)]diff --git a/agent/tests/test_yfinance_uk_scale.py b/agent/tests/test_yfinance_uk_scale.pyindex 05c1590e2..e3fbd67f3 100644--- a/agent/tests/test_yfinance_uk_scale.py+++ b/agent/tests/test_yfinance_uk_scale.py@@ -1,4 +1,4 @@-"""yfinance loader scales GBp-quoted UK (.L/.IL) prices to GBP.+"""yfinance loader scales GBp-quoted UK (.L) prices to GBP.Yahoo-family data serves LSE UK names in pence (VOD.L ~117p); the loadermust normalize ÷100 so ``code_currency``'s GBP matches the values (#1206).@@ -44,18 +44,18 @@ def test_fetch_scales_lse_pence_to_gbp(monkeypatch: pytest.MonkeyPatch) -> None:assert frame["volume"].iloc[0] == 100-def test_fetch_scales_irish_gbp_names(monkeypatch: pytest.MonkeyPatch) -> None:+def test_fetch_scales_other_lse_names(monkeypatch: pytest.MonkeyPatch) -> None:monkeypatch.delenv("VIBE_TRADING_DATA_CACHE", raising=False)def fake_download(tickers, start_date, end_date, interval):- assert tickers == ["DCC.IL"]+ assert tickers == ["BARC.L"]return _download_frame()monkeypatch.setattr(yfl, "_download_history", fake_download)- result = yfl.DataLoader().fetch(["DCC.IL"], "2025-01-01", "2025-01-03")+ result = yfl.DataLoader().fetch(["BARC.L"], "2025-01-01", "2025-01-03")- assert result["DCC.IL"]["close"].iloc[0] == pytest.approx(1.175)+ assert result["BARC.L"]["close"].iloc[0] == pytest.approx(1.175)def test_fetch_leaves_us_prices_untouched(monkeypatch: pytest.MonkeyPatch) -> None: