Skip to main content
Ultra Feature. Requires an Ultra subscription. Get started at api.mathematicalcompany.com
Market-make “Will the Fed cut rates in 2026?” on Polymarket while hedging with TLT (iShares 20+ Year Treasury Bond ETF) on Alpaca. If rates are cut, bond prices rise, so the TLT position offsets losses on the prediction market side.

Full Code

How It Works

  1. Two exchanges: Polymarket for prediction market orders, Alpaca for stock hedge orders
  2. Two feeds: PolymarketBook streams Yes/No prices, AlpacaFeed streams TLT quotes
  3. stock_hedge() runs each cycle:
  • Computes the rolling hedge ratio between the prediction market and TLT
  • Tracks effectiveness, basis risk, and correlation
  • Flags rebalancing when the ratio drifts past the 5% threshold
  • With auto_rebalance=True, sends Alpaca orders to adjust the hedge
  1. my_strategy() quotes the prediction market around the live fair value

Pre-Trade Analysis

Before going live, check the hedge relationship:

Run It

Extending

Multi-Ticker Hedge

Hedge with multiple instruments instead of just one:

Signal-Driven Fair Value

Use a signal combiner instead of raw mid-price:

Cross-Exchange Hedge

Hedge a Kalshi position instead of Polymarket:
See Stock Market Hedging for the full API reference and Horizon + Alpaca for exchange setup.