---
title: "Oracle Edge Scanner"
description: "Multi-signal forecasting and edge detection across prediction markets."
icon: "crystal-ball"
---

<Info>**Ultra Feature** -- This requires an Ultra subscription. [Get started at horizon.mathematicalcompany.com](https://horizon.mathematicalcompany.com)</Info>

Use the Oracle module to forecast market outcomes with a 6-signal decomposition, scan for mispriced markets, and inject edge signals into a live trading pipeline.

## Full Code

```python
"""Oracle: forecast markets and scan for edge."""

import horizon as hz

engine = hz.Engine()
engine.start_feed("polymarket", "polymarket_book", config_json='{"condition_id": "election-winner"}')

# ── Forecast a single market ──
forecast = hz.forecast_market(
    engine,
    market_id="election-winner",
    feed_name="polymarket",
)

print("Market Forecast: election-winner")
print(f"  Fair value:       {forecast.fair_value:.4f}")
print(f"  Market price:     {forecast.market_price:.4f}")
print(f"  Edge:             {forecast.edge:.4f}")
print(f"  Confidence:       {forecast.confidence:.2f}")
print(f"  Direction:        {forecast.direction}")

print(f"\n  Signal Decomposition:")
for signal in forecast.signals:
    print(f"    {signal.name:20s} value={signal.value:+.4f} weight={signal.weight:.2f}")

# ── Scan for edges across markets ──
edges = hz.scan_edges(
    engine,
    market_ids=["election-winner", "btc-100k", "fed-rate-cut", "gop-senate"],
    feed_map={
        "election-winner": "polymarket",
        "btc-100k": "btc",
        "fed-rate-cut": "fed",
        "gop-senate": "gop_senate_feed",
    },
    min_edge_bps=300,   # only show edges > 300 bps (3 cents)
)

print(f"\nEdge Scanner ({len(edges)} opportunities):")
for opp in edges:
    print(f"  {opp.market_id}: edge={opp.edge_bps:.0f}bps direction={opp.direction} conf={opp.confidence:.2f}")

# ── Full oracle report ──
report = hz.oracle_report(engine, market_ids=["election-winner", "btc-100k"])

print(f"\nOracle Report:")
print(f"  Markets analyzed:   {report.markets_analyzed}")
print(f"  Edges found:        {report.edges_found}")
print(f"  Avg confidence:     {report.avg_confidence:.2f}")
print(f"  Coverage:           {report.coverage:.0%}")
```

## Pipeline Mode

Inject oracle edge forecasts into a live quoting strategy:

```python
"""Oracle pipeline: inject edge for downstream quoting."""

import horizon as hz
from horizon.context import FeedData

oracle_pipe = hz.oracle(
    config=hz.OracleConfig(
        feed_map={"election-winner": "polymarket"},
        scan_interval=30,      # re-forecast every 30 seconds
        min_edge_bps=200,
    ),
)


def quoter(ctx: hz.Context, fair: float) -> list[hz.Quote]:
    """Quote only when oracle detects edge."""
    oracle_edge = ctx.params.get("oracle_edge", 0.0)
    oracle_conf = ctx.params.get("oracle_confidence", 0.0)

    if abs(oracle_edge) < 0.02 or oracle_conf < 0.5:
        return []   # no edge or low confidence

    # Tighter spread when oracle is confident
    spread = 0.02 + (1.0 - oracle_conf) * 0.04
    size = hz.kelly_size(fair, fair - oracle_edge, 5000.0, 0.25, 30.0)

    return hz.quotes(fair, spread, size=max(1.0, size))


hz.run(
    name="oracle_trader",
    markets=["election-winner"],
    feeds={
        "polymarket": hz.PolymarketBook("election-winner"),
    },
    pipeline=[oracle_pipe, quoter],
    risk=hz.Risk(max_position=100, max_drawdown_pct=5),
    interval=2.0,
    mode="paper",
)
```

## How It Works

1. **`forecast_market()`** decomposes the forecast into 6 signals:
   - Price level, momentum, mean reversion, flow, microstructure, and sentiment
   - Each signal is weighted by the oracle's learned coefficients
   - The combined fair value is the weighted sum
2. **`scan_edges()`** applies `forecast_market()` across multiple markets and filters by minimum edge
3. **`oracle()`** pipeline function re-forecasts on a schedule and stores the edge in `ctx.params`
4. **`oracle_report()`** generates a coverage analysis showing which markets have signal and which lack data

## Run It

```bash
python examples/oracle_edge_scanner.py
```

See [Oracle](/oracle) for the full reference.
