Major upgrade to the ML engine: - LSTM model type: 2-layer PyTorch LSTM with early stopping, GPU support - Hybrid mode: LSTM (60%) + XGBoost (40%) with agreement gating - StandardScaler normalization (critical for LSTM) - PCA dimensionality reduction (configurable variance retention) - ATR-based dynamic stop-loss/take-profit adapting to volatility - Rolling window retraining for more realistic time series validation - Updated LLM system prompt with docs for all new parameters - All backward compatible (xgboost/lightgbm/catboost still work) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
BTC ML Trading Strategy Optimizer
An automated optimization loop that trains ML models on BTC/USDT data, backtests trading strategies, and uses an LLM to iteratively improve the configuration.
Architecture
┌─────────────────────────────────────────────────────────────────┐
│ Optimization Loop │
│ │
│ ┌──────────┐ ┌───────────────┐ ┌──────────────────────┐ │
│ │ VPS │───>│ Windows PC │───>│ Mac Mini │ │
│ │ (Orch.) │<───│ (GPU/ML) │ │ (LLM) │ │
│ │ │<───────────────────────>│ │ │
│ │ - Fetch │ │ - XGBoost │ │ - Ollama │ │
│ │ data │ │ - LightGBM │ │ - qwen3.5:27b │ │
│ │ - Coord │ │ - CatBoost │ │ - Analyze results │ │
│ │ - Store │ │ - RTX 4070 Ti │ │ - Suggest changes │ │
│ └──────────┘ └───────────────┘ └──────────────────────┘ │
│ ▲ │ │
│ └────────────────────────────────────────┘ │
│ Modified config │
└─────────────────────────────────────────────────────────────────┘
Machines (Tailscale)
| Machine | Role | Address | Key Resources |
|---|---|---|---|
| VPS | Orchestrator | localhost | Coordination, data |
| Windows PC | ML Engine | 100.76.218.38 | RTX 4070 Ti GPU |
| Mac Mini | LLM | 100.100.242.21 | Ollama, qwen3.5:27b |
Directory Structure
btc-ml-optimizer/
├── orchestrator.py # Main loop — coordinates everything
├── ml_engine/
│ └── train_and_backtest.py # Self-contained ML script (runs on Windows)
├── llm_client/
│ └── analyzer.py # LLM strategy analyzer (calls Mac Mini)
├── scripts/
│ ├── fetch_data.py # BTC/USDT data fetcher (ccxt)
│ └── setup_windows.sh # Install deps on Windows PC
├── config/
│ └── initial_config.json # Starting configuration
├── data/ # OHLCV CSV files
├── results/ # Iteration results + logs
├── requirements_vps.txt # VPS Python dependencies
└── requirements_windows.txt # Windows PC Python dependencies
Setup
1. VPS (this machine)
pip install -r requirements_vps.txt
2. Windows PC
# From VPS — installs all ML deps on Windows via SSH
bash scripts/setup_windows.sh
Or manually on Windows:
pip install -r requirements_windows.txt
3. Mac Mini
Ensure Ollama is running with the qwen3.5:27b model:
ollama pull qwen3.5:27b
ollama serve # should already be running
Usage
Fetch Data
python3 scripts/fetch_data.py
Downloads 2 years of BTC/USDT 1h and 4h OHLCV data from Binance.
Run the Optimizer
python3 orchestrator.py
The optimizer will:
- Ensure data is fetched
- Upload ML engine + data to Windows PC
- Train model and backtest on GPU
- Send results to LLM for analysis
- Apply LLM-suggested config changes
- Repeat until convergence (or 50 iterations)
Run ML Engine Standalone (on Windows)
python train_and_backtest.py --config config.json --data btc_4h.csv --output results.json
Configuration Reference
model_type
xgboost— XGBoost with GPU (default, generally best)lightgbm— LightGBM with GPU (faster training)catboost— CatBoost with GPU (handles interactions well)ensemble— Soft voting of all three
features
technical_indicators— List of indicators to computelookback_periods— Windows for return/volatility featuresuse_volume_features— Include volume-derived featuresuse_volatility_features— Include volatility featuresuse_candle_patterns— Include candlestick pattern featuresuse_lag_features— Include lagged feature valueslag_periods— Specific lag periods to use
target
direction—"long"or"both"horizon_candles— Forward-looking prediction windowthreshold_pct— Minimum % move to label as positive
hyperparameters
Standard gradient boosting params: learning_rate, max_depth, n_estimators, subsample, colsample_bytree, min_child_weight, gamma, reg_alpha, reg_lambda
strategy
entry_threshold— Min probability to enter trade (0.5-0.8)stop_loss_pct— Stop loss percentagetake_profit_pct— Take profit percentagetrailing_stop_pct— Trailing stop distanceposition_sizing—"confidence_scaled"or"fixed"min_confidence_to_trade— Absolute minimum confidence
training
walk_forward_windows— Number of walk-forward splits (3-10)train_pct/validation_pct/test_pct— Data split ratios
Convergence Criteria
The optimizer stops when:
- Sharpe ratio exceeds 3.0
- Sharpe improvement < 1% over 5 consecutive iterations
- Maximum 50 iterations reached
Output
config/best_config.json— Best configuration foundresults/iterations.jsonl— Full log of every iterationresults/results_iter_N.json— Detailed results per iteration
Description
Bitcoin Accumulation Zone Monitor — On-chain metrics dashboard with historical backtesting for long-term BTC holders. Scores buying opportunities 0-100 using Puell Multiple, MVRV Z-Score, Fear & Greed, Reserve Risk, RHODL, NUPL, LTH Realized Price, 200W SMA, and more.
Languages
Python
99.4%
Shell
0.6%