AcyLa's picture
Update ML Intern artifact metadata
b933bb9 verified
|
Raw History Blame Contribute Delete
11.4 kB
---
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