Reversion — Polymarket Signal & Risk System

Inspiration

I kept noticing something odd on Polymarket. When news breaks about a court case or a political event, the market price swings hard — often too hard. A market pricing Harvey Weinstein's prison sentence would drop 20% in a day, then slowly creep back up over the next week. It felt like the crowd was overreacting, then correcting itself.

That's a classic pattern in quantitative finance — mean reversion. Prices that deviate sharply from their recent baseline tend to revert. It works in stocks. It works in commodities. The question was: does it work in prediction markets?

I decided to find out systematically. Not by eyeballing a few markets, but by backtesting across 30 markets, running hundreds of simulated trades, and measuring the edge precisely. The answer came back clearly: yes, with a 54–61% win rate on the best markets and a mean reversion average PnL of $822 vs momentum's -$253.

That's what built this system.


What it does

Reversion is a 7-layer quantitative signal generation and portfolio management system for Polymarket prediction markets.

It scans 50 live markets, identifies mean reversion opportunities, validates them from multiple independent angles, and outputs ranked trade recommendations with mathematically optimal position sizes.

The full pipeline:

  1. Signal Detection — identifies markets where price moved beyond an adaptive volatility threshold in the last 3 days
  2. Data Split — separates training history from signal window with a gap buffer to prevent data leakage
  3. Walk-Forward Backtest — simulates the strategy on historical data with realistic 3-day hold periods and mark-to-market equity tracking
  4. Kelly Criterion — computes optimal position size from historical win probability and payoff ratio
  5. Orderbook Depth — reads live bid/ask imbalance to check if smart money agrees with the signal
  6. AI + News Filter — fetches real headlines via Google News RSS and asks LLaMA 3.1 whether the price move is news-justified
  7. Portfolio Allocator — ranks signals by confidence score and allocates capital with position limits and event group concentration caps

Live output on March 24, 2026:

  • 50 markets scanned
  • 2 signals detected
  • BitBoy Convicted: BUY YES signal, -18% price drop over 3 days, 52.8% historical win rate, $1,750 allocated (Kelly-sized)

Backtest results across 30 markets:

Market Trades Win Rate PnL
Weinstein 10-20yr 207 54.1% +$9,066
Weinstein 20-30yr 205 55.6% +$5,502
BitBoy Convicted 197 52.3% +$4,055
Weinstein 30yr+ 73 60.3% +$1,399
Trump out as President 49 61.2% +$375

How we built it

Data layer — entirely on public Polymarket APIs, no paid feeds:

  • Gamma API for market metadata and prices
  • CLOB API for price history and live orderbook
  • Google News RSS for real-time headlines

Signal detection — the key insight was adaptive thresholds. A fixed 2% threshold for every market is wrong because different markets have different natural volatility. A crypto price market moves more than a political market. So each market gets its own threshold:

$$\text{threshold} = \sigma_{\Delta p} \times 1.5$$

$$\text{threshold} \in [0.01,\ 0.08]$$

where $\sigma_{\Delta p}$ is the standard deviation of daily price changes on that market's historical data.

Data split — to prevent leakage, history is split into three non-overlapping regions:

[.... TRAINING (n-7) ....] [GAP (3)] [SIGNAL (4)]

Training data computes volatility, runs the backtest, and calculates Kelly. The signal window only detects the current price move. The gap buffer ensures the boundary point is never shared.

Walk-forward backtest — positions are tracked as open with capital locked in. The equity curve tracks true portfolio value at every timestep:

$$\text{equity}(t) = \text{cash}(t) + \sum_{\text{open}} \text{size}i \cdot \frac{p{\text{current}}}{p_{\text{entry},i}}$$

This means the equity curve never artificially drops when capital is deployed — it reflects real portfolio value.

Kelly Criterion — position sizing uses the full Kelly formula:

$$f^* = \frac{p \cdot b - (1-p)}{b}, \quad b = \frac{\bar{w}}{\bar{l}}$$

Capped at 25% (half-Kelly) as a safety margin against estimation error in win probability.

Confidence scoring — built from independent factors only to avoid double counting:

  • Win probability (0–40 pts) — primary signal quality
  • Signal magnitude vs threshold (0–15 pts)
  • Orderbook confirmation (0–25 pts) — fully independent data source
  • Max drawdown penalty
  • Time to resolution (0–10 pts)
  • Volume proxy (0–10 pts)
  • AI modifier, optional (±10 pts)

AI layer — deliberately optional. If Groq fails, the system scores and ranks signals using quant factors alone. The AI adds or subtracts confidence points as a modifier but is never in the critical path.


Challenges we ran into

Data leakage at the boundary The first version computed volatility on history[:-4] then used history[-4] as the start of the signal window. These are adjacent — the boundary point is shared. Fixed by adding a 3-point gap buffer so training and signal windows never touch.

Portfolio curve tracking free cash instead of total equity When positions were open, cash dropped because capital was locked in. The equity curve looked like the strategy was losing money mid-trade. Fixed by computing mark-to-market value of all open positions at every timestep and adding it to free cash.

API filtering ignored The Polymarket trades endpoint (data-api.polymarket.com/trades) returns global trades regardless of the asset_id parameter passed in. Attempted client-side filtering but the token IDs in the response didn't match the token IDs from the markets API. Dropped the whale tracker in favour of strengthening the orderbook and backtest layers instead.

Double counting in confidence score First version included win probability, Kelly fraction, and backtest PnL as separate inputs. All three are derived from the same underlying trade data. Removed Kelly and PnL from the score — win probability alone represents the backtest signal quality, with truly independent factors scored separately.

AI as a hard dependency Early versions crashed the pipeline if the Groq API call failed. Refactored with try/except so AI failure is caught gracefully and the signal continues scoring on quant factors alone.


Accomplishments that we're proud of

  • Built a complete quantitative pipeline from raw API data to portfolio recommendations in 48 hours with no external trading libraries
  • Achieved +$9,066 PnL on the best market across 207 trades — consistent, not a fluke
  • Mean reversion averaged +$822 across all 30 markets vs momentum's -$253 — a clear, measurable edge
  • Identified and fixed data leakage before submission — a subtle issue that most hackathon backtests skip entirely
  • Designed the AI layer as an optional modifier rather than a required dependency
  • Implemented true walk-forward simulation with mark-to-market equity tracking

What we learned

Prediction markets have real, exploitable inefficiencies. The 54–61% win rates on the best markets are not large, but they are consistent across hundreds of trades. In quant trading, consistency matters more than magnitude.

Data integrity matters more than model complexity. The most impactful improvements were not adding more layers — they were fixing data leakage and correcting the equity curve. A simple strategy with clean data beats a complex strategy with dirty data every time.

The Kelly Criterion is not just theory. Sizing positions at the mathematically optimal fraction based on actual historical win probability produces meaningfully better portfolio outcomes than fixed percentage sizing.

AI works best as a filter, not a foundation. Using LLaMA 3.1 to read news headlines and validate signals adds real value — but only when it sits on top of a solid quant layer. The quant edge should exist independently of the AI.

Conservative systems are better systems. A system that fires on 2 signals out of 50 markets and allocates only 17.5% of capital is not failing — it is being disciplined. The value is in what it says no to.


What's next for Reversion

Execution layer — connecting the Synthesis API (synthesis.trade) would turn signal recommendations into live orders on Polymarket and Kalshi. All inputs needed for execution are already in the output: market ID, direction, size, confidence score. Under 100 lines of additional code.

Cross-market arbitrage — Polymarket and Kalshi often list the same event at different prices. A unified API like Synthesis makes this a straightforward extension.

Expanded market coverage — currently scans 50 markets. The pipeline scales to hundreds with no architectural changes.

Live paper trading log — automatically logging every signal as a paper trade and tracking outcomes over time would build a real forward-tested track record to complement the backtest results.

Richer signals — adding social sentiment, resolution source credibility weighting, and correlated market baskets could improve signal quality beyond price history and orderbook depth alone.

Built With

Share this project:

Updates

Submission history