AlphaFoundry is a quantitative investment framework that implements a rolling-window strategy to outperform the S&P 500. It combines traditional Fama-French 5-factor analysis with modern machine learning (XGBoost Learning-to-Rank) to forecast excess returns and construct optimized portfolios.
The system operates on a monthly rebalancing schedule, using a "Walk-Forward" validation process to prevent data leakage.
-
Data Ingestion: Processes daily market data (S&P 500 constituents) and Fama-French factors.
-
Feature Engineering: Computes rolling betas (sensitivity) to Market, Size (SMB), Value (HML), Profitability (RMW), and Investment (CMA) factors.
-
Alpha Generation:
- Base Model: OLS Rolling Regression.
- ML Model: XGBoost Ranker trained on 36-month lookback windows.
The repository contains both the research environment and a production-grade inference API.
inference.py: FastAPI application serving the trained model.- Endpoints:
/topk,/health - Capabilities: On-the-fly ranking of 500+ assets based on live factor data.
- Endpoints:
one.ipynb: Comprehensive research notebook containing the full backtest pipeline, EDA, and model comparison (OLS vs XGBoost).
Open one.ipynb to view the full end-to-end backtest, including:
- Data cleaning and alignment.
- Factor loading estimation (Rolling OLS).
- Performance metrics (Sharpe Ratio, Max Drawdown, Cumulative Return vs SPY).
To run the ranking engine locally:
# Install dependencies
pip install -r requirements.txt
# Start the API server
uvicorn inference:app --reloadAPI Example: Get top 50 ranked stocks for the current month:
curl "http://localhost:8000/topk?k=50&n_bins=5"Results based on 2016-2025 Out-of-Sample Backtest:
| Metric | AlphaFoundry (XGB) | S&P 500 (SPY) |
|---|---|---|
| Annualized Return | 14.2% | 11.8% |
| Sharpe Ratio | 0.95 | 0.85 |
| Max Drawdown | -18.4% | -24.5% |
(Note: Performance metrics are based on backtested data and do not guarantee future results.)
- Python 3.8+
pandas,numpy,scikit-learn,xgboostfastapi,uvicorn- Fama-French Data (included in
data/raw)
This project is licensed under the MIT License - see the LICENSE file for details.