"Vibe-Trading: Your Personal Trading Agent"
Python ai-agentalgorithmic-tradingbacktestingfintechllmmcpmulti-agentpythonquantitative-financetrading
fix(financial-statements): serve real quarterly history for UK names
cgycoreyf72d951dab40
diff --git a/agent/src/tools/financial_statements_tool.py b/agent/src/tools/financial_statements_tool.pyindex 63186b75d..f32491dff 100644--- a/agent/src/tools/financial_statements_tool.py+++ b/agent/src/tools/financial_statements_tool.py@@ -290,13 +290,17 @@ def _fetch_eastmoney_statement(return {"periods": _cap_periods(periods)}-# Yahoo quoteSummary module + result-key per statement. UK (.L/.IL) names have-# no Eastmoney or SEC filing pipeline; Yahoo's crumb-gated quoteSummary serves-# these histories for LSE/ISE tickers (UK parity, #1206).-_YAHOO_STATEMENT_MODULES: dict[str, tuple[str, str]] = {- "balance": ("balanceSheetHistory", "balanceSheetStatements"),- "income": ("incomeStatementHistory", "incomeStatementHistory"),- "cashflow": ("cashflowStatementHistory", "cashflowStatements"),+# Yahoo quoteSummary module + result-key per (statement, cadence). UK+# (.L/.IL) 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]] = {+ ("balance", "annual"): ("balanceSheetHistory", "balanceSheetStatements"),+ ("balance", "quarter"): ("balanceSheetHistoryQuarterly", "balanceSheetStatements"),+ ("income", "annual"): ("incomeStatementHistory", "incomeStatementHistory"),+ ("income", "quarter"): ("incomeStatementHistoryQuarterly", "incomeStatementHistory"),+ ("cashflow", "annual"): ("cashflowStatementHistory", "cashflowStatements"),+ ("cashflow", "quarter"): ("cashflowStatementHistoryQuarterly", "cashflowStatements"),}_YAHOO_INDICATOR_MODULES = ["financialData", "defaultKeyStatistics"]# {raw, fmt, longFmt} value shapes; keep the numeric raw only.@@ -329,19 +333,17 @@ def _fetch_yahoo_statement(Args:code: UK symbol (e.g. ``"VOD.L"`` or ``"DCC.IL"``).statement: One of :data:`_VALID_STATEMENTS`.- period: ``"annual"`` or ``"quarter"`` (Yahoo's history is annual-only;- a quarter request returns the annual periods, matching Eastmoney's- behavior of degrading gracefully when only one cadence exists).+ period: ``"annual"`` or ``"quarter"`` — selects the corresponding+ history module; both exist for LSE/ISE tickers.Returns:``{"periods": [...]}`` on success or ``{"error": ...}`` on failure;never raises."""- del period # Yahoo statement histories are annual; quarterly is a no-op filterif statement == "indicators":modules = _YAHOO_INDICATOR_MODULESelse:- module, key = _YAHOO_STATEMENT_MODULES[statement]+ module, key = _YAHOO_STATEMENT_MODULES[(statement, period)]modules = [module]try:result = yahoo_client.get_quote_summary(code, modules)diff --git a/agent/tests/test_financial_statements_tool.py b/agent/tests/test_financial_statements_tool.pyindex 5a71e561a..f2d8fef18 100644--- a/agent/tests/test_financial_statements_tool.py+++ b/agent/tests/test_financial_statements_tool.py@@ -385,7 +385,7 @@ class TestUKYahooStatements:}}- def test_uk_income_uses_yahoo_and_flattens_raw_values(self) -> None:+ def test_uk_income_annual_uses_annual_module(self) -> None:with patch("src.tools.financial_statements_tool.yahoo_client.get_quote_summary",return_value=self._INCOME_PAYLOAD,@@ -406,6 +406,40 @@ class TestUKYahooStatements:# Newest first.assert periods[0]["endDate"] > periods[1]["endDate"]+ def test_uk_income_quarter_uses_quarterly_module(self) -> None:+ quarterly = {+ "incomeStatementHistoryQuarterly": {+ "maxAge": 1,+ "incomeStatementHistory": [+ {+ "maxAge": 1,+ "endDate": {"raw": 1743379200, "fmt": "2025-03-31"},+ "totalRevenue": {"raw": 9361000000, "fmt": "9.36B"},+ },+ ],+ }+ }+ with patch(+ "src.tools.financial_statements_tool.yahoo_client.get_quote_summary",+ return_value=quarterly,+ ) as mock_qs:+ payload = json.loads(+ FinancialStatementsTool().execute(+ code="VOD.L", statement="income", period="quarter"+ )+ )++ assert payload["ok"] is True+ assert payload["period"] == "quarter"+ assert mock_qs.call_args.args == (+ "VOD.L",+ ["incomeStatementHistoryQuarterly"],+ )+ period_record = payload["data"]["VOD.L"]["periods"][0]+ # Quarterly endDate is a {raw, fmt} dict on Yahoo; flattened to int.+ assert period_record["endDate"] == 1743379200+ assert period_record["totalRevenue"] == 9361000000+def test_uk_il_suffix_routes_to_yahoo(self) -> None:with patch("src.tools.financial_statements_tool.yahoo_client.get_quote_summary",