Data & Machine LearningOctober 2026Status: Complete
Financial Market Data Lakehouse
A Delta Lake Medallion Pipeline Turning Market Data into Leakage-Safe, ML-Ready Datasets
At a glance
- Problem
- Market data is easy to download but hard to trust, reproduce and use for modeling without quietly leaking future information.
- My role
- Designed and built the PySpark pipeline and its validation end to end.
- Key decision
- Treat the data like a controlled system: append-only raw history, quality rules that quarantine instead of drop, idempotent upserts and time-travel versions, then leakage-safe splits for modeling.
- Result
- Ten years of daily data for 20 equities flow into a 27-feature Gold layer and two validated ML datasets, with honest baseline results.
- Proof
- 50,280 validated rows6 quality rules with quarantine15 offline unit tests
- Built with
- Processing
- PySpark
- Delta Lake
- Data
- yfinance
- pandas
- PyArrow
- NumPy
- Modeling
- Spark MLlib
- Quality
- pytest
- Notebook
- Jupyter
- Matplotlib
In Practice
Silver Market Data
AAPL in the Silver layer: 2,514 deduplicated, quality-checked trading days of adjusted closes and volume from 2016 to 2025, stored as a Delta table.
Trend Features
AAPL in 2025 with its 20- and 50-day moving averages, each computed only once its window is full. Gold stores them as scale-free ratios to the price.
Context
I wanted to practise data engineering the way a regulated institution has to: market data is easy to retrieve, but analysis is only as good as its lineage, quality controls and reproducibility. The project builds those controls into a pipeline from the start, then uses the result for modeling.
How can raw market data become a trustworthy, reproducible foundation for modeling, without leaking the future into the past?
Turning downloaded prices into model-ready data means handling duplicates and corrections, enforcing quality rules without silently losing records, keeping history replayable, and making sure no feature or label uses information that wasn't available at the time. Most quick pipelines skip at least one of these, and the gaps show up later as results nobody can reproduce or trust.
Approach
Market data moves through Delta Lake Bronze, Silver and Gold layers, each with its own write pattern and guarantee. Bronze appends raw batches with ingestion lineage, so any batch can be replayed. Silver deduplicates to the latest ingestion, applies six quality rules, quarantines failures with the rules they broke and merges by ticker and date, so replays never overwrite newer data. Gold recomputes 27 features from dividend-adjusted prices using only information available at each day's close, and keeps prior versions through time travel.
Data sources
Yahoo Finance Market Data
Ten years (2016–2025) of daily OHLCV and adjusted prices for 20 US equities across nine GICS sectors, collected with the yfinance library.
Solution
Ingestion and Bronze
Ingestion. Download ten years of daily prices for 20 sector-diverse US equities with yfinance, stamped with ingestion ID and timestamp.
Immutable Bronze. Append raw batches to a Bronze Delta table as immutable, replayable history.
Silver quality and conformance
Idempotent upserts. Deduplicate on ticker and date, keeping the latest ingestion; MERGE into Silver as idempotent upserts.
Quality rules with quarantine. Enforce six data-quality rules (required fields, positive prices, non-negative volume, high/low consistency) and quarantine failures with a failed-rules list instead of dropping them.
Sector enrichment. Enrich records with a sector reference table.
Gold features and datasets
27 scale-free features. Compute 27 scale-free features (returns, momentum, trend, risk, volume, market and sector context, calendar), with rolling statistics null until their window is full.
Two modeling datasets. Build a time-series forecasting panel and a classification dataset with direction and volatility-scaled trend labels.
Purged chronological splits. Split chronologically (train to 2022, validation 2023, test 2024–2025) and purge rows whose label window crosses a split boundary.
Dataset validation. Validate datasets for duplicate keys, null features, empty splits and overlapping split dates.
Engineering
CLI package. Modular package with a CLI (full run, offline rebuild from Bronze, ticker subsets).
Offline tests. 15 offline unit tests on synthetic data, and a notebook that runs the pipeline and inspects each layer.
Architecture
Each layer has its own write pattern and guarantee. Bronze is append-only: every ingested batch is kept with its lineage and can be replayed. Silver is a MERGE on ticker and date: deduplicated, typed, sector-enriched and quality-checked, with failing records sent to a quarantine table, and replaying older batches never overwrites newer data.
Gold is recomputed in full from Silver, with Delta time travel keeping prior versions. From the 27-feature Gold table the pipeline builds two datasets: a time-series forecasting panel and a classification dataset with purged chronological splits, plus baseline model metrics.
Components
- Ingestion with lineage
- Bronze append-only table
- Silver MERGE table
- Quarantine table
- Sector reference table
- Gold feature table
- Time-series panel
- Classification dataset
- Baseline metrics
Outcome
The full run produces 50,280 validated Silver rows, a 49,080-row time-series panel and a classification dataset split 33,640 / 4,600 / 9,640 across train, validation and test. No quality rule fired on the Yahoo Finance data; the quarantine path is covered by unit tests. Baseline models (logistic regression and random forest) show the dataset working end to end: five-day direction is essentially unpredictable, with models only matching the majority class, while a volatility-scaled trend label beats its baseline by roughly 1–3 points on both held-out periods.
Scope and limits
A local, single-machine pipeline over one public data source. Gold is recomputed in full each run, and the baselines are sanity checks, not a trading model.
Lessons Learned
A reliable analytical workflow requires more than data ingestion; schema, quality, storage and transformation decisions are equally important.
A well-designed Gold layer can provide a reusable analytical foundation rather than coupling feature engineering to a single model or use case.
Separating pipeline implementation from notebook exploration improves reproducibility, maintainability and clarity.
Quarantining bad records, rather than dropping them, keeps data quality visible and auditable.
The most important modeling decisions here were about time: full windows only, features known at the close, and purged split boundaries.
What's next
- Walk-forward cross-validation.
- Sector-relative labels.
- Macro features such as interest rates and VIX.
- Classical forecasting baselines (ARIMA, exponential smoothing) on the time-series panel.
- Incremental Gold builds instead of a full recompute.


