Equity Co-Movement & Portfolio Diversification via Itemset Mining
Applying FP-Growth frequent itemset mining and association rules to Brazilian stock exchange (B3) historical data to detect directional co-movements beyond pairwise linear correlation.
- Role
- Independent Data Science Project
- Domain
- Financial Markets · Unsupervised Learning
- Year
- 2023
01. Context & Problem
Portfolio diversification relies on combining assets that do not move in lockstep during market regimes. Standard Pearson correlation matrices only capture pairwise linear relationships and can miss multi-asset directional co-occurrences.
- Evaluate whether equities traded on Brazil’s B3 exchange exhibit recurring multi-stock directional co-movements (e.g., joint up/down trading days).
- Reframe daily market returns into a transactional representation suitable for frequent pattern mining without combinatorial explosion.
02. System Architecture & Approach
Transformed daily B3 historical equity quotes into directional transaction baskets (each trading day as a basket of stocks moving up/down above threshold) and mined frequent co-movement sets using FP-Growth and association rule metrics (support, confidence, lift).
01
B3 Historical Ingestion & Cleaning
Parsed official B3 COTAHIST fixed-width historical files, filtered liquid spot-market tickers, and aligned trading calendars.
02
Directional Basket Encoding
Converted continuous daily return series into binary event matrices representing directional moves per trading session.
03
FP-Growth Frequent Itemset Mining
Used `mlxtend` FP-Growth to extract multi-asset co-movement sets efficiently compared to candidate-heavy Apriori scans.
04
Lift & Independence Diagnostics
Ranked association rules by Lift (> 1 indicating positive dependence) to separate genuine sector/factor coupling from broad market drift.
03. Engineering Decisions & Trade-offs
FP-Growth over Apriori
FP-Growth compresses transactions into a prefix tree and avoids repeated full-dataset candidate scans across hundreds of equity tickers.
Lift as Primary Filter over Raw Confidence
In bull or bear markets, raw confidence inflates trivially for frequently rising stocks; Lift normalizes against baseline marginal probability.
04. Outcomes & Key Takeaways
- Demonstrated a creative, non-parametric alternative to correlation matrices for screening hidden portfolio concentration risks.
- Published as a clean, reproducible Jupyter notebook with full B3 preprocessing and FP-Growth evaluation steps.