Cross-Sectional Equity Return Prediction & Statistical Inference Engine (Phase 3.5)
1. Executive Summary
This repository implements an institutional-grade quantitative equity research pipeline evaluating whether regularized machine learning models improve out-of-sample cross-sectional return prediction and net risk-adjusted portfolio performance over transparent factor baselines and a market-capitalization benchmark.
Research Question: On a Point-in-Time CRSP Top-500 US Common-Equity Universe (2014–2024), do constrained LightGBM and Ridge Regression models outperform a standalone 12–1 Momentum signal, an Aligned 5-Factor Heuristic, or the Top-500 Cap-Weighted Universe under strict t+1 -> t+6 5-cohort execution and multiple-testing control?
Key Empirical Takeaways (Honest Null & Benchmark-Outperformance Finding):
- Neither LightGBM nor Ridge beat standalone 12–1 Momentum out of sample: In both quarantined validation (
2022–2023) and the untouched final test (2024), higher-turnover ML signals (13.30x–16.34x annualized L/S turnover for LightGBM vs. 7.29x–7.49x for Momentum) generated lower net Sharpe ratios (-0.3779 and -0.2815 Excess Sharpe vs. -0.0821 and 0.8190 for Momentum).
- Zero strategies survive multiple-testing FDR control (
M = 5): Across all five pre-specified hypotheses (H_1–H_5), neither Benjamini-Hochberg (q = 0.05) nor Benjamini-Yekutieli adjusted one-sided Newey-West HAC (L = 5) p-values reject the null in 2022–2023 or 2024. Even in 2024, where 12–1 Momentum (H_1) achieved 11.41% annualized net spread return (Spread Sharpe = 1.4671) and a strictly positive 95% bootstrap IC CI ([0.0040, 0.0845]), its nominal one-sided p-value (0.0511) became 0.2553 (BH) and 0.5830 (BY).
- Long-only ML trailed the Cap-Weighted benchmark:
LightGBM Long-Only (top quintile, 0 bps short borrow) trailed the Top-500 Cap-Weighted benchmark by -3.43%/yr in 2022–2023 (-0.32% vs. 3.11%) and -3.48%/yr in 2024 (22.51% vs. 26.00%).
2. Methodology Overview (Frozen Phase 3.5 Specification)
2.1 Data & Point-in-Time CRSP Top-500 Universe (src/data/)
- WRDS Legacy SIZ Extraction (
2014-01-01 to 2024-12-31): crsp.dsf, crsp.dsedelist, crsp.stocknames, crsp.dsi.vwretd, and ff.factors_daily.rf via WRDSFetcher.
- Annual Reconstitution: Ranked on the final trading day of December ($T$), effective on the first trading day of January ($Y+1$).
- Pre-Ranking Eligibility Filters:
- US common-equity share codes:
shrcd $\in {10, 11}$
- Effective-dated primary exchange:
exchcd $\in {1, 2, 3}$ with $\text{namedt} \le T \le \text{nameenddt}$
- Operating entity exclusions:
siccd $\neq 6798$ (REITs) and siccd $\notin [6720, 6726]$ (closed-end funds)
- Liquidity/price floor: $|P_T| \ge 5.00$ USD and $S_T > 0$
- Return seasoning: at least
252 valid daily returns over the prior 252 market trading days
- Deterministic Top-500 Selection & Delisting Contraction: Ranked descending by $\text{Cap}{i,T} = |P{i,T}| \cdot S_{i,T} \cdot 1000$ with deterministic tie-breaking by
permno ascending. Mid-year delistings naturally contract daily active membership to $500 - K_t$ without replacement. Missing PIT metadata raises ValueError (silent fallbacks disabled).
- Shumway Delisting Engine (
src/data/delisting.py): Compounds $R_{i,\text{total}} = (1 + R_{i,\text{ret}})(1 + R_{i,\text{dlret}}) - 1$ on dlstdt. Exchange-sensitive Shumway imputation (-30% for NYSE/AMEX exchcd $\in {1, 2}$, -55% for NASDAQ exchcd $= 3$) applies strictly to dlstcd $\in {500, 520, 551\text{–}574, 580, 584}$. All other missing dlret events (117 rows across the 2014–2024 dataset) are recorded in get_unresolved_audit_log() with numeric dlret = 0.0 in baseline (plus -100% pessimistic and 0% optimistic sensitivity toggles).
2.2 Exact 5-Factor Features & Normalization (src/features/engine.py)
Raw trailing windows are computed on the continuous 2014–2024 delisting-adjusted history panel prior to intersecting active PIT daily membership (2015–2024), preventing early-year lookback truncation while preserving strict PIT cross-sectional normalization:
| Feature |
Economic Definition |
Calendar Window |
Min Valid Obs |
mom_12_1 |
Compounded 12-to-1 month momentum return |
$[t-251, t-21]$ |
$K \ge 200$ |
rev_1m |
Compounded 1-month short-term reversal |
$[t-20, t]$ |
$K \ge 18$ |
vol_63d |
Annualized sample return volatility ($\sqrt{252},\hat{\sigma}$) |
$[t-62, t]$ |
$K \ge 50$ |
beta_252d |
Market-Model Beta (rolling OLS slope vs. crsp.dsi.vwretd) |
$[t-251, t]$ |
$K \ge 200$ paired |
turnover_21d |
Mean share turnover $\text{vol} / (\text{shrout} \times 1000)$ |
$[t-20, t]$ |
$K \ge 18$ |
On each active PIT date $t$, features are cross-sectionally MAD-winsorized ($\text{median}_t \pm 5 \times 1.4826 \times \text{MAD}_t$, falling back to 1%/99% quantiles only if $\text{MAD}_t = 0$), cross-sectionally z-scored, and median-imputed (z = 0.0) with binary *_missing indicator flags.
2.3 Continuous Targets, 6-Day Calendar Purge & Research Schedule (src/validation/)
- Non-Anticipatory Target: Signal at close $t$ → enter at close $t+1$ → exit at close $t+6$:
$$y_{i,t} = \prod_{j=2}^{6}(1 + R_{i,t+j}) - 1$$
Securities must be active at $t+1$ close; mid-horizon delistings on $t+2 \dots t+6$ settle at $R_{\text{total}}$ on
dlstdt and hold 0% cash through $t+6$.
- Strict 6-Trading-Day Purge:
PurgedWalkForwardCV and ResearchScheduleSplitter enforce $t_{\text{train}} \le T_{\text{val}} - 7$ on the canonical market calendar across three regimes:
- Development / Tuning (
2015-01-01 to 2021-12-31): 4 expanding folds validating 2018, 2019, 2020, 2021
- Quarantined Validation (
2022-01-01 to 2023-12-31): Frozen-model evaluation
- Untouched Final Test (
2024-01-02 to 2024-12-20): Terminal signal date 2024-12-20 (allowing 6 trading days through 2024-12-31), locked by default (--run-final-test defaults to False)
2.4 Models, Benchmarks & 5-Cohort Execution (src/models/, src/portfolio/)
- Models & Benchmarks: Constrained
LightGBM (max_depth $\in {2,3,4}$, num_leaves $\le 2^{\text{depth}}$, min_child_samples $\in {250,500,1000}$, learning_rate $\in {0.01,0.03,0.05}$, L2 early stopping at 50 rounds, leaf concentration diagnostics), Ridge ($\alpha \in {0.01, 0.1, 1, 10, 100, 1000}$), Standalone 12–1 Momentum, Aligned 5-Factor Heuristic ($z(\text{mom}{\text{12-1}}) - z(\text{rev}{\text{1m}}) - z(\text{vol}{\text{63d}}) - z(\text{beta}{\text{252d}}) - z(\text{turnover}_{\text{21d}})$), and Top-500 Cap-Weighted Universe ($t-1$ cap weights).
- Portfolio Construction: Quintile sorting (
num_quantiles = 5; 10 sensitivity). Option B (100% gross exposure: +50% Long / -50% Short, $\text{NAV} = 1.0$, daily spread $0.5,(R_L - R_S)$) for H_1–H_4; Long-Only Top Quintile (+100% Long / 0% Short, 0 borrow drag) for H_5.
- 5 Overlapping Cohorts & Costs:
20% of capital enters daily at $t+1$ close, drifts unrebalanced across $t+2 \dots t+6$, and exits at $t+6$ close (Cost_t = 2c · Turnover_t with baseline c = 5 bps plus 0.5 · (b / 252) with baseline b = 50 bps annualized short borrow; optional market impact and Alphalens diagnostics disabled by default via --use-market-impact=False, --run-alphalens=False).
2.5 Statistical Inference (src/evaluation/)
- Excess Returns: Daily
ff.factors_daily.rf subtraction ($R_t - r_{f,t}$) for standalone portfolio Excess Sharpe without double-subtracting $r_f$ from the H_5 active spread.
- Joint Circular Block Bootstrap: Joint date-level resampling with circular wrapping ($z_{T+j} = z_j$),
b = 5 primary (b in {10, 21} sensitivity), M = 10,000 replications, seed = 42.
- Multiple-Testing Control (
M = 5): One-sided upper-tail tests via Newey-West HAC (L = 5) with Benjamini-Hochberg (q = 0.05) and Benjamini-Yekutieli adjusted p-values across H_1–H_5.
3. Empirical Results (2015–2024 WRDS PIT Top-500)
3.1 2015–2021 Development Tuning (4 Expanding Folds: 2018–2021)
- Constrained LightGBM (
n_estimators = 12): Best grid parameters max_depth = 2, num_leaves = 4, min_child_samples = 250, learning_rate = 0.05, subsample = 0.8, subsample_freq = 1, colsample_bytree = 0.8; mean OOS daily Spearman IC = 0.0094 (fold ICs: 0.0090, 0.0317, -0.0040, 0.0010).
- Ridge Regression (
alpha = 100.0): Mean OOS daily Spearman IC = 0.0057 (fold ICs: -0.0193, 0.0296, 0.0016, 0.0107).
3.2 2022–2023 Quarantined Validation (2022-01-03 to 2023-12-29, n_days = 505)
| Strategy / Benchmark |
Mean IC |
ICIR |
Net Ann. Return |
Spread Sharpe |
Excess Sharpe |
Max DD |
Turnover |
Cost Drag |
BH Adj. p (Reject) |
H_1 (12–1 Momentum L/S) |
0.0183 |
0.0754 |
2.19% |
0.1804 |
-0.0821 |
14.53% |
7.49x |
99.7 bps |
0.6051 (False) |
H_2 (5-Factor Heuristic L/S) |
0.0151 |
0.0473 |
2.69% |
0.1704 |
-0.0316 |
16.52% |
9.04x |
115.2 bps |
0.6051 (False) |
H_3 (Ridge L/S) |
-0.0043 |
-0.0143 |
-1.23% |
-0.0774 |
-0.2785 |
19.31% |
10.62x |
131.0 bps |
0.6051 (False) |
H_4 (LightGBM L/S) |
-0.0076 |
-0.0282 |
-2.61% |
-0.1698 |
-0.3779 |
19.63% |
13.30x |
157.7 bps |
0.6051 (False) |
lgbm_long_only (Top Quintile) |
-0.0076 |
-0.0282 |
-0.32% |
— |
-0.0922 |
40.17% |
9.43x |
94.3 bps |
— |
H_5 (lgbm_long_only - CapW) |
-0.0076 |
-0.0282 |
-3.43% |
-0.1546 |
— |
— |
— |
— |
0.6051 (False) |
Top-500 Cap-Weighted |
— |
— |
3.11% |
— |
-0.0043 |
25.01% |
— |
— |
— |
- 2022–2023 HAC & FDR Details (
BY Adj. p = 1.0000 for all 5): H_1 (t = 0.2818, nominal p = 0.3890), H_2 (t = 0.2617, p = 0.3968), H_3 (t = -0.1224, p = 0.5487), H_4 (t = -0.2667, p = 0.6051), H_5 (t = -0.2448, p = 0.5967).
- 2022–2023 Circular Block Bootstrap (
b = 5, 95% CIs): All five hypotheses span zero across mean daily return, spread Sharpe (H_1: [-1.0786, 1.5492], H_4: [-1.4915, 1.1073]), and bootstrap IC (H_1: [-0.0196, 0.0558], H_4: [-0.0481, 0.0348]).
3.3 2024 Untouched Final Test (2024-01-02 to 2024-12-20, n_days = 250)
| Strategy / Benchmark |
Mean IC |
ICIR |
Net Ann. Return |
Spread Sharpe |
Excess Sharpe |
Max DD |
Turnover |
Cost Drag |
HAC t (p_nom) |
BH_p / BY_p (Rej) |
H_1 (12–1 Momentum L/S) |
0.0471 |
0.2487 |
11.41% |
1.4671 |
0.8190 |
4.31% |
7.29x |
97.5 bps |
1.635 (0.0511) |
0.2553 / 0.5830 (False) |
H_2 (5-Factor Heuristic L/S) |
0.0160 |
0.0818 |
-0.90% |
-0.1070 |
-0.7083 |
8.47% |
9.66x |
121.2 bps |
-0.118 (0.5468) |
0.6261 / 1.0000 (False) |
H_3 (Ridge L/S) |
0.0109 |
0.0561 |
-0.65% |
-0.0839 |
-0.7317 |
8.25% |
13.49x |
159.5 bps |
-0.089 (0.5356) |
0.6261 / 1.0000 (False) |
H_4 (LightGBM L/S) |
0.0098 |
0.0536 |
2.94% |
0.3950 |
-0.2815 |
6.75% |
16.34x |
187.1 bps |
0.427 (0.3345) |
0.6261 / 1.0000 (False) |
lgbm_long_only (Top Quintile) |
0.0098 |
0.0536 |
22.51% |
1.1241 |
0.8724 |
13.43% |
13.29x |
132.9 bps |
— |
— |
H_5 (lgbm_long_only - CapW) |
0.0098 |
0.0536 |
-3.48% |
-0.3109 |
— |
12.66% |
— |
— |
-0.321 (0.6261) |
0.6261 / 1.0000 (False) |
Top-500 Cap-Weighted |
— |
— |
26.00% |
1.9925 |
1.6062 |
8.90% |
— |
— |
— |
— |
2024 Circular Block Bootstrap 95% & 99% CIs (b = 5 primary) & b ∈ {5, 10, 21} Sensitivity
| Strategy |
95% Ret CI (b = 5) |
99% Ret CI (b = 5) |
95% Spread Sharpe CI (b = 5) |
99% Spread Sharpe CI (b = 5) |
95% IC CI (b = 5) |
99% IC CI (b = 5) |
H_1 |
[-0.000115, 0.001007] |
[-0.000287, 0.001195] |
[-0.3774, 3.3861] |
[-0.8887, 4.0470] |
[0.0040, 0.0845] |
[-0.0085, 0.0988] |
H_2 |
[-0.000631, 0.000584] |
[-0.000826, 0.000791] |
[-1.9307, 1.7227] |
[-2.5696, 2.3219] |
[-0.0266, 0.0617] |
[-0.0393, 0.0763] |
H_3 |
[-0.000606, 0.000535] |
[-0.000777, 0.000708] |
[-1.8860, 1.8061] |
[-2.3916, 2.3926] |
[-0.0349, 0.0552] |
[-0.0505, 0.0705] |
H_4 |
[-0.000440, 0.000657] |
[-0.000618, 0.000817] |
[-1.4360, 2.3167] |
[-2.0181, 2.9089] |
[-0.0331, 0.0499] |
[-0.0452, 0.0638] |
H_5 |
[-0.000990, 0.000729] |
[-0.001250, 0.000992] |
[-2.3179, 1.5622] |
[-2.9391, 2.1226] |
[-0.0331, 0.0499] |
[-0.0452, 0.0638] |
- Block-Length Sensitivity (
b ∈ {5, 10, 21}): Conclusions remain invariant across longer block lengths (b = 10, b = 21). All 95% and 99% mean-return and spread-Sharpe CIs include zero for every hypothesis (H_1 95% Sharpe CI: [-0.1897, 3.2674] at b = 10 and [-0.1140, 3.3183] at b = 21), while H_1 daily IC remains positive at 95% ([0.0038, 0.0870] at b = 10; [0.0033, 0.0899] at b = 21) and crosses zero at 99%.
Methodological Footnotes:
- Spread Sharpe vs. Excess Sharpe:
Spread Sharpe is annualized mean / std * sqrt(252) on the portfolio/active spread without subtracting rf (zero-cost long-short spread assumption); Excess Sharpe subtracts daily ff.factors_daily.rf, which applies directly to long-only portfolios and dollar-neutral spreads funded against zero-interest collateral.
- IC Date Alignment: Standalone Spearman IC (
n_valid_dates = 501 in 2022–2023, 246 in 2024) drops trailing boundary signal dates whose 6-day target extends past the period cutoff; joint Circular Block Bootstrap aligns daily ICs against realized portfolio dates (n_obs = 505 in 2022–2023 with bootstrap IC 0.0185 / -0.0070; n_obs = 250 in 2024 with bootstrap IC 0.0441 / 0.0084), causing small boundary-alignment differences.
- Long-Only vs. Active Spread:
lgbm_long_only shares H_4 LightGBM prediction ICs; H_5 (lgbm_long_only minus Top-500 Cap-Weighted) is evaluated as a benchmark-relative active spread without subtracting rf twice.
4. Repository Structure, Legacy Progression & Reproducibility
4.1 Codebase Layout
.
├── main.py # CLI runner (--run-final-test, --use-market-impact, --run-alphalens default False)
├── requirements.txt # Pinned Python dependencies
├── src/
│ ├── pipeline.py # SystematicTradingPipeline orchestrator & artifact serialization
│ ├── data/
│ │ ├── wrds_fetcher.py # WRDS Legacy SIZ extractor (dsf, dsedelist, stocknames, dsi, ff_factors)
│ │ ├── universe.py # Point-in-Time CRSP Top-500 universe engine (PointInTimeUniverse)
│ │ └── delisting.py # Strict Shumway delisting engine & UNRESOLVED audit log
│ ├── features/
│ │ └── engine.py # 5-factor engine, MAD winsorization, Z-scoring & median imputation
│ ├── validation/
│ │ ├── target.py # Continuous t+1 -> t+6 compounded targets & delisting cash settlement
│ │ └── splitters.py # PurgedWalkForwardCV (6-day purge) & ResearchScheduleSplitter
│ ├── models/
│ │ ├── walk_forward.py # ConstrainedLightGBMTuner, RidgeTuner & leaf concentration diagnostics
│ │ └── benchmarks.py # 12-1 Momentum, 5-Factor Heuristic & Top-500 Cap-Weighted benchmark
│ ├── portfolio/
│ │ ├── allocator.py # Option B (+50% L / -50% S) & Long-Only Top Quintile allocator
│ │ └── simulator.py # 5-overlapping-cohort simulator & gated impact model
│ └── evaluation/
│ ├── metrics.py # Daily ff.factors_daily.rf excess returns, drawdowns & cost attribution
│ ├── bootstrap.py # Joint Circular Block Bootstrap (b=5/10/21, M=10,000, seed=42)
│ ├── fdr.py # M=5 one-sided Newey-West HAC (L=5) + BH & BY FDR adjustments
│ └── alphalens_adapter.py # Optional Alphalens diagnostics (run_alphalens=False by default)
├── tests/ # 56 synthetic unit & integration tests across 8 test modules
└── legacy/ # Frozen 5-stock academic prototype (see legacy/README_LEGACY.md)
4.2 Progression from legacy/
The legacy/ directory preserves the original frozen 5-stock academic course project (MSFT, JNJ, XOM, AAPL, JPM; 11,320 rows; single mom_1m_z feature; 3-quantile discretized target; 5-day purge; mean IC = -0.0036, ICIR = -0.2064) alongside SHA-256 integrity digests. Upgrading to src/ replaced the 5-stock sample with the full Point-in-Time CRSP Top-500 US Common-Equity Universe, exchange-sensitive Shumway delisting adjustments, continuous t+1 -> t+6 targets, a 6-day purge, 5 overlapping cohorts, and formal bootstrap/FDR inference.
4.3 Running Tests Without WRDS Access
CRSP and Fama-French datasets require an institutional WRDS account (and raw parquets / output reports remain excluded via .gitignore). All 56 unit and integration tests run fully offline using deterministic synthetic market fixtures:
python3 -m venv .venv && source .venv/bin/activate
pip install --upgrade pip && pip install -r requirements.txt
python3 -m unittest discover -s tests -v # Runs all 56 tests offline (56/56 passing)
4.4 Running the Pipeline CLI (main.py)
# Default: 2015–2021 dev tuning + 2022–2023 quarantined validation (2024 locked)
python3 main.py --data data/raw --output reports/
# Download fresh WRDS CRSP & FF tables (requires WRDS_USERNAME / ~/.pgpass)
export WRDS_USERNAME="your_wrds_username"
python3 main.py --wrds --output reports/
# Unlock one-shot 2024 final test evaluation (disabled by default)
python3 main.py --data data/raw --output reports/final_test_2024 --run-final-test
Supported CLI options (python3 main.py --help): --data (data/raw), --wrds (False), --start-date (2014-01-01), --end-date (2024-12-31), --output (reports/), --delisting-sensitivity {shumway,-100%,0%,pessimistic,optimistic} (shumway), --quantiles (5), --fee-bps (5.0), --borrow-bps (50.0), --use-market-impact (False), --aum (100000000.0), --liquidity-mode {ignore,warn,cap} (ignore), --bootstrap-block (5), --bootstrap-reps (10000), --seed (42), --run-final-test (False), --run-alphalens (False), --quiet (False).
4.5 Programmatic Usage
from src.pipeline import PipelineConfig, SystematicTradingPipeline
config = PipelineConfig(
data_path="data/raw",
num_quantiles=5,
use_market_impact=False,
run_alphalens=False,
run_final_test=False,
output_dir="reports/",
)
results = SystematicTradingPipeline(config).run()
print(results["validation"]["fdr_table"])
评论