DEV Community

FatherSon
FatherSon

Posted on

Statistical Arbitrage Between Polymarket and Kalshi: Cointegration, Order Book Imbalance & Open 55GB Dataset

Retail traders bet on who wins.

Quantitative hedge funds bet on price discrepancies between platforms.

When the same real-world event is traded on both Polymarket and Kalshi, temporary liquidity imbalances create deterministic, mean-reverting price gaps. Sophisticated desks exploit these gaps with statistical models — completely agnostic to the underlying event.

A public repository and a 55GB L2 order book dataset (tick-by-tick snapshots at 100ms intervals, 850+ million state updates in Parquet format) have been released to make this research accessible.

Here’s exactly how the math works and how to get started.

The Core Idea

When two platforms offer contracts on the exact same outcome, their prices must converge to the same terminal value ($1 or $0) at resolution. Local shocks (whales, liquidity differences, API latency) cause temporary divergence.

Quants model the spread between platforms and trade the mean-reversion while staying delta-neutral.

Method 1: Cointegration + Ornstein-Uhlenbeck Mean Reversion

Step 1: Test for Cointegration

Let ( P_{P,t} ) = mid-price on Polymarket and ( P_{K,t} ) = mid-price on Kalshi at time ( t ).

Construct the spread:
[
S_t = P_{P,t} - \beta P_{K,t} - \mu
]

Run the Augmented Dickey-Fuller (ADF) or Johansen test on historical data to confirm ( S_t ) is stationary (I(0)) and mean-reverting.

Step 2: Model the Spread with Ornstein-Uhlenbeck Process

[
dS_t = \theta (\mu - S_t) \, dt + \sigma \, dW_t
]

Where:

  • ( \theta ): speed of mean reversion
  • ( \mu ): long-term mean
  • ( \sigma ): volatility of the spread
  • ( dW_t ): Brownian motion

Step 3: Calibrate Parameters (MLE)

Discretize and estimate ( \theta ) via Maximum Likelihood Estimation on the Parquet dataset. The mean-reversion time ( \tau = 1/\theta ) tells you how quickly gaps close.

If reversion is faster than execution latency + fees, the pair is tradable.

Step 4: Optimal Entry & Exit

Solve an optimal stopping problem to find thresholds ( x_{open} ) and ( x_{close} ) that maximize expected profit after transaction costs and slippage.

Method 2: Order Book Imbalance (OBI) + Micro-Price (High-Frequency)

At millisecond horizons, cointegration is too slow. Quants use Level 1 Order Book Imbalance:

[
I_t = \frac{V_b(t) - V_a(t)}{V_b(t) + V_a(t)} \quad I_t \in [-1, 1]
]

Where ( V_b ) and ( V_a ) are volumes at the best bid and ask.

Micro-Price Calculation

The “true” instantaneous price before the next trade:

[
P_{micro}(t) = \frac{V_b(t) \cdot P_a(t) + V_a(t) \cdot P_b(t)}{V_b(t) + V_a(t)}
]

This simplifies to:

[
P_{micro}(t) = P_{mid}(t) + I_t \cdot \frac{\Delta spread}{2}
]

Cross-Venue Predictive Power

Because Polymarket (hybrid on-chain) and Kalshi (centralized) have different order processing speeds, an imbalance on one platform can predict price movement on the other within ~200ms.

Quants build Markov chain transition matrices on historical L2 data to calculate the probability that a strong imbalance (( I > 0.8 )) on Platform A leads to a book clearing on Platform B.

When probability exceeds a threshold, they cross the spread on the lagging venue.

Why This Beats Retail Trading

  • Process over prediction: No need to forecast elections or economic data.
  • Delta-neutral: Positions are hedged across platforms.
  • Mathematical edge: Exploits measurable liquidity and latency differences.
  • Repeatable: Small edges compounded at high frequency.

The same infrastructure used by systematic desks is now public.

Getting Started with the Dataset

Requirements:

  • Python 3.10+
  • ~60GB free SSD space

Quick setup (from the released repo):

  1. Install uv (fast dependency manager)
  2. Clone the repository
  3. Create environment and install dependencies (polars, scikit-learn, statsmodels, etc.)
  4. Download and decompress the 39GB orderbooks_l2.tar.zst file
  5. Verify the daily Parquet files (split by market category)

You now have institutional-grade L2 data for backtesting cointegration, OU models, and order book imbalance strategies.

Key Takeaways for Builders

  • Focus on the spread between venues rather than single-platform direction.
  • Combine statistical models (cointegration/OU) with microstructure signals (OBI + micro-price).
  • Latency and execution quality are part of the edge.
  • Start with the open dataset to validate signals before going live.

This is how professional desks extract consistent alpha from prediction markets without needing superior forecasts — just superior process and mathematics.

The repository and full 55GB dataset are available for anyone serious about building these strategies.

If you have more questions, please feel free to contact me at any time: https://t.me/FatherSon97

Polymarket #Kalshi #StatisticalArbitrage #PredictionMarkets #OrderBook #QuantitativeTrading #Cointegration #OrnsteinUhlenbeck #MarketMicrostructure #DeFi #CryptoTrading #Backtesting

Top comments (0)