Documentation Index
Fetch the complete documentation index at: https://mathematicalcompany.mintlify.app/llms.txt
Use this file to discover all available pages before exploring further.
Scan for parity violations where the YES and NO contracts on the same market sum to less than $1.00, creating risk-free profit opportunities.
Full Code
"""Parity arbitrage: buy YES + NO when combined cost < $1.00."""
import horizon as hz
from horizon.context import FeedData
def check_parity(ctx: hz.Context) -> float:
"""Compute the fair value from book feed."""
book = ctx.feeds.get("polymarket", FeedData())
return book.price if book.price > 0 else 0.50
# Pipeline scanner detects and auto-executes parity arb
scanner = hz.parity_arb_scanner(
market_id="election-winner",
feed_name="polymarket",
min_edge=0.005, # minimum 0.5 cent edge
auto_execute=True, # submit orders automatically
cooldown=5.0, # seconds between executions
)
hz.run(
name="parity_arb",
markets=["election-winner"],
feeds={
"polymarket": hz.PolymarketBook("election-winner"),
},
pipeline=[check_parity, scanner],
risk=hz.Risk(max_position=200, max_drawdown_pct=2),
interval=0.5,
mode="paper",
)
How It Works
PolymarketBook streams live bid/ask for both YES and NO sides
parity_arb_scanner() checks if best_ask_yes + best_ask_no < 1.00
- When a violation is found, it buys both sides to lock in the difference
auto_execute=True submits the orders immediately; set to False for alerts only
One-Shot Sweep
For a quick check without a live loop, use parity_arb_sweep():
"""One-shot parity check on a running engine."""
import horizon as hz
engine = hz.Engine()
engine.start_feed("polymarket", "polymarket_book", config_json='{"condition_id": "election-winner"}')
result = hz.parity_arb_sweep(engine, market_id="election-winner", feed_name="polymarket")
if result:
print(f"Parity violation: YES ask={result.yes_ask:.4f}, NO ask={result.no_ask:.4f}")
print(f"Combined cost: ${result.yes_ask + result.no_ask:.4f}")
print(f"Edge: ${result.edge:.4f} per pair")
else:
print("No parity violation found")
Run It
python examples/parity_arb_scanner.py
Dual Scanner
Combine parity scanning with cross-exchange arb for maximum coverage:
scanner = hz.composite_arb(
methods=[
hz.ArbMethodConfig(method="parity", market_id="election-winner", feed_name="polymarket"),
hz.ArbMethodConfig(
method="cross_exchange",
market_id="election-winner",
exchanges=["polymarket", "kalshi"],
feed_map={"polymarket": "polymarket", "kalshi": "kalshi"},
),
],
min_edge=0.005,
auto_execute=True,
)
See Parity Arbitrage for the full method reference.