Developer Console
Sign in to manage API keys.

Long-short portfolio on Hyperliquid from prediction market prices

An autonomous agent queries PolyBridge at price thresholds, reconstructs market-implied distributions, and sizes a long-short book for Hyperliquid 1x perps.

Published
May 31, 2026
Read time
4 min
Stack
Python · MCP

Every direction and position size comes from prediction market prices. The agent asks four threshold questions per asset, turns the survival probabilities into a coarse price distribution, then sizes the resulting expected returns with half-Kelly.

Before you begin

Install PolyBridge MCP for Claude Desktop from the MCP release.

Verify by asking Claude: Use PolyBridge Forecast: Will BTC exceed $70,000 on July 31, 2026?

You should see a probability, confidence range, and source-market metadata.

Prompt

Ask for threshold prices, not a directional view

The prompt asks the agent to collect all 20 Forecast probabilities first, then execute the sizing script.

promptclaude-prompt.txt
You have access to the PolyBridge MCP tool (polybridge_forecast).

Assets and spot prices:
BTC $74,000 · SPX $7,580 · OP $0.12 · BERA $0.38 · WTI $87

For each asset, query PolyBridge Forecast at four price thresholds
(0.60×, 0.85×, 1.15×, 1.50× spot), all resolving July 31, 2026.

Round thresholds: to nearest $100 if spot ≥ $1,000; to nearest $1
if spot ≥ $10; to nearest $0.01 otherwise.

Question format: "Will {ASSET} exceed ${T} on July 31, 2026?"

Collect all 20 probabilities first. Then write and execute a Python
script that:

1. Enforces monotonicity (clip so P(> Tᵢ₊₁) ≤ P(> Tᵢ)).

2. Reconstructs a piecewise price distribution per asset:
   Below T₁:             prob = 1 − P(> T₁),            midpoint = T₁ / 2
   Between Tᵢ and Tᵢ₊₁:  prob = P(> Tᵢ) − P(> Tᵢ₊₁),   midpoint = (Tᵢ + Tᵢ₊₁) / 2
   Above T₄:             prob = P(> T₄),                midpoint = (T₄ + 1.5 × T₄) / 2

3. Computes per asset:
   E[price]  = Σ midpoint × prob
   E[return] = (E[price] − spot) / spot
   Vol       = √(Σ midpoint² × prob − E[price]²) / spot

4. Sizes via half-Kelly:
   weight   = 0.5 × E[return] / Vol²
   notional = weight × $50,000

   Constraints:
   Gross notional ≤ $50,000
   No single position > $20,000 (40%)
   Scale all positions proportionally if gross exceeds budget
   Round to nearest $100
   Direction = sign of E[return]

Output:
1. Survival probability table per asset
2. Expected returns, implied vols, and sized position table
3. Hyperliquid 1× perp order instructions as JSON
Workflow

What the agent does

The four threshold factors place two thresholds below and two above the current price for each asset.

four price-threshold Forecast questions per asset
BTC, SPX, OP, BERA, and WTI
July 31, 2026 horizon
0.60x, 0.85x, 1.15x, and 1.50x spot thresholds
20 Forecast calls total
Monotonic survival probabilities
Piecewise price distribution
Expected return and implied volatility
Half-Kelly sizing
$50,000 gross budget with a $20,000 / 40% max single position
AssetSpot0.60x0.85x1.15x1.50x
BTC$74,000$44,400$62,900$85,100$111,000
SPX$7,580$4,500$6,400$8,700$11,400
OP$0.12$0.07$0.10$0.14$0.18
BERA$0.38$0.23$0.32$0.44$0.57
WTI$87$52$74$100$131
The article shows the BTC survival curve as the worked example. Running the cookbook generates complete live survival curves for all five assets.
Example

Snapshot output

This public article uses the May 31 snapshot. Results change with live probabilities.

Snapshot 2026-05-31. Results change with live probabilities.

Asset  Dir     E[r]     Vol    Notional
──────────────────────────────────────────
BTC    LONG   +6.40%  33.70%    $8,600
SPX    LONG   +7.86%  23.30%   $12,200
OP     SHORT  -6.00%  31.90%    $9,000
BERA   SHORT -11.05%  30.00%   $12,200
WTI    LONG   +2.78%  23.00%    $8,000

Gross: $50,000 / $50,000
Sizing

How half-Kelly turns distributions into notionals

Each survival probability P(price > T) is a point on the asset's implied cumulative distribution. Four points define five probability bands. Expected price is the probability-weighted sum of band midpoints; comparing expected price to spot gives expected return. Half-Kelly converts expected return and implied volatility into a position weight.

BTC spot: $74,000
ThresholdP(BTC > T)
$44,40096%
$62,90078%
$85,10030%
$111,0008%
  • P(BTC between $62.9K and $85.1K) = 0.78 - 0.30 = 0.48
  • midpoint = $74,000
  • lower tail below $44.4K has probability 0.04 and midpoint $22,200
  • upper tail above $111K has probability 0.08 and midpoint $138,750
  • E[price] = $78,736
  • E[return] = +6.40%
  • Vol = 33.7%
  • Half-Kelly weight = 0.5 x 0.0640 / 0.337^2 = 0.282
  • Raw notional = $14,100 LONG
  • After caps and proportional scaling, BTC final notional = $8,600
Portfolio

Sized long-short book

The final gross notional is $50,000, with no single position above $20,000 or 40% of the book.

AssetDirE[r]VolNotional
BTCLONG+6.40%33.70%$8,600
SPXLONG+7.86%23.30%$12,200
OPSHORT-6.00%31.90%$9,000
BERASHORT-11.05%30.00%$12,200
WTILONG+2.78%23.00%$8,000
Gross: $50,000 / $50,000
Orders

Hyperliquid order instructions JSON

The generated JSON is notional-only by design; routing code should verify instruments, margin, and exchange constraints before placing real orders.

{
  "generated_at": "2026-05-31T14:00:00Z",
  "horizon": "July 31, 2026",
  "venue": "Hyperliquid",
  "instrument": "1x_perp",
  "orders": [
    {
      "asset": "BTC",
      "direction": "LONG",
      "notional_usd": 8600
    },
    {
      "asset": "SPX",
      "direction": "LONG",
      "notional_usd": 12200
    },
    {
      "asset": "OP",
      "direction": "SHORT",
      "notional_usd": 9000
    },
    {
      "asset": "BERA",
      "direction": "SHORT",
      "notional_usd": 12200
    },
    {
      "asset": "WTI",
      "direction": "LONG",
      "notional_usd": 8000
    }
  ]
}
Limits

What this example does not solve

  • Assets are sized independently; no correlation model.
  • Upper-tail ceiling is arbitrary: above T4 midpoint uses 1.5 x T4.
  • Prediction market prices are risk-neutral-ish and may include liquidity/risk premia.
  • Four thresholds create a coarse distribution, not a full option surface.
  • If raw survival probabilities are non-monotonic or based on weak proxy markets, monotonicity clipping makes the math coherent but does not make the signal reliable.
  • Hyperliquid instruments must exist and be checked before routing real orders.
  • Informational example only. Not financial advice.
Run the workflow

Run the threshold workflow.

Connect Hosted MCP or open the Colab notebook and run all cells.

Read the MCP docs →