Discard vendor outlier bars in intraday data - #17
Merged
Conversation
EODHD sporadically returns junk prints in the 1-minute intraday endpoint, e.g. an isolated 2.4 bar for USDKRW on 2024-01-02, a day the pair traded around 1300. The downloader wrote them verbatim, so a single bad bar ended up in the generated minute quote file. Bars further than 25% from the median close of their own day are now discarded. Judging each day against itself keeps a genuine trend across the 120-day download window from tripping the filter; days too sparse to give a meaningful median fall back to the median of the whole window, which is what catches a junk print landing alone on a day. The threshold clears every real move in the USDKRW minute history: over 5323 days the widest deviation of a bar from its daily median is 10.5%, and of a sparse day from its window median 3.1%, against 99.8% for the junk bar. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
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.
Problem
EODHD sporadically returns junk prints in the 1-minute intraday endpoint. The raw response for USDKRW on 2024-01-02 opens with:
{"timestamp":1704155040,"datetime":"2024-01-02 00:24:00","open":2.4,"high":2.4,"low":2.4,"close":2.4,"volume":1} {"timestamp":1704161460,"datetime":"2024-01-02 02:11:00","open":1299.84,"high":1300.05,...,"volume":28}An isolated bar with all four OHLC fields at 2.4, 1h47m before the first genuine bar of the session, on a day the pair traded around 1300. It is the only one of the day's 1182 bars deviating more than 10% from the median. The downloader only filtered nulls, so the bar was written verbatim into
forex/oanda/minute/usdkrw/20240102_quote.zip.The vendor volume is not a usable signal: that day has 30 volume-1 bars and the other 29 are legitimate quiet minutes.
Fix
Bars further than 25% from the median close of their own day are discarded, and each drop is logged.
Threshold
Measured over the full USDKRW minute history, 5323 daily files / 4.8M bars:
25% clears every real move with no false positives across the whole history.
Verification
Re-running the downloader for 20240102:
The regenerated file is byte-identical to the previous output minus that row. 9 new unit tests cover the real 2024-01-02 case, zero and negative prices, the sparse-day fallback, chronological ordering, empty input, and two no-false-positive guards (the widest genuine intraday move, and a 120-day window drifting 1000 to 1595).
Six other days (20231124, 20231201, 20231214, 20231229, 20240312, 20240607) carry 5-10% spikes that look like the same family of vendor glitch but sit below this threshold. Catching them safely needs a different rule (deviation from neighboring bars rather than the daily median), so they are left alone here.
🤖 Generated with Claude Code