← Back

Quant RL

Prototype

Signature capability

Every trained policy has to pass a rolling walk-forward gate (60-day train / 30-day out-of-sample, 3 windows) where it must beat buy-and-hold Sharpe on all windows before it ships, backed by 280 test functions.

What it is

Quant RL is a custom RL trading library, forked from tensortrade-ng and rebuilt around a ports-and-adapters pipeline (domain/ports/adapters, regime-filtered trainer). It fetches Hyperliquid OHLCV plus L2 order-book features, builds a Gymnasium trading environment with pluggable reward schemes (risk-adjusted returns, position-based, simple profit), and trains a PPO agent via stable-baselines3 with VecNormalize. Trained policies are exported to ONNX so inference at trade time needs only onnxruntime, not the full SB3/torch stack. A walk-forward validator acts as the promotion gate: a policy is rejected unless it beats buy-and-hold Sharpe across all out-of-sample windows. It also carries an experimental "ant-swarm" regime finder that calls real quantum-RNG hardware for exploration diversity, falling back to CPU simulation.

Highlights

  • ~12,400 lines of Python across a clean, layered package (core, env, feed, training, inference, validation, pipeline) with a strict ports/adapters split
  • 280 test functions including hypothesis property-based tests; the walk-forward gate requires beating buy-and-hold Sharpe on all 3 out-of-sample windows before a policy is promoted
  • PPO trained with stable-baselines3 + VecNormalize, then exported to ONNX so live inference drops the SB3/torch dependency and runs on onnxruntime alone
  • Full data path built from scratch: Hyperliquid OHLCV adapter, L2 order-book feature merge with coverage gating, and idempotent SQLite (trading.db) OHLCV backfill
  • Deliberately dependency-light: dropped pandas_ta/numba in favor of pure pandas/numpy indicators to keep the build portable
  • Persisted obs-normalizer (mean/std as JSON) so the ONNX policy sees identically scaled inputs at inference

Tech · Python 3.11+, PyTorch, stable-baselines3, Gymnasium, ONNX/onnxruntime, NumPy, pandas, SQLite, pytest + Hypothesis