mirror of
https://github.com/TauricResearch/TradingAgents.git
synced 2026-09-27 15:02:39 +03:00
fix(dataflows): quote the prices the vendor reported in the verification snapshot
- gap filling keeps indicators on a continuous series, but put the previous session's open, high and low under an unsettled bar's date - load_ohlcv takes fill_gaps, and the snapshot reads the frame as reported
This commit is contained in:
@@ -32,7 +32,9 @@ def _verified_rows(symbol: str, curr_date: str) -> pd.DataFrame:
|
||||
look-ahead rows, but we re-apply the cutoff defensively — this is a
|
||||
verification path, so it must not trust its input to be pre-filtered.
|
||||
"""
|
||||
data = load_ohlcv(symbol, curr_date)
|
||||
# As reported: this snapshot is quoted by the agents as exact prices, so a
|
||||
# gap-filled cell would put the previous session's number under this date.
|
||||
data = load_ohlcv(symbol, curr_date, fill_gaps=False)
|
||||
if data is None or data.empty:
|
||||
raise ValueError(f"No OHLCV data available for {symbol}.")
|
||||
|
||||
|
||||
@@ -179,12 +179,16 @@ def _cache_is_fresh(data_file, curr_date_dt, now) -> bool:
|
||||
return curr_date_dt.date() < now.date() or (now - written).total_seconds() <= OHLCV_CACHE_TTL_SECONDS
|
||||
|
||||
|
||||
def load_ohlcv(symbol: str, curr_date: str) -> pd.DataFrame:
|
||||
def load_ohlcv(symbol: str, curr_date: str, fill_gaps: bool = True) -> pd.DataFrame:
|
||||
"""Fetch OHLCV data with caching, filtered to prevent look-ahead bias.
|
||||
|
||||
Downloads 5 years of data up to today and caches per symbol. On
|
||||
subsequent calls the cache is reused. Rows after curr_date are
|
||||
filtered out so backtests never see future prices.
|
||||
|
||||
``fill_gaps`` carries prices forward over gaps so indicators compute on a
|
||||
continuous series. Pass ``False`` to read the values as the vendor reported
|
||||
them, leaving a cell that was never reported empty.
|
||||
"""
|
||||
# Resolve broker/forex symbols (XAUUSD+ -> GC=F) to Yahoo's convention,
|
||||
# then reject values that would escape the cache directory when
|
||||
@@ -262,7 +266,10 @@ def load_ohlcv(symbol: str, curr_date: str) -> pd.DataFrame:
|
||||
data["Date"].iloc[-1].date(), data["Date"].iloc[settled[-1]].date(),
|
||||
)
|
||||
|
||||
data = _fill_price_gaps(data)
|
||||
# Indicators need a continuous series, so gaps are carried forward. A caller
|
||||
# that reports the numbers themselves asks for the frame as it was reported:
|
||||
# a filled cell is the previous session's price under this session's date.
|
||||
data = _fill_price_gaps(data) if fill_gaps else data.dropna(subset=["Close"]).copy()
|
||||
|
||||
# Reject a stale frame (latest row far older than curr_date) rather than
|
||||
# feeding year-old prices into indicators (#1021).
|
||||
|
||||
Reference in New Issue
Block a user