POSITION
FLAT
NAV
·
WIN% · 0
·
ROLL ΔNAV · 0
·
L:S · 0
·
AVG HOLD · 0
·
IN-MKT% · 30m
0%
TEMP
·
TRAIN STEP
·
TICKS
·
MODE
PAPER · LIVE DATA
AI/ML Bootcamp Capstone, Cohort 2510-FTB-CT-AIM-PT

Online Alternative-data Reinforcement Learning on Bitcoin Perpetuals

An online reinforcement learning agent that trains itself in real time on live market data. It ingests seventeen streams of alternative data across five exchanges for BTC, learns to trade perpetual futures, and gets better while we watch it. Running right now on this machine.

Andrew VanDyke, Instructor Dr. George Perdrizet, TA Andrew Thomas
Background

What is a BTC perpetual future?

going long

You buy a contract that tracks the price of Bitcoin. If the price goes up, you profit. If it goes down, you lose. You can close the position at any time to lock in your gain or cut your loss. No expiration date, no physical delivery, just a bet on direction with leverage.

going short

You sell a contract you do not own. If the price goes down, you profit (you sold high, you buy back low). If the price goes up, you lose. This is how you bet on a price decline without owning any Bitcoin at all.

  • perpetual means the contract never expires, unlike traditional futures which settle on a fixed date
  • funding rate is a periodic payment between longs and shorts that keeps the contract price close to the spot price
  • the system trades BTC-USDT perpetuals on Bitunix, a crypto derivatives exchange, using paper mode (simulated fills, no real capital at risk)
218 input dimensions from 17 feature blocks

The feature blocks

Each block polls its own data source on its own cadence, spanning two orders of magnitude from 200 milliseconds down to once every 30 seconds. The feature ring buffer handles the cadence mismatch so that on every tick, the runner pulls the latest cached value from each block regardless of when that block last refreshed. Any block showing all zeros is still warming up its z-score normalization window, which can take anywhere from a few minutes to several hours depending on its polling cadence.

L2 microstructure (refined)
20 dims · 200 ms · Bitunix WS (local orderbook)
Order flow imbalance, microprice, weighted mid, depth imbalance, realized vol, and trade imbalance. The highest-frequency block in the system and the only one computed on-demand every tick rather than on a background thread.
Bitget derivatives
14 dims · 10 s · Bitget API
Funding rate and z-score, OI delta, OI-price divergence, top-trader and global L/S ratios at 5m and 1h (with divergence signal), resting liquidity balance, actual taker flow imbalance from recent trades, taker intensity, funding settlement countdown, and annualized funding.
Cross-exchange premium
3 dims · 5 s · Bitget + Bitunix
Spread between Bitget mid and Bitunix mid, external mid 1-tick return, and spread z-score. Arbitrage pressure proxy, since large cross-venue premiums often precede directional moves.
Hyperliquid derivatives
10 dims · 10 s · Hyperliquid API
Funding rate, OI, mark-oracle premium, CEX funding spread, 24h volume, impact spread, daily return from the largest on-chain perp DEX. Plus ETH-BTC and SOL-BTC funding divergence and cross-asset funding dispersion across the top 10 markets by OI.
Coinalyze aggregated
5 dims · 10 s · Coinalyze
Liquidation intensity, cross-venue OI change, long/short liquidation ratio, plus cross-exchange aggregated funding rate and its z-score. Cascade detection and market-wide funding consensus.
Deribit options
9 dims · 10 s · Deribit
ATM IV, put/call skew, term structure slope, Deribit funding, DVOL (BTC volatility index) with hourly change, put/call OI ratio, OI concentration at top strikes, and options volume put/call flow. What the options market thinks and where it is positioned.
Stablecoin supply
3 dims · 10 s · DeFiLlama
USDT supply change, total stablecoin supply change, and USDC supply change. USDC tracks institutional flows (Circle/Coinbase), USDT tracks retail/offshore. Both are dry powder proxies.
Polymarket sentiment
2 dims · 30 s · Polymarket Gamma API
BTC-related prediction market odds and market volume. Crowd-sourced sentiment from people putting actual money on forward outcomes rather than on the current price.
Social sentiment
88 dims · 2 s · Bluesky, StockTwits, 4chan, FGI
88-dimensional rolling sentiment vector built from four live social streams. Tier-1 NLP (VADER, crypto lexicon, NRC emotions, linguistic features) processes every post in microseconds. Rolling EMA aggregates at 30s, 5m, 15m windows track volume, sentiment, engagement, per-source divergence, emotion, and novelty. The engine runs as a separate process communicating via shared memory at 5 Hz.
Orderbook dynamics
8 dims · 200 ms · Bitunix WS (local orderbook)
Book imbalance deltas at 1s and 5s, bid/ask cancellation rates, spread volatility, depth replenishment speed, microprice, and microprice-vs-mid deviation. Deeper L2 features computed from the same orderbook as the L2 block.
Trade microstructure
12 dims · 200 ms · Bitunix WS (trade stream)
VWAP deviation at 1s and 5s, aggressor buy/sell volume, volume imbalance at 1s and 5s, trade intensity, large trade detection and imbalance, inter-trade arrival clustering, Kyle's lambda (price impact estimator), and tick direction run length.
Volatility microstructure
4 dims · 200 ms · Derived + Deribit
Ultra-short realized volatility at 10s and 60s windows, volatility-of-volatility (regime change detector), and the IV-RV spread (Deribit implied vol minus realized vol — the variance risk premium).
Cross-venue microstructure
20 dims · 1 s · Kraken + Coinbase + Alpaca + Bitget + Bitunix
Price spreads across 5 exchanges, combined bid/ask depth, global liquidity imbalance, best-price dispersion, per-venue buy pressure, volume concentration (HHI), and price discovery lead-lag signals. Kraken and Coinbase via WebSocket, Bitget via REST, Alpaca via WebSocket with L2 orderbook.
Funding microstructure
5 dims · 10 s · Bitget + Hyperliquid + dYdX
Cross-venue funding rate spread, funding velocity over 60s, mean funding across venues, time to next funding settlement, and mark-index premium in basis points. Captures positioning consensus and arbitrage pressure across CEX and DEX venues.
Liquidation flow
5 dims · 30 s · Coinalyze
Cross-exchange aggregated long and short liquidation volumes, liquidation imbalance, cascade detection flag (volume spike > 3x rolling mean), and liquidation intensity ratio. Cascade detection is particularly valuable — cascading liquidations are self-reinforcing.
ETH/alt correlation
4 dims · 2 s · Kraken REST
ETH-BTC and SOL-BTC 5-second return spreads (divergence is mean-reverting), ETH 1-second lead signal (ETH often leads BTC by 1-3 seconds in crypto-specific moves), and cross-alt volume ratio relative to rolling mean.
On-chain metrics
6 dims · 10 s · mempool.space
Bitcoin mempool size, fastest fee rate, transaction count momentum, seconds since last block, fee spread (urgency dispersion), and mempool congestion z-score. Connects on-chain activity to derivatives pricing — mempool congestion often correlates with volatility.
Per-scalar freshness and current values

Feature health

One row per scalar across every feature block feeding the state vector. The block health light (first column) reflects the poll thread's last successful fetch; the scalarhealth light (next to each feature name) reflects the time since that specific scalar's value last changed — a scalar that sits frozen past 2× its expected period turns red even if the block itself is still being polled. Δ% compares the current value against the value immediately prior to its most recent change, so flat scalars don't show a misleading 0.0%.

1Hz snapshot writerno writes yetlast ok: ·lines written: ·dir: ·
filter0 / 0 scalars shown
blockblockblock agetarget#ffeatureagevalueΔ%
no scalars match this filter
The demo

Live x-ray

Every node below is streaming from the running system. Click any node to open a detail panel with architecture, live values, and the full latent or feature vector. Scroll to zoom, drag to pan.

Every fill, as it happens

Live trade tape

Fills from the runner, streamed live. The NAV columns form a continuous ladder — each open's NAV @ entry equals the prior close's NAV @ exit. ΔNAV is thecumulative_pnldelta between consecutive closes (restart-immune), so the column sums to the account's trade-to-trade realized PnL net of real fees, slippage, and funding. Hold is the time the position was open.

timemodesidepriceqtyholdNAV @ entryNAV @ exitΔ NAV
waiting for first fill...
Live candles with trade overlay

BTC price and trades

BTC/USDT candles with historical backfill from Bitget plus live ticks from the orderbook feed. Toggle Candle / Linear (a mid-price line); in Linear mode the Bid / Ask overlays draw the live best bid/ask. Scroll to zoom, drag to pan. Entry arrows use the tape's open colours (light blue L / light purple S); exit arrows are green/red by round-trip ΔNAV. Each round trip also draws a price-level segment from its entry price to its exit price, and the current open position shows a dashed entry line.

mode
State vector breakdown

System overview

  • 116 dims from 16 live feature blocks (normalized z-scores; slow blocks carry an explicit age dim), each on its own cadence contract
  • 64 dims from a book CNN encoder consuming the L2 order book directly
  • 64 dims from a GRU temporal encoder consuming a rolling 60-tick window (plus 64 each from the full-state MLP and cross-block attention encoders)

The four 64-dim encoder latents feed a standard continuous SAC head with a 1-dimensional action in the range minus one to one. The raw action is accumulated into a temperature integrator with hysteresis thresholds so the policy cannot churn.

The integrated temperature is what decides whether we open long, exit long, open short, or cover short. The live x-ray further down shows all of this flowing in real time.

Streaming from the training loop

Live training

Critic loss, actor loss, alpha loss, and the current entropy temperature from the learner process — averaged per second over the entire training history. If you are watching this live, you can see the SAC temperature and losses move in real time as the policy trains.

waiting for training events...

1-second means over the full training history — scroll to zoom (all the way out to the whole run), drag to pan. Actor loss reads on the LEFT scale; critic/alpha on the right. Hover for elapsed training time and gradient step.

Why the encoders learn anything

Auxiliary forward-return prediction

📊
step 1
buffer aged samples

wait for replay samples to age at least 240 seconds so we know what the price actually did at 1, 2, and 4 minutes into the future

🧠
step 2
predict forward returns

each encoder independently predicts the log-return at 60s, 120s, and 240s horizons from its latent representation

📉
step 3
MSE gradient update

supervised loss trains the encoder to produce latents that explain price movement, independent of the RL policy gradient

This solves the cold-start problem. The RL policy has sparse reward, so without auxiliary supervision the encoder latents would be random noise for hours. By the time the SAC head is ready to exploit those representations, they already contain forward-looking signal.

What a few hours of live training tells us

Honest findings

What is working:

  • everything is wired up, gradients flowing, encoders learning
  • the agent is actively taking positions without blowing through risk limits
  • alpha (SAC entropy temperature) is decaying on schedule, meaning the agent is gradually trusting its policy over random exploration
  • critic loss is stable rather than diverging
  • the hold-triangle reward is visibly pushing the policy toward trade durations long enough to clear simulated costs

What I am explicitly not claiming:

  • that this agent is profitable
  • that the signal generalizes beyond BTC
  • that the feature selection is optimal
  • that transaction cost modeling is accurate beyond the 4 basis points baked into the reward
  • that a few hours of live data lets me distinguish alpha from noise
Where this goes

What is next

  • graduate out of burn-in: need rolling 200-trade Sharpe to clear 0.5 on paper, which is a few days of training away if the system is going to work at all
  • touch real capital: the calibrated phase starts at $3 positions, which is where the transaction cost modeling actually has to be right
  • feature ablations: figure out which of the seventeen blocks are actually doing work, which is the thing I was not able to answer during the capstone window
  • extend to a small basket: carry the same stack to a few more symbols once the single-symbol case holds up
  • learned risk gate: replace the hand-tuned temperature integrator so the policy decides its own trade cadence instead of inheriting mine
  • position sizing: add an appendix on Kelly criterion and volatility targeting, which is out of scope for this research talk