File size: 4,548 Bytes
5d5ab7d | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 | # AlphaForge - Multi-Asset Quantitative Trading System
A comprehensive quantitative trading system that combines price-based alpha signals, financial sentiment analysis, volatility forecasting, portfolio optimization, and ML-based options pricing.
## Features
### 1. Multi-Asset Alpha Model
- **LSTM** neural network for sequential pattern recognition
- **Transformer** architecture for attention-based forecasting
- **XGBoost** ensemble for robust feature-based predictions
- **Ensemble** combining all three with IC-weighted blending
- **IC Tracking**: Information Coefficient monitoring over time
- **Feature Drift Detection**: XGBoost importance divergence tracking
### 2. News + Sentiment Alpha (FinBERT)
- Uses `ProsusAI/finbert` for financial sentiment analysis
- Converts news/social media into numerical alpha signals
- Confidence-weighted aggregation per asset per day
- Synthetic news generation for testing
### 3. Volatility Forecasting Engine
- **GARCH(1,1)** with Student-t errors for baseline
- **LSTM** with skewed Student's t distributional output
- **EWMA covariance** matrix construction
- Positive definite enforcement
### 4. Portfolio Optimizer
- Mean-variance optimization with transaction costs
- Max Sharpe ratio optimization
- Minimum volatility with return constraints
- **Robust optimization** with uncertainty sets
- **Black-Litterman** model for incorporating views
- Efficient frontier computation
### 5. Options Pricing with ML
- 4-layer neural network (256-128-64-32)
- Black-Scholes baseline for comparison
- Implied volatility prediction
- **Mispricing detection** for arbitrage signals
- Synthetic data generation for training
### 6. Backtest Engine
- Transaction cost and slippage simulation
- Comprehensive metrics:
- Sharpe, Sortino, Calmar ratios
- Max drawdown, win rate
- Alpha, Beta, Information Ratio
- Turnover and cost analysis
- Regime detection (bull/bear/high-vol)
- Rolling performance metrics
## Installation
```bash
git clone https://huggingface.co/Premchan369/alphaforge-quant-system
cd alphaforge-quant-system
pip install -r requirements.txt
```
## Usage
### Train Alpha Model
```bash
python main.py --mode train --tickers SPY QQQ AAPL MSFT --epochs 50
```
### Run Full Backtest
```bash
python main.py --mode backtest --start 2020-01-01 --end 2024-01-01
```
### Train Options Model
```bash
python main.py --mode options
```
## Pipeline Architecture
```
Market Data (OHLCV)
|
+---> Technical Indicators (RSI, MACD, Bollinger, etc.)
+---> Cross-Asset Features (beta, correlation, spreads)
|
v
Alpha Model (LSTM + Transformer + XGBoost Ensemble)
|---> Predicted Returns (mu)
|---> IC Tracking
|
News Data
|
v
Sentiment Model (FinBERT)
|---> Sentiment Alpha (S_t)
|
v
Combined Alpha = w1 * Price Alpha + w2 * Sentiment Alpha
Market Data
|
v
Volatility Engine (GARCH + LSTM)
|---> Covariance Matrix (Sigma)
|
v
Portfolio Optimizer (Mean-Variance / Max Sharpe / Robust)
|---> Optimal Weights (w)
|
v
Backtest Engine
|---> PnL, Sharpe, Drawdown, etc.
```
## Key Metrics
| Metric | Description |
|--------|-------------|
| **IC** | Information Coefficient (rank correlation between predicted and actual returns) |
| **Sharpe** | Risk-adjusted return (excess return / volatility) |
| **Sortino** | Downside risk-adjusted return |
| **Max DD** | Maximum peak-to-trough decline |
| **Calmar** | Annualized return / max drawdown |
| **Alpha** | Excess return vs benchmark |
| **Beta** | Market sensitivity |
## File Structure
| File | Description |
|------|-------------|
| `main.py` | Entry point and orchestration |
| `market_data.py` | Data fetching and feature engineering |
| `alpha_model.py` | LSTM/Transformer/XGBoost ensemble |
| `sentiment_model.py` | FinBERT sentiment analysis |
| `volatility_model.py` | GARCH + LSTM volatility forecasting |
| `portfolio_optimizer.py` | Mean-variance and robust optimization |
| `options_pricer.py` | ML options pricing and mispricing detection |
| `backtest_engine.py` | Backtesting with comprehensive metrics |
## Research Backing
- **Alpha Models**: xLSTM-TS with wavelet denoising (Lopez Gil et al., 2024)
- **Sentiment**: FinBERT (Araci, 2019) with ChatGPT benchmarking (Fatouros et al., 2023)
- **Volatility**: LSTM with skewed Student's t (Michankow, 2025)
- **Portfolio**: Multi-task learning for joint optimization (Ong & Herremans, 2023)
- **Options**: 5-layer FNN outperforming Black-Scholes (Berger et al., 2023)
## License
MIT
|