An end-to-end ML pipeline for regime-aware cryptocurrency trading (ETH-USD): deterministic phase labeling (bull/sideways/bear), feature engineering (50+ indicators), XGBoost for bear regime, Optuna hyperparameter tuning, and VectorBT backtesting. Achieves Sharpe ~1.95, Total Return ~24% (2024–2025). Staged for deep learning with Temporal Fusion Transformer (TFT) on hourly data.
- Regime-Aware ML: Deterministic phase labeling (bull/sideways/bear) using YAML-configured rules (slope, volatility, hysteresis). XGBoost model for bear regime (daily data), with TFT staged for hourly data.
- Feature Engineering: 50+ technical indicators (MA, EMA, RSI, MACD, ATR, Bollinger Bands, ADX) via
talibrary. - Tuning & Backtesting: Optuna with time-aware walk-forward CV (60 trials), VectorBT with fees/slippage for realistic backtests.
- Engineering: Reproducible CLI (
tsroot.cli) withtyper,Makefilefor one-command pipeline (data → features → phases → ML → backtest), Poetry environments (core,tft), no look-ahead bias.
- Bear Regime (ETH-USD, 2024–2025 test): Sharpe Ratio ~1.95, Total Return ~24.29%, Max Drawdown ~20.17%, 5 trades.
- Baseline (Buy & Hold): Sharpe ~1.06, Total Return ~3.25%, Max Drawdown ~59.12%.
- Methodology: 3-day horizon classification/regression, thresholded signals with volatility gating.
| Metric | Model Value | Buy & Hold |
|---|---|---|
| Sharpe Ratio | 1.95 | 1.06 |
| Total Return | 24.29% | 3.25% |
| Max Drawdown | 20.17% | 59.12% |
| Trades | 5 | - |
Show Instructions
- Clone and install dependencies:
git clone https://github.com/NkvMax/trading-system.git
cd trading-system
poetry install-
Configure pipeline in
configs/ETH-USD.yaml(phase rules: base_window, thresholds). -
Run pipeline (bear regime, ETH-USD):
# Download raw data (yfinance)
make data
# Generate 50+ indicators
make features
# Label bull/sideways/bear
make phases
# Train XGBoost with Optuna
make train
# Run VectorBT backtest
make backtest- For TFT (hourly data, GPU ≥16GB VRAM):
# Use -E tft for deep learning (GPU)
poetry install -E tft
make tft_trainArtifacts saved in data/, models/, logs/. Plots (equity curves, predictions) in logs/.
Show Details
- Phase Logic: YAML-defined rules (e.g., bull: ≥+2% slope in 7d, bear: ≤-2%, sideways: |slope|<0.02 + low volatility <0.015 ATR). Hysteresis prevents jitter. No look-ahead bias.
- ML Pipeline: XGBoost for bear regime (daily data, 3-day horizon classification/regression). Optuna tuning (60 trials, walk-forward CV). TFT for hourly data (sequence modeling with covariates).
- Backtesting: VectorBT with realistic fees/slippage, held-out test period (2024–2025). Thresholded signals with volatility gating.
- Scope: ETH-USD only; extensible to other assets via configs.
Show Roadmap
- Promote hourly TFT training (≥50k samples, GPU compute).
- Expand to multiple assets via configs and Makefile guards.
- Add reporting: per-phase equity curves, turnover analysis, drift monitoring.
Pull requests welcome!
MIT