Skip to content

"Vibe-Trading: Your Personal Trading Agent"

Merge PR #1320: serve adjusted prices on the FMP and Tiingo paths (#1296)

Haozhe Wub2b0cb1a6339
diff --cc agent/backtest/loaders/fmp_loader.py
index e6f607a10,a66b42b0c..0adeaf6c4
--- a/agent/backtest/loaders/fmp_loader.py
+++ b/agent/backtest/loaders/fmp_loader.py
@@@ -10,9 -10,9 +10,10 @@@ API format (public, documented)
?symbol=SYMBOL&from=YYYY-MM-DD&to=YYYY-MM-DD&apikey=KEY
The JSON body is a top-level array ``[{date, open, high, low, close,
- volume}, ...]`` in ascending date order (legacy ``{"symbol": "AAPL",
- "historical": [...]}`` shape is still accepted for compatibility); an unknown
- symbol or empty window yields an empty array.
-adjClose, volume}, ...]`` in descending date order (legacy
-``{"symbol": "AAPL", "historical": [...]}`` shape is still accepted for
-compatibility); an unknown symbol or empty window yields an empty array.
++adjClose, volume}, ...]`` (legacy ``{"symbol": "AAPL", "historical": [...]}``
++shape is still accepted for compatibility); an unknown symbol or empty window
++yields an empty array. The parser sorts by date, so the order the endpoint
++happens to return is not relied on.
Auth: set ``FMP_API_KEY`` in the environment. Covers US equities only.
"""
@@@ -183,11 -191,15 +192,19 @@@ class DataLoader
def _parse_historical(payload: Any) -> Optional[pd.DataFrame]:
"""Convert an FMP historical-price body into an ascending OHLCV frame.
- FMP's historical endpoint returns dividend- and split-adjusted prices via
- ``adjClose`` (qfq caliber, matching eastmoney/tencent/yahoo/yfinance).
- Scale OHLC by ``adjClose/close`` when present so backtests see total-return
- prices rather than raw gaps.
+ Stable API returns a top-level array; legacy ``{"historical": [...]}``
+ shape is accepted for compatibility.
+
++ The endpoint carries dividend- and split-adjusted closes in ``adjClose``.
++ OHLC is scaled by ``adjClose/close`` when present so backtests see
++ total-return prices rather than raw gaps — the same split_dividend caliber
++ eastmoney/tencent/yahoo/yfinance serve, and what this source is registered
++ as in ``PRICE_CALIBER_BY_SOURCE``. Volume is never scaled.
+
Args:
payload: Decoded JSON body from the historical-price endpoint.
+ Accepts both the legacy ``{"historical": [...]}`` dict and the
+ Stable top-level ``[...]`` array.
Returns:
DataFrame indexed by ``trade_date`` with float ``open/high/low/close/