fix(data): include the requested end date in yfinance fetches
yfinance treats end as exclusive, so get_YFin_data_online dropped the requested end_date row and load_ohlcv dropped the current day. Request one day past the end so the range is inclusive (look-ahead is still prevented by the curr_date filter; the header still shows the requested range). Also correct the load_ohlcv docstring to the 5-year window it actually downloads.
This commit is contained in:
3 files changed
+73
-6
No files matched your search
@@ -14,14 +14,17 @@ def get_YFin_data_online(
|
||||
):
|
||||
|
||||
datetime.strptime(start_date, "%Y-%m-%d")
|
||||
datetime.strptime(end_date, "%Y-%m-%d")
|
||||
end_dt = datetime.strptime(end_date, "%Y-%m-%d")
|
||||
|
||||
# Resolve broker/forex symbols to Yahoo's convention (XAUUSD+ -> GC=F).
|
||||
canonical = normalize_symbol(symbol)
|
||||
ticker = yf.Ticker(canonical)
|
||||
|
||||
# Fetch historical data for the specified date range
|
||||
data = yf_retry(lambda: ticker.history(start=start_date, end=end_date))
|
||||
# yfinance treats ``end`` as EXCLUSIVE, so it would drop the requested
|
||||
# end_date row (and the current day when end_date is today). Request one day
|
||||
# past end_date so the requested range is actually inclusive (#986/#987).
|
||||
end_inclusive = (end_dt + relativedelta(days=1)).strftime("%Y-%m-%d")
|
||||
data = yf_retry(lambda: ticker.history(start=start_date, end=end_inclusive))
|
||||
|
||||
# Empty result means the symbol is unknown/delisted. Raise a typed error
|
||||
# instead of returning prose: the routing layer turns it into a single
|
||||
|
||||
Reference in new issue
Block a user