FREE FINANCIAL EDUCATION
Data cleaning
Detect duplicates and impossible bars without silently rewriting valid events.
What you will learn
Prerequisites: Time series sorting, OHLCV fields and corporate-action adjustments.
- Detect duplicates and impossible bars without silently rewriting valid events.
- Separate missing observations from genuine zero activity.
- Preserve an audit trail for corrections and exclusions.
Mechanism and decision rules
Cleaning should make data defects visible and reproducible. Begin with schema checks, timestamp ordering, duplicate identifiers and instrument consistency. For ordinary OHLC bars, high should be at least the open, close and low, while low should be no greater than the other prices. Negative volume is invalid for ordinary executed-volume data, but a zero-volume interval may be legitimate depending on the vendor’s construction.
Do not automatically replace every outlier with a nearby average. A large jump may be real news, a split, a contract change or a bad print; those require different treatments. Keep raw data immutable and record each transformation, reason and affected timestamp. Missing bars should remain distinguishable from observed bars, especially when indicators or execution rules depend on elapsed time and liquidity.
Worked example · synthetic data
A synthetic feed contains two identical records with the same exchange event ID and one bar with O = 100, H = 99, L = 98, C = 100.5. The duplicate event can be deduplicated by its stable ID under the documented policy. The bar fails OHLC consistency because both open and close exceed the high; it should be quarantined for source verification rather than “fixed” by guessing.
A missing 10:05 bar is different from a reported 10:05 bar with zero volume. Forward-filling its close may be acceptable for a marked valuation convention, but inventing volume or treating the fill as an executable trade is not.
Failure modes and limits
Some data fields represent corrections or cancellations and can use vendor-specific signs; read the schema before applying generic rules. Adjusted prices paired with unadjusted volumes can distort indicators. Removing extreme losses because they look unusual can materially bias a backtest. Every exclusion needs an information-independent rationale.
Practice case
A bar has O = 50, H = 53, L = 49, C = 52 and volume = 0. Another timestamp has no record. Can these be treated as equivalent? What metadata or checks are needed?
Reveal the worked answer
They are not automatically equivalent. The zero-volume bar may be a vendor-generated carry-forward or an observed no-trade interval; the missing record may be an outage. Check the provider’s bar policy and session calendar, retain a missing-data flag, and prohibit fabricated fills on either interval without an explicit execution model.
Check your understanding
Sources and next steps
The lesson, calculations and synthetic cases are original educational material. References explain underlying contract or chart conventions; none validates the profitability of a trading rule. Actual contract specifications, settlement obligations and charges must be checked before trading.
Explore OHLCV data in the chart lab · Explore volume-at-price and TPO data · Practice library
