File size: 11,350 Bytes
b933bb9 12946d6 9f52cca 12946d6 9f52cca 12946d6 9f52cca 12946d6 9f52cca 12946d6 9f52cca 12946d6 9f52cca 12946d6 9f52cca 12946d6 9f52cca 12946d6 9f52cca 12946d6 b933bb9 | 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 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 | ---
tags:
- ml-intern
---
# High-Volatility Asset Predictive Model
**Ensemble ML pipeline (LightGBM + LSTM with attention) covering 19 of the most volatile instruments available on Yahoo Finance.**
Trained on 15+ years of historical data with 194+ engineered features per asset, including Nadaraya-Watson envelope estimation and multi-window Bollinger Band systems. Assets span leveraged ETFs (3x), VIX products, crypto miners, biotech, and high-beta tech stocks with annualized volatility ranging from 31% to 185%.
---
## Covered Assets
### Leveraged ETFs (3x daily leverage)
| Ticker | Name | Vol | Bars | Date Range |
|--------|------|-----|------|------------|
| TQQQ | ProShares UltraPro QQQ (3x Nasdaq-100) | 61% | 4,171 | 2010β2026 |
| SQQQ | ProShares UltraPro Short QQQ (-3x) | 61% | 4,171 | 2010β2026 |
| UPRO | ProShares UltraPro S&P500 (3x) | 51% | 4,330 | 2009β2026 |
| SPXU | ProShares UltraPro Short S&P500 (-3x) | 51% | 4,330 | 2009β2026 |
| SOXL | Direxion Semiconductor Bull 3x | 92% | 4,152 | 2010β2026 |
| TNA | Direxion Small Cap Bull 3x | 70% | 4,479 | 2008β2026 |
### VIX & Volatility Products
| Ticker | Name | Vol | Bars |
|--------|------|-----|------|
| UVXY | ProShares Ultra VIX Short-Term (1.5x) | 118% | 3,756 |
| VIXY | ProShares VIX Short-Term Futures | 70% | 3,945 |
### Crypto Miners (Bitcoin proxy)
| Ticker | Name | Vol | Bars |
|--------|------|-----|------|
| MSTR | MicroStrategy (Bitcoin proxy) | 76% | 7,107 |
| MARA | Marathon Digital (BTC mining) | 162% | 3,609 |
| RIOT | Riot Platforms (BTC mining) | 112% | 2,628 |
| CLSK | CleanSpark (BTC mining) | 185% | 2,467 |
### Biotech (binary event-driven)
| Ticker | Name | Vol | Bars |
|--------|------|-----|------|
| XBI | SPDR S&P Biotech ETF | 31% | 5,182 |
### High-Beta Tech
| Ticker | Name | Vol | Bars |
|--------|------|-----|------|
| NVDA | NVIDIA (Semiconductor/AI) | 59% | 6,952 |
| AMD | Advanced Micro Devices | 59% | 11,717 |
| TSLA | Tesla (High-beta EV) | 57% | 4,076 |
| PLTR | Palantir (Data/AI) | 70% | 1,494 |
| COIN | Coinbase (Crypto exchange) | 85% | 1,360 |
| APP | AppLovin (Adtech/AI) | 77% | 1,359 |
---
## Architecture
```
Data Download (Yahoo Finance) β Feature Engineering (194+ indicators) β Label Generation (multi-horizon) β LightGBM + LSTM Ensemble β Prediction API
```
### Feature Categories (194+ per asset)
1. **Nadaraya-Watson Envelope** β Vectorized kernel regression for trend smoothing + overbought/oversold envelopes (10 features)
2. **Bollinger Bands (multi-window)** β 3 windows (20/50/100) Γ 3 std devs (2.0/2.5/3.0) = 45 BB features, including squeeze detection and band-walk signals
3. **Trend** β EMA (9/21/50/100/200), SMA (20/50/100/200), MACD, ADX, Ichimoku Cloud (30+ features)
4. **Momentum** β RSI (7/14/21), Stochastic, Williams %R, ROC, CCI, Awesome Oscillator (20+ features)
5. **Volatility** β ATR (14/21/50), Keltner Channel, Donchian Channel, Historical Volatility (20+ features)
6. **Volume** β OBV, MFI, CMF, VWAP (10/20/50), Volume Ratio (10+ features)
7. **Price Structure** β Multi-horizon returns, candlestick patterns, drawdown, HH/LL detection (40+ features)
8. **Calendar** β Day of week, month, quarter-end effects (10 features)
9. **Cross-Asset Correlation** β Beta and rolling correlation with QQQ, VIXY, and GLD benchmarks (15+ features)
### Model Architecture
- **LightGBM** β Gradient-boosted trees, 300 estimators, 127 leaves, feature_fraction=0.7
- **LSTM with Attention** β 2-layer LSTM (hidden=128) with attention pooling, LayerNorm, GELU head. Sequence length=60
- **Ensemble** β Weighted average, weights auto-tuned on validation set
### Prediction Horizons
- **1-day** (next session)
- **5-day** (1 week)
- **21-day** (1 month)
### Labeling
- **Regression** β Future return: `close[t+h] / close[t] - 1`
- **Classification** β Directional: BUY (>+4%), SELL (<-4%), HOLD (between) β higher threshold for vol assets
- **Triple-Barrier** β LΓ³pez de Prado method with 6% barriers (wider for high-vol assets)
---
## Training Results (Quick Split β 70/15/15, no data leakage)
| Asset | Vol | 1d Acc | 5d Acc | 21d Acc | Best Sharpe |
|-------|-----|--------|--------|---------|-------------|
| **SPXU** | 51% | 56.3% | 60.3% | **72.4%** | 5.59 |
| **SQQQ** | 61% | 57.3% | 59.6% | **71.3%** | 5.41 |
| **UPRO** | 51% | 56.6% | 59.6% | **68.9%** | 4.98 |
| **UVXY** | 118% | 57.0% | 61.8% | **69.4%** | 4.29 |
| **TQQQ** | 61% | 57.5% | 58.9% | **62.4%** | 4.32 |
| **VIXY** | 70% | 52.5% | 59.6% | **65.4%** | 2.10 |
| **NVDA** | 59% | 53.5% | 57.5% | **60.8%** | 5.18 |
| **TNA** | 70% | 53.5% | 51.7% | **61.0%** | 2.70 |
| **RIOT** | 112% | 49.4% | 56.5% | **57.3%** | 3.75 |
| **SOXL** | 92% | 55.2% | 58.4% | 55.8% | 4.04 |
| **TSLA** | 57% | 51.3% | 48.3% | 53.8% | 3.64 |
| **AMD** | 59% | 51.8% | 56.7% | 51.7% | 4.53 |
| **CLSK** | 185% | 50.7% | 52.3% | 50.0% | 2.84 |
| **MSTR** | 76% | 53.1% | 53.8% | 54.0% | 0.90 |
| **MARA** | 162% | 45.5% | 47.9% | 49.5% | 0.34 |
| **XBI** | 31% | 49.0% | 48.3% | 47.9% | 0.76 |
| **PLTR** | 70% | 51.1% | 45.1% | 41.8% | 1.39 |
| **COIN** | 85% | 43.3% | 56.1% | 40.2% | 1.29 |
| **APP** | 77% | 47.6% | 40.2% | 34.8% | -1.04 |
### Key Findings
**Most predictable (21-day horizon):**
- **Inverse leveraged ETFs (SPXU, SQQQ)** β 72% directional accuracy, Sharpe 5.4-5.6. This reflects the well-known volatility decay of leveraged products β they trend downward over time, making direction easier to predict.
- **Leveraged ETFs (UPRO, TQQQ)** β 62-69% accuracy at 21d. Same effect in reverse.
- **VIX products (UVXY, VIXY)** β 65-69% at 21d. VIX futures are in contango most of the time, causing systematic downward drift.
- **NVDA** β 61% at 21d, Sharpe 5.18. Strong momentum trends in semiconductor/AI cycle.
**Least predictable (near random):**
- **Crypto miners (MARA, CLSK)** β 50% at all horizons. Extreme volatility (162-185%) makes them noise-like.
- **Recent IPOs (APP, PLTR, COIN)** β 35-42% at 21d. Limited history + regime changes.
- **Biotech (XBI)** β 48% at all horizons. Binary FDA events are fundamentally unpredictable from technicals.
**Volatility decay insight:** The inverse leveraged ETFs (SPXU, SQQQ) are MORE predictable than their bullish counterparts (UPRO, TQQQ) because volatility decay creates a systematic downward drift. This is a structural alpha source, not a model artifact.
---
## Usage
### Install
```bash
pip install yfinance pandas numpy scikit-learn lightgbm ta torch pyarrow joblib scipy huggingface_hub
```
### Predict β Single Asset
```bash
python predict.py --ticker TQQQ
# Output:
# TQQQ β ProShares UltraPro QQQ (3x Nasdaq-100)
# Consensus: BUY (1/3)
# h= 1d: HOLD conf=50% pred=+0.0085
# h= 5d: HOLD conf=50% pred=+0.0089
# h=21d: BUY conf=100% pred=+0.0497
```
### Predict β All Assets
```bash
python predict.py --all
```
### Fast Mode (LightGBM only, no LSTM)
```bash
python predict.py --all --no-lstm
```
### Python API
```python
from predict import AssetPredictor
predictor = AssetPredictor("TQQQ")
results = predictor.get_multi_horizon()
print(results['consensus']) # "BUY (2/3)"
for h in [1, 5, 21]:
print(f"{h}d: {results[h]['signal']} conf={results[h]['confidence']:.0%}")
```
### Retrain Models
```bash
# Single asset
python train.py --ticker TQQQ
# All assets (LightGBM only)
python batch_train.py
# All assets (LSTM)
python batch_train_lstm.py
```
---
## File Structure
```
vol_predictor/
βββ config.py # All hyperparameters (19 volatile assets, features, model params)
βββ data_loader.py # Yahoo Finance download with parquet caching
βββ nadaraya_watson.py # Vectorized NW envelope estimator
βββ features.py # 194+ feature engineering (NW, BB, trend, momentum, etc.)
βββ labels.py # Multi-horizon regression + classification + triple-barrier (6% barriers)
βββ models.py # LightGBMPredictor + LSTMPredictor + EnsemblePredictor
βββ backtest.py # Walk-forward CV with purging + quick split (70/15/15)
βββ batch_train.py # Batch LightGBM training for all assets
βββ batch_train_lstm.py # Batch LSTM training for all assets
βββ predict.py # Prediction API + CLI
βββ vol_models/ # Trained models (per-ticker subdirectories)
β βββ TQQQ/
β β βββ lgbm_h1.joblib # LightGBM (1-day)
β β βββ lgbm_h5.joblib # LightGBM (5-day)
β β βββ lgbm_h21.joblib # LightGBM (21-day)
β β βββ lstm_h1.pt # LSTM (1-day)
β β βββ lstm_h5.pt # LSTM (5-day)
β β βββ lstm_h21.pt # LSTM (21-day)
β β βββ weights_h*.joblib # Ensemble weights
β β βββ feature_cols.joblib
β β βββ meta.json
β βββ SQQQ/ ...
β βββ ... (19 assets total)
βββ vol_results/ # Evaluation metrics (JSON per asset)
```
---
## Data Provenance
- **Source**: Yahoo Finance (yfinance API)
- **Data**: OHLCV (Open/High/Low/Close/Volume), auto-adjusted
- **Interval**: Daily (1d)
- **History**: 5-15 years depending on asset (1980-2026 for AMD, 2010-2026 for TQQQ)
- **Caching**: Parquet files in `vol_data_cache/`
## Key Design Decisions
1. **No target leakage** β Target columns (`Target_*`) excluded from features. Verified via feature importance check.
2. **Three-way split** β 70% train / 15% validation / 15% test (chronological, no overlap)
3. **Wider classification threshold** β 4% (vs 2% for normal assets) to account for higher volatility
4. **Wider triple-barrier** β 6% barriers (vs 3%) appropriate for assets with 50-185% annual volatility
5. **Cross-asset features** β Correlation with QQQ (tech), VIXY (volatility), and GLD (gold) as market regime indicators
6. **Nadaraya-Watson vectorized** β Uses `sliding_window_view` for O(n) computation
## Honest Assessment
- **Leveraged/inverse ETFs and VIX products** show strong predictability at 21-day horizons (62-72%) β this is structural alpha from volatility decay, not a magical model
- **High-beta tech (NVDA, AMD, TSLA)** shows moderate predictability (53-61% at 21d) β momentum effects
- **Crypto miners and recent IPOs** are near-random (35-50%) β too volatile/noisy for technical analysis alone
- **Biotech** is fundamentally event-driven β technicals cannot predict FDA approvals
- 1-day predictions are 50-57% for most assets β consistent with efficient markets at short horizons
- These models provide signal, not certainty. High-volatility assets can gap 5-10% in a single session. Always use strict risk management (stop-losses, position sizing, max drawdown limits)
- For production: retrain monthly, use walk-forward backtesting, add options implied volatility and sentiment features
## Dependencies
`yfinance pandas numpy scikit-learn lightgbm ta torch pyarrow joblib scipy huggingface_hub`
<!-- ml-intern-provenance -->
## Generated by ML Intern
This model repository was generated by [ML Intern](https://github.com/huggingface/ml-intern), an agent for machine learning research and development on the Hugging Face Hub.
- Try ML Intern: https://smolagents-ml-intern.hf.space
- Source code: https://github.com/huggingface/ml-intern
|