Trading System

August – September 2025

An algorithmic trading platform built to learn quantitative finance and push my engineering skills into new territory - real-time systems, ML pipelines, and code that touches real money.

  • Hybrid Architecture - Go for real-time execution, Python for ML via gRPC
  • Signal Generation - TCN and LSTM models with 50+ engineered features
  • Risk Management - Kelly criterion sizing, circuit breakers, regime-aware position adjustment
  • Data Pipeline - Alpaca WebSocket streams into TimescaleDB hypertables
Trading System Architecture
Hybrid Go/Python architecture - real-time execution separated from ML intelligence via gRPC

The Split

Go handles everything real-time and safety-critical: ingesting market data via WebSocket, managing positions, enforcing risk limits, executing orders. Python handles the intelligence: feature engineering, model inference, regime classification. They communicate over gRPC - Go sends OHLCV bars, Python returns signals with confidence scores and price targets.

The split is deliberate. Go’s type safety and performance make it the right choice for code that can lose money if it misbehaves. Python’s ecosystem (TensorFlow, scikit-learn, TA-Lib) makes it the right choice for ML experimentation. gRPC latency is 2-15ms, acceptable for minute-bar trading.

Signal Generation

ML Pipeline
Feature engineering through model inference to trading signals

The ML pipeline starts with 50+ engineered features: technical indicators (RSI, MACD, Bollinger), volatility measures (ATR, Garman-Klass), volume analysis (OBV, VWAP, CMF), and market microstructure features (order imbalance, trade intensity).

Two models work together:

TCN (Temporal Convolutional Network) - Dual-head architecture outputting both classification (support/resistance/neutral) and price targets. Trained with focal loss to handle class imbalance and Huber loss for robust price regression.

LSTM Regime Classifier - Classifies market conditions as trending, ranging, or volatile. Strategies adapt based on regime - wider stops in volatile markets, tighter in trending. This alone improved Sharpe ratio by 30% and reduced max drawdown by 57% in backtests.

Level detection identifies support and resistance zones through swing point analysis. When predicted levels align with historical zones, confidence gets boosted.

Risk Management

Risk Management
Kelly criterion position sizing with circuit breakers and dynamic adjustments

Position sizing uses the Kelly criterion - mathematically optimal bet sizing based on win rate and risk/reward ratio. Applied at 50% (half-Kelly) because full Kelly is too aggressive for real trading.

Confidence scores from the ML models map to maximum risk percentages: 85%+ confidence allows 2% risk, 75-85% allows 1.5%, 60-75% allows 0.75%, below 60% means no trade.

Circuit breakers provide hard stops: -2% daily, -5% weekly, -15% monthly. If any threshold is hit, trading halts automatically.

Dynamic adjustments layer on top: regime multipliers (0.8x in volatile markets, 1.4x in trending), volatility scaling, and portfolio heat limits that prevent over-concentration in correlated positions.

Volume Validation

One of the more effective filters. Before entering any trade, the system checks that breakout volume is 50-100% above the 20-day moving average. This single check filters out 30-40% of would-be losing trades - news spikes and false breakouts that look good on price action alone.

Under the Hood

  • Go Platform: Ingestor (WebSocket streams), Traderd (trading daemon), position sizer, risk manager, order execution
  • Python ML: Feature engine (12 modules, 4500+ lines), TCN classifier, LSTM regime, level detection, backtester
  • Data: TimescaleDB hypertables for OHLCV, Redis for feature caching
  • Training: Walk-forward validation, focal loss for imbalanced classes, hyperparameter optimization

Stack: Go, Python, gRPC, TensorFlow, TimescaleDB, Redis, Alpaca API

Currently paper trading while refining strategies. The goal isn’t to get rich - it’s to build something non-trivial where mistakes have consequences.