Preserve intraday closing-auction bar dropped by Yahoo schedule end#2806
Open
dokson wants to merge 1 commit into
Open
Preserve intraday closing-auction bar dropped by Yahoo schedule end#2806dokson wants to merge 1 commit into
dokson wants to merge 1 commit into
Conversation
Yahoo's `tradingPeriods.end` undershoots the real session close on several exchanges (SAU, SAO, KSC, BUD, NZE, SES, JNB, DFM) and on US half-days, omitting the closing auction. Yahoo still returns a bar at index == end holding the auction price, but `fix_Yahoo_returning_prepost_unrequested` discarded it via `index >= end`, leaving users without the official close. - Switch the boundary in `fix_Yahoo_returning_prepost_unrequested` from `>=` to `>` so the bar at the schedule end survives. Pre-market and post-close bars are still dropped — they're handled by the second half of the filter or sit clearly past `end`. - Add `test_fix_prepost_keeps_closing_auction_bar` as a synthetic, no-network regression test pinning the boundary semantics on both sides. - Add `test_intraday_closing_auction_bar_saudi` as a live check on 2222.SR. - Relax the assertion in `test_prune_post_intraday_us` from `<` to `<=`: the half-day closing-auction bar at the early-close timestamp is now preserved too, which is the intended outcome. Closes ranaroussi#1585
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #1585.
Yahoo's
tradingPeriods.endundershoots the real session close on several exchanges by omitting the closing auction. Yahoo still returns a bar atindex == endholding the auction price, butfix_Yahoo_returning_prepost_unrequestedwas discarding it viaindex >= end, leaving users without the official close.The reporter's case was Saudi (2222.SR), but a sweep of the major venues found the same pattern on at least 8 exchanges plus US half-days:
In every case Yahoo returns a bar at exactly
endwith a validCloseandVolume == 0, i.e. the closing-auction print. TheVolume == 0part is acknowledged as a Yahoo data limitation in the original issue thread (auction volume not exposed intraday) and is out of scope for this PR.Changes
yfinance/utils.py: switch the drop boundary infix_Yahoo_returning_prepost_unrequestedfromquotes.index >= quotes['end']toquotes.index > quotes['end']. Single-character semantic change. Pre-market bars are still pruned by the other half of the filter; bars strictly pastend(post-close) still get dropped.tests/test_prices.py:test_fix_prepost_keeps_closing_auction_bar— synthetic, no-network regression test exercising both sides of the boundary (pre-market and post-close still drop, bar at == end survives).test_intraday_closing_auction_bar_saudi— live integration check on 2222.SR.test_prune_post_intraday_usassertion relaxed from<to<=: the half-day closing-auction bar at the early-close timestamp is now preserved, which is the intended behavior.Behavior before
Behavior after
Test plan
python -m unittest tests.test_prices.TestPriceHistory.test_fix_prepost_keeps_closing_auction_bar tests.test_prices.TestPriceHistory.test_intraday_closing_auction_bar_saudi tests.test_prices.TestPriceHistory.test_prune_post_intraday_us tests.test_prices.TestPriceHistory.test_prune_post_intraday_asx -v— all passdev(verified by reverting just the>=/>change), pass with the fix