Financial Data Engineering: Sources, Cleaning, and Storage
Module: Fintech AI | Difficulty: Advanced
Data Types
| Type | Source | Frequency |
|---|---|---|
| Tick | Exchange | Real-time |
| OHLCV | Vendor | Daily |
| Fundamental | SEC filings | Quarterly |
| Alternative | Web, satellite | Various |
Data Quality
Point-in-Time
import pandas as pd
import numpy as np
class FinancialDataPipeline:
def __init__(self):
self.raw_data = None; self.clean_data = None
def clean(self, df):
# Remove duplicates
df = df.drop_duplicates()
# Handle missing values
df = df.ffill()
# Remove outliers
for col in df.select_dtypes(include=[np.number]).columns:
q1 = df[col].quantile(0.01)
q99 = df[col].quantile(0.99)
df = df[(df[col] >= q1) & (df[col] <= q99)]
return df
def align_data(self, data_dict, dates):
# Align all data to common dates
aligned = {}
for name, data in data_dict.items():
aligned[name] = data.reindex(dates).ffill()
return aligned
Research Insight: Data quality is the most important factor in quantitative finance. The phrase "garbage in, garbage out" is especially true for financial data. Common issues: survivorship bias, look-ahead bias, and data snooping. Rigorous data engineering is essential for reproducible research.