mirror of
https://github.com/TauricResearch/TradingAgents.git
synced 2026-09-19 11:15:24 +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:
@@ -167,3 +167,34 @@ def test_tz_aware_latest_bar_is_kept_at_the_cutoff(monkeypatch, tmp_path):
|
||||
out = _run_load(monkeypatch, tmp_path, frame, "2026-05-08")
|
||||
assert out["Close"].iloc[-1] == 101.5
|
||||
assert out["Date"].iloc[-1] == pd.Timestamp("2026-05-08")
|
||||
|
||||
|
||||
@pytest.mark.unit
|
||||
def test_the_snapshot_does_not_present_a_filled_price_as_reported(monkeypatch, tmp_path):
|
||||
"""Gap filling exists so indicators compute on a continuous series. The
|
||||
verification snapshot is the one place a number must be what the vendor
|
||||
reported, or the module built to stop invented prices supplies them."""
|
||||
from tradingagents.dataflows import market_data_validator as mdv, stockstats_utils as su
|
||||
|
||||
frame = pd.DataFrame({
|
||||
"Date": ["2026-05-06", "2026-05-07", "2026-05-08"],
|
||||
"Open": [100.0, 104.5, ""], # the latest bar has not settled
|
||||
"High": [101.0, 105.5, ""],
|
||||
"Low": [99.0, 103.5, ""],
|
||||
"Close": [100.5, 105.0, 106.0],
|
||||
"Volume": [1000000, 1000000, ""],
|
||||
})
|
||||
today = pd.Timestamp("2026-05-08 12:00")
|
||||
monkeypatch.setattr(su, "get_config", lambda: {"data_cache_dir": str(tmp_path)})
|
||||
monkeypatch.setattr(su.pd.Timestamp, "today", staticmethod(lambda: today))
|
||||
cache = tmp_path / "AAPL-YFin-data.csv"
|
||||
cache.write_text(frame.to_csv(index=False))
|
||||
os.utime(cache, (today.timestamp(), today.timestamp()))
|
||||
monkeypatch.setattr(su.yf, "download", lambda *a, **k: (_ for _ in ()).throw(
|
||||
AssertionError("should read the seeded cache")))
|
||||
|
||||
out = mdv.build_verified_market_snapshot("AAPL", "2026-05-08", 3)
|
||||
|
||||
row = out.split("Latest verified OHLCV row")[1].split("###")[0]
|
||||
assert "104.50" not in row and "105.50" not in row # the previous session's numbers
|
||||
assert "106.00" in row # the close the vendor did report
|
||||
|
||||
Reference in New Issue
Block a user