Data Cleaning
Data cleaning is the disciplined pipeline that turns a raw market feed into a series fit to backtest on — correcting bad ticks, handling missing values, applying corporate-action adjustments and aligning timestamps in a deliberate order — and its reliability rests on doing those steps reproducibly and without introducing look-ahead.
Quick Answer
Data cleaning turns a raw feed into a series fit to backtest on, and works best as a fixed, coded pipeline. Order matters: normalise timestamps, detect outliers on raw prices, handle missing values, then apply corporate-action adjustments. No step may use information a live system lacked, and every correction is logged so figures trace back to a raw print.
Definition: Data Cleaning
Data Cleaning is the reproducible pipeline that turns a raw market feed into a series fit to backtest on, correcting bad ticks, gaps, corporate actions and timestamps in a deliberate, causal order.
Key takeaways: Data Cleaning
- Data cleaning is a fixed, reproducible pipeline, not a one-off manual scrub
- Order matters: normalise timestamps, filter outliers on raw data, handle gaps, then adjust and align
- No step may use future information; keep the pipeline causal or point-in-time
- Store raw and cleaned data with full provenance so any result is traceable and reversible
- Clean conservatively — preserve real risk events; over-cleaning is as harmful as under-cleaning
Data Cleaning at a glance
| Nature | A reproducible coded pipeline, not a one-off scrub |
|---|---|
| Defensible order | Timestamps → outliers (raw) → missing → adjust → align |
| Cardinal rule | No step may use future information (causal only) |
| Provenance | Version source, code and params; log every correction |
| Storage | Keep both the raw and the cleaned series |
| Over-cleaning | Smoothing real gaps makes the test dishonest |
Data Cleaning in simple words
Data cleaning is everything you do to raw market data before you trust a backtest run on it: removing erroneous prices, patching gaps sensibly, adjusting for splits and dividends, and fixing timestamps. It is best thought of as a pipeline — a fixed sequence of steps applied the same way every time. Getting the order right matters, because cleaning one problem before another can either fix the data or quietly corrupt it further.
What Data Cleaning is for
A data-cleaning pipeline exists because every other data-quality problem — bad ticks, missing values, corporate actions, timestamps — has to be resolved before signals are computed, and doing it ad hoc produces backtests nobody can reproduce or trust.
Data Cleaning — professional explanation
Cleaning is a pipeline, not a one-off
Raw data carries several distinct faults at once, and each has its own remedy, so cleaning is a sequence of well-defined stages rather than a single scrub. Treating it as a pipeline — ingest, validate, correct, adjust, align, store — makes the process repeatable and auditable, so the same raw input always yields the same clean output. This matters because a backtest is only as trustworthy as the data beneath it, and an undocumented, hand-edited dataset cannot be reproduced or debugged. The pipeline should be code, versioned and rerunnable, not a series of manual spreadsheet fixes.
Order of operations
The sequence of cleaning steps is not arbitrary; doing them in the wrong order corrupts the result. Outlier detection should generally run on raw prices before corporate-action adjustment, because adjustment rescales the series and can turn a genuine split into an apparent outlier or mask a real bad tick. Timestamp normalisation should precede any cross-series alignment, so events are ordered correctly before they are joined. Missing-value handling interacts with both: you must know whether a gap is a halt, a holiday or a fault before deciding to forward-fill, mark untradeable or leave it. A defensible order is: normalise timestamps, detect and correct outliers on raw data, classify and handle missing values, apply corporate-action adjustments, then align and resample.
Cleaning must not introduce look-ahead
The cardinal rule is that no cleaning step may use information from after the point being cleaned in a way a live system could not. Back-filling a gap, interpolating across it, standardising with full-sample statistics, or applying back-adjustment factors that depend on future actions all inject future knowledge. A pipeline built for backtesting must either operate point-in-time — cleaning each date using only data available by then — or be restricted to transformations that are provably causal. This is the difference between a dataset that is merely tidy and one that is honestly usable for simulation.
Reproducibility and provenance
A clean dataset is only valuable if you can say exactly how it was produced. That means recording the raw source and its version, the cleaning code and its version, every parameter used, and a log of every correction applied, so any figure in a backtest can be traced back to a raw print. Storing both the raw and the cleaned series lets you re-derive alternatives, reverse a decision, or audit a suspicious result. Without this provenance, two researchers running the same strategy on nominally the same data can get different numbers and never discover why, which quietly undermines every conclusion drawn from the backtest.
Cleaning as a boundary, not a cure
Cleaning improves data but cannot manufacture information that was never captured, and over-cleaning is its own hazard. Smoothing away real gaps, deleting inconvenient outliers, or filling untradeable halts makes the series prettier while making the backtest less honest. The goal is fidelity to the tradeable market, not visual smoothness, so a good pipeline is conservative: it corrects clear errors, flags the ambiguous cases for review, and preserves genuine risk events intact. The output should be documented with its known limitations, because a backtest inherits every assumption baked into the cleaning, and pretending the data is perfect is itself a modelling error.
How Data Cleaning looks visually
Worked example: Data Cleaning
Illustrative example (Indian market)
You assemble three years of NSE data for a multi-stock backtest on capital of Rs 5,00,000, and you clean it as a pipeline. First you normalise all timestamps to IST and confirm each bar lands in the 9:15 to 15:30 session. Next you run outlier detection on the raw prices, flagging a one-tick spike to 49,150 on a Bank Nifty series and a stale zero on a mid-cap, correcting both with logged reasons. Then you classify gaps, marking three circuit-locked days as untradeable rather than filling them. Only then do you apply split and bonus factors from a dated corporate-action master. Had you adjusted for the split first, the pre-split price of Rs 2,000 rescaled to Rs 1,000 might have escaped your outlier filter or masked the real spike, and your bad-tick detection would have run on a distorted series. The order preserved both corrections and made the whole run reproducible from the raw files.
For an Indian equity universe the pipeline must reconcile NSE trading holidays, apply frequent bonus and split adjustments from a corporate-action master, mark small and mid-cap circuit days as untradeable, and normalise IST timestamps, all before any signal runs. Skipping any stage — for example adjusting prices before filtering bad ticks — produces a dataset that looks clean but silently corrupts the backtest.
Ad hoc cleaning vs Pipeline cleaning
| Aspect | Ad hoc / manual | Pipeline |
|---|---|---|
| Reproducible | No | Yes, same input to same output |
| Order of steps | Inconsistent | Fixed and justified |
| Look-ahead control | Easily violated | Enforced by design |
| Auditability | Corrections untracked | Every change logged |
| Debugging a result | Hard or impossible | Traceable to raw source |
Limitations of Data Cleaning
- Cleaning cannot recover information that the raw feed never captured
- Over-cleaning smooths away genuine gaps and outliers that are real risk
- The correct order of operations depends on the data and must be reasoned, not assumed
- A point-in-time pipeline is more expensive than a single precomputed clean series
- Every cleaning choice is an assumption the backtest silently inherits
How professionals treat Data Cleaning
Institutional data engineering treats cleaning as versioned, testable code with a fixed and justified order of operations, run identically every time so the clean output is fully reproducible from the raw source. They enforce causality in every step to prevent look-ahead, store raw alongside cleaned data with full provenance, and log every correction for audit. Crucially they treat cleaning conservatively — correcting clear errors, flagging ambiguous ones, and preserving genuine risk events — and they document the residual limitations so downstream backtests know exactly what assumptions they inherit.
Common misconceptions about Data Cleaning
Misconception: Data cleaning can fix any data problem.
Reality: Cleaning corrects errors and handles known issues, but it cannot recover information the raw feed never captured. Over-cleaning is also harmful, because smoothing away real gaps and outliers removes genuine risk the strategy must face.
Misconception: Cleaner data is always better.
Reality: If you clean too hard you erase real events like news gaps, which are exactly the risks your strategy has to survive. The aim is honest data, not smooth-looking data.
Common mistakes with Data Cleaning
- Applying corporate-action adjustment before outlier detection, distorting the bad-tick filter
- Cleaning data by hand in a spreadsheet so the process cannot be reproduced or audited
- Using back-fill, interpolation or full-sample statistics in a step, injecting look-ahead
- Discarding the raw data after cleaning, leaving no way to reverse or re-derive decisions
- Over-cleaning until genuine news gaps and circuit moves vanish from the series
- Failing to log corrections, so a suspicious backtest result cannot be traced to its cause
Data Cleaning: frequently asked questions
Why should cleaning be a pipeline rather than manual fixes?
Because a pipeline is repeatable and auditable: the same raw input always yields the same clean output. Manual, hand-edited fixes cannot be reproduced or debugged, so a backtest built on them cannot be trusted or replicated by anyone else.
Does the order of cleaning steps matter?
Very much. Outlier detection should run on raw prices before corporate-action adjustment, and timestamps should be normalised before any cross-series alignment. Doing steps in the wrong order can mask real errors or turn a split into an apparent outlier.
What is a good order of operations for cleaning?
A defensible sequence is: normalise timestamps, detect and correct outliers on raw data, classify and handle missing values, apply corporate-action adjustments, then align and resample. The exact order should be reasoned for the specific data, not copied blindly.
How can data cleaning introduce look-ahead bias?
By using information from after the point being cleaned — back-filling a gap, interpolating across it, standardising with full-sample statistics, or applying back-adjustment factors that depend on future actions. A backtesting pipeline must keep every step causal or point-in-time.
Why store both raw and cleaned data?
So you can re-derive alternatives, reverse a decision and audit a suspicious result. Keeping the raw source with full provenance means any figure in a backtest can be traced back to a real print, which is essential for debugging and trust.
Do professional teams clean data differently from retail?
Mainly in discipline. Professionals treat cleaning as versioned code with fixed order, enforced causality, full provenance and logged corrections, and they clean conservatively. The individual fixes are similar, but the reproducibility and auditability are what separate the two.
Voice search: how people ask about Data Cleaning
Natural-language questions people ask about Data Cleaning.
What is data cleaning?
It is everything you do to raw market data before trusting a backtest on it — removing bad prices, patching gaps, adjusting for splits and dividends, and fixing timestamps, all in a set order.
Why does the order of cleaning steps matter?
Because fixing one thing before another can either repair the data or wreck it. For example, you should filter out bad prices before adjusting for splits, or the adjustment can hide the errors.
Can cleaning data accidentally cheat?
Yes. Some common fixes, like filling a gap using a later price or scaling with the whole history, sneak future information into the past. A good pipeline only uses data that was available at the time.
Sources & references
- Chan, E. P. (2013). Algorithmic Trading: Winning Strategies and Their Rationale. John Wiley & Sons (data preparation and pitfalls).
- Mechanics — cleaning order and causal (point-in-time) transforms here are computed conventions (EV-1), not external facts.
Published 11 July 2026. Educational content only — not investment advice. Markets and rules change; verify current conventions with SEBI, NSE/BSE and your broker.