Inspiration

We were inspired by Kalshi, the first CFTC-regulated prediction market in the US, which has shown how powerful crowd-sourced probability estimation can be for forecasting real-world events. However, we noticed a gap: traditional prediction markets rely on trading volume and order books to discover prices, which requires significant liquidity and active participation.

We asked ourselves: What if we could derive market probabilities directly from public discourse? Twitter/X is the world's real-time information network where breaking news, expert opinions, and public sentiment naturally emerge. By combining:

  • The structured outcome framework of prediction markets (like Kalshi)
  • The real-time signal density of X's public posts
  • The reasoning capabilities of xAI's Grok

...we could build a system that continuously computes probability estimates without requiring any trading activity.

What it does

xPredict is an AI-powered prediction market that turns public X posts into live probability estimates for any future event.

Core flow

  • Ask a question → “Will the Fed cut rates in December 2024?”
  • Grok structures it → normalizes the question, generates exclusive outcomes with priors, and creates X API filter rules
  • X posts stream in → ingestion worker listens to X filtered stream
  • Grok scores each post → relevance, stance, evidence strength, credibility
  • Probabilities update → pushes live odds to the UI with deterministic aggregation (softmax with temperature, decay, dilution):

$$P(o|t) = \text{softmax}\left(\frac{E_o}{T}\right) \quad \text{where} \quad E_o(t) = \sum_p \Delta E_{o,p}$$

Each post contributes:

$$\Delta E_o = \text{sign}(\text{stance}_o) \cdot (\text{relevance} \cdot \text{strength} \cdot \text{credibility})^\gamma \cdot M \cdot A \cdot D \cdot S$$

Key features

  • Ask Grok: conversationally query any market for quick explanations or deeper dives
  • Real-time probability charts with 1H/1D/1W/1M/All ranges
  • Curated evidence feed with AI explanations of why probabilities moved
  • Multi-depth Grok analysis (Quick / Standard / Deep Dive) with web search + citations
  • Cross-market correlation insights surfacing causal chains between related questions
  • Automatic market resolution using Grok’s real-time knowledge
  • Dark mode, interactive crosshair tooltips, and responsive UI
  • ML feedback loop that learns from resolved markets to improve calibration:

How we built it

High-Level Diagram:


                                    ┌─────────────┐
                                    │    User     │
                                    └──────┬──────┘
                                           │
                    ┌──────────────────────┼──────────────────────┐
                    │                      │                      │
                    ▼                      ▼                      ▼
           ┌───────────────┐      ┌───────────────┐      ┌───────────────┐
           │  Ask Question │      │  View Market  │      │   Resolve     │
           └───────┬───────┘      └───────┬───────┘      └───────┬───────┘
                   │                      │                      │
                   ▼                      │                      │
           ┌───────────────┐              │                      │
           │   Grok LLM    │◄─────────────┼──────────────────────┤
           │ (create/check)│              │                      │
           └───────┬───────┘              │                      │
                   │                      │                      │
                   ▼                      ▼                      ▼
           ┌─────────────────────────────────────────────────────────┐
           │                    SUPABASE                             │
           │  markets | outcomes | raw_posts | scored_posts | state  │
           └─────────────────────────────────────────────────────────┘
                   ▲                      ▲
                   │                      │
           ┌───────┴───────┐              │
           │  X API: Add   │              │
           │  Stream Rules │              │
           └───────┬───────┘              │
                   │                      │
                   ▼                      │
           ┌───────────────┐              │
           │ X Filtered    │              │
           │ Stream        │              │
           └───────┬───────┘              │
                   │                      │
                   ▼                      │
           ┌───────────────┐              │
           │  INGESTION    │              │
           │  WORKER       │──────────────┤
           │  (long-lived) │              │
           └───────┬───────┘              │
                   │                      │
                   ▼                      │
           ┌───────────────┐              │
           │  Grok LLM     │              │
           │  (scoring)    │              │
           └───────┬───────┘              │
                   │                      │
                   ▼                      │
           ┌───────────────┐              │
           │  Probability  │              │
           │  Engine       │──────────────┘
           └───────────────┘

Tech Stack:

  • Frontend: Next.js 14 (App Router), React 18, TailwindCSS, Radix UI, Lightweight Charts
  • Backend: Next.js API Routes, Supabase (Postgres + Auth + Realtime)
  • AI/ML:
    • xAI Grok 3 for scoring, analysis, market creation, and resolution
    • LightGBM for probability correction learning
    • PyTorch for post usefulness prediction
  • Data Pipeline: TypeScript ingestion worker with X API v2 filtered stream
  • Validation: Zod schemas throughout for type-safe LLM output parsing

Key Implementation Details:

  1. Probability Engine: Pure, deterministic function that computes probabilities from scored posts. Uses exponential decay (6-hour half-life), author dilution (prevents spam), metric weighting (followers, engagement), and temperature-scaled softmax.

  2. Grok Integration: Every LLM response is validated with Zod schemas. We prompt Grok to return structured JSON for scoring, market creation, similarity checks, resolution, and deep analysis.

  3. Real-time Updates: The ingestion worker maintains a persistent connection to X's filtered stream. New posts flow through scoring → probability update → Supabase Realtime → UI push within seconds.

Challenges we ran into

  1. LLM output reliability: Grok occasionally returns malformed JSON or unexpected values. We added defensive parsing with regex fallbacks for code-fenced responses, plus Zod validation with .parse() to fail fast on schema violations.

  2. Probability stability: Early versions showed wild probability swings from single tweets. We implemented:

    • Author count dilution: \(A = \max(0.35, \frac{1}{\sqrt{1 + 0.75(n-1)}})\)
    • Temporal decay: 5-minute grace period, then exponential decay
    • Adaptive temperature: \(T = T_0 \cdot (1 + \frac{\alpha}{\sqrt{1 + W_{batch}}})\)
    • EMA smoothing between updates
  3. Duplicate market detection: Users often phrase the same question differently. We built semantic similarity checking using Grok to detect when a new question is essentially asking the same thing as an existing market.

  4. Spam/noise filtering: X's filtered stream captures a lot of irrelevant content. We use multi-stage filtering: keyword relevance threshold → Grok relevance score → minimum weight threshold → credibility floor.

Accomplishments that we're proud of

  • Fully functional end-to-end pipeline: From natural language question → structured market → live ingestion → real-time probabilities → resolution detection
  • Clean separation of concerns: Pure probability math in shared package, stateless web app on Vercel, long-lived worker for streaming
  • Type-safe LLM integration: Every Grok response is schema-validated with Zod—no any types at boundaries
  • Polished UX: interactive charts, AI-labeled evidence cards, dark mode
  • ML feedback loop infrastructure: Resolved markets automatically generate training data for improving the probability engine

What we learned

  • LLMs need guardrails: strict schemas keep production stable
  • Calibration is hard: decay, temperature, and smoothing matter as much as model scores
  • Real-time pipelines need resilience: reconnection/backoff is essential for X streaming
  • Softmax keeps multi-outcome probabilities simple and consistent
  • Supabase Realtime makes the UX feel alive without polling

What's next for xPredict

  1. Enhanced ML models: Train on more resolved markets to learn systematic biases in Grok's scoring (e.g., overweighting viral tweets)

  2. Multi-source ingestion: Expand beyond X to Reddit, news APIs, and official data sources

  3. User accounts + portfolios: Let users track their "positions" on questions and earn reputation for accurate predictions

  4. Backtesting framework: Replay historical events with our engine to measure prediction accuracy vs. actual outcomes

  5. API for developers: Expose probability endpoints so others can build on our prediction infrastructure

  6. Mobile app: Native experience for tracking markets on-the-go

Built with

  • Languages: TypeScript, Python, SQL
  • Frameworks: Next.js 14, React 18, FastAPI, TailwindCSS
  • Platforms: Vercel (web), Supabase (DB/auth/realtime)
  • APIs: xAI Grok API, X API v2 filtered stream
  • ML/AI: LightGBM, PyTorch, Optuna, SHAP
  • Libraries: Zod, Lightweight Charts, Radix UI, supabase-js
  • Database: PostgreSQL via Supabase

Note: Unfortunately, our demo video did not record our screen properly. However, we have an amazing explanation there despite the lack of visuals. Update: We uploaded a new video! Old video: https://www.youtube.com/watch?v=M5uXEnVwb3U

Built With

Share this project:

Updates