DEV Community

Cover image for PythCorrelation
rustrell
rustrell

Posted on

PythCorrelation

Real-Time Crypto Correlation
Powered by Pyth Oracle Data
Explore how crypto assets move together using live market data.

Pyth Correlation Tracker is a real-time multi-asset analytics terminal that streams live price data from Pyth Network oracles and computes statistical relationships between 28 major assets across crypto, forex, metals, equities, and indices — revealing hidden market connections as they happen.

What It Does

Traditional charting tools show prices in isolation. But prices don't move alone — BTC and Gold correlate during macro crises, ETH leads SOL by seconds, EUR/USD predicts crypto volatility spikes. These relationships are the hidden architecture of markets.

Pyth Correlation Tracker makes those relationships visible, live, in real time:

  • Matrix — Live Pearson heatmap across 28 assets, updated every 3 seconds
  • Charts — Full OHLCV candlestick charts via Pyth Benchmarks (6 timeframes: 1m → 1D)
  • Correlation — Deep-dive pair analysis with 90-day history + shareable PNG card
  • Lead-Lag — Cross-correlation CCF(k) identifying which asset moves first
  • Entropy Lab — The real discovery: Shannon entropy + NMI seeded from live Pyth prices

Live

App: pythcorrelation.com
Docs: [pythcorrelation.gitbook.io
(https://pythcorrelation.gitbook.io/pythcorrelation-docs)
Twitter: @xzolmoney


Pyth Features Used

  • Price Feeds (off-chain) — Pyth Hermes REST, 28 assets simultaneously, 3s update interval
  • Historical OHLCV — Pyth Benchmarks /v1/shims/tradingview/history — all asset classes
  • Pyth prices as entropy seed — Live Pyth oracle prices (BTC, ETH, SOL, DOGE, XAU) are XOR-hashed to seed the bootstrap PRNG for the Entropy Lab. Market-derived randomness, not Math.random().
  • All asset classes — Crypto, FX, Metals, Energy, Equities, Indices via single oracle
  • Hackathon API Key — Bearer token for Pyth Pro higher rate limits

Features

1. Matrix — Live Correlation Heatmap

The main dashboard. A real-time Pearson correlation heatmap across all 28 assets — updated every 3 seconds from Pyth oracle.

  • Green = positive correlation, Red = inverse, Purple = no relationship
  • Rolling window: last 200 live Pyth ticks (~10 minutes)
  • Top Pairs Ranking — top 6 most correlated and top 6 most inversely correlated
  • Correlation Alert 🔔 — get notified when a pair crosses your threshold
  • Ticker cards: live price, % change, 50-tick sparkline, 24h High/Low, avg correlation
  • Sort by: Price ↑↓, Correlation ↑↓
  • Filter: All / Crypto / FX / Metals / Equity


2. Charts — OHLCV via Pyth Benchmarks

Full candlestick charts powered entirely by Pyth Benchmarks API — no Binance, no third-party proxies, zero CORS issues.

  • All 28 assets including XAU/USD (Gold), EUR/USD, AAPL, SPY, WTI — not just crypto
  • 6 timeframes: 1m · 5m · 15m · 1h · 4h · 1D
  • 3 chart modes: Candlestick, Line, Bar
  • 300 historical bars per load + live candle updates from Pyth ticks

This replaced Binance entirely. One oracle, all asset classes, same OHLCV format {t[], o[], h[], l[], c[], v[]}.


3. Correlation — Deep-Dive + 90-Day History

Pair-level analysis for any two of the 28 assets. Choose a pair, get instant deep-dive:

  • Large Pearson r — color-coded, updated live
  • Rolling correlation chart — watch the relationship evolve tick by tick
  • 90-day history — switch to 1D timeframe via Pyth Benchmarks daily bars to see how any pair's correlation evolved over 3 months
  • Strength labels: Very Strong / Strong / Moderate / Weak / Uncorrelated
  • Share Card — one click generates a 1200×1200 PNG with pair symbols, correlation value, color bar, and LIVE · PYTH ORACLE badge — ready to post on X/Twitter


4. Lead-Lag — Who Moves First?

Standard correlation asks: "Do A and B move together?"
Lead-Lag asks: "Does A at time T predict B at time T+k?"

CCF(k) = Pearson(A[t], B[t+k])   for k = −20..+20
Enter fullscreen mode Exit fullscreen mode
  • Positive k → A leads B by k ticks (~3s each)
  • Negative k → B leads A
  • Peak at k = +3 → Asset A moves ~9 seconds before Asset B

Real signals we found:

Signal Interpretation
BTC leads ETH by 2-3 ticks ETH price discovery follows BTC with ~6-9s delay
EUR/USD leads Gold Macro FX signal precedes metals reaction
Flat CCF Assets react independently to different catalysts


5. Entropy Lab — This Is the Real Discovery

Most analytics platforms stop at correlation. We went further.

Correlation tells you IF two assets move together. Entropy tells you WHY they can't be predicted — and WHO is pulling the strings.

This module is built on a key insight: standard correlation is blind to nonlinear dependencies. Two assets can have Pearson r ≈ 0 and still be deeply structurally coupled — just not in a linear way. Entropy Lab catches exactly this.

How Pyth prices seed the entropy bootstrap

We use live Pyth oracle prices as the entropy source — not Math.random(), not a static seed. The PRNG seed is derived by XOR-mixing live prices for 5 assets using the Fibonacci hash constant:

function pythSeed(prices) {
  const syms = ["BTC", "ETH", "SOL", "DOGE", "XAU/USD"];
  let h = Date.now() & 0xFFFFFF;
  for (const s of syms) {
    const v = prices[s];
    if (v) h = Math.imul(h ^ 0x9e3779b9, Math.floor(v * 100) | 0);
  }
  return h >>> 0;
}
Enter fullscreen mode Exit fullscreen mode

The seed changes every 3 seconds with new Pyth data. You can't reproduce yesterday's entropy run without yesterday's Pyth prices. Each analysis is verifiably tied to the current market state.

Each asset also gets its own independent RNG stream:

const rng = mulberry32((seed ^ (si * 0x9E3779B9)) >>> 0);
Enter fullscreen mode Exit fullscreen mode

Why we chose Gaussian Differential Entropy

Classic Shannon entropy via quantile binning has a fatal flaw: binning your own sample always produces a near-uniform distribution → H = log₂(8) = 3.0 for every asset. Completely useless.

We use Gaussian Differential Entropy instead:

H(X) = ½ · ln(2πe · σ²)   [nats]
Enter fullscreen mode Exit fullscreen mode

This gives real, meaningful separation:

Asset H (nats) What it means
USDC ≈ −9 Near-zero variance — most predictable asset
EUR/USD ≈ −3 Stable forex regime
BTC ≈ −1 Volatile but structured
DOGE ≈ 0 Maximum chaos — near-random walk

NMI — The Hidden Connection Detector

Normalized Mutual Information captures what Pearson completely misses:

NMI(X,Y) = I(X;Y) / √[H(X)·H(Y)]   ∈ [0, 1]
Enter fullscreen mode Exit fullscreen mode

The Hidden Connections panel flags pairs where:

  • |Pearson r| < 0.3 — looks uncorrelated to standard tools
  • NMI > 0.4 — but deeply structurally coupled

These are the relationships that most platforms never show you. Volatility coupling, regime-dependent co-movement, lagged nonlinear dependencies — all invisible to Pearson, visible in NMI.

  • Bootstrap CI: 60 iterations, 70% with-replacement resample
  • Live Run mode: continuous recompute as new Pyth ticks arrive


Architecture

Pyth Hermes REST (~3s)
        │
        ├──→ pythSeed() → XOR hash → mulberry32 PRNG seed
        │
        ▼
  Rolling Buffer (200 ticks per asset)
        │
   ┌────┴──────────────────────┐
   ▼                           ▼
Pearson Matrix             Entropy Lab
(linear corr)         (Gaussian H + NMI)
   │                           │
   └──────────┬────────────────┘
              ▼
       Lead-Lag CCF(k)
              │
              ▼
    Pyth Benchmarks (OHLCV + 90d history)
              │
              ▼
         React + Canvas UI
Enter fullscreen mode Exit fullscreen mode

Data Sources

Pyth Hermes — Live Prices

GET https://hermes.pyth.network/v2/updates/price/latest
    ?ids[]=<feed_id>&parsed=true
    Authorization: Bearer <PYTH_PRO_KEY>
Enter fullscreen mode Exit fullscreen mode

~400ms oracle latency · 3s dashboard refresh

Pyth Benchmarks — Historical OHLCV

GET https://benchmarks.pyth.network/v1/shims/tradingview/history
    ?symbol=Metal.XAU/USD&resolution=D&countback=300
Enter fullscreen mode Exit fullscreen mode

Returns {t[], o[], h[], l[], c[], v[]} — all asset classes, one API.


28 Assets, 6 Classes, 1 Oracle

Class Count Assets
Crypto 19 BTC ETH SOL DOGE USDC AVAX ADA LINK UNI LTC DOT TRX APT SUI PEPE NEAR ATOM POL HYPE
FX 2 EUR/USD · GBP/USD
Metals 1 XAU/USD (Gold)
Energy 1 WTI (Crude Oil)
Equities 1 AAPL
Indices 4 SPY · QQQ · DIA · IWM

Tech Stack

Layer Technology
Frontend React 18 + Canvas API — zero chart libraries
Oracle (live) Pyth Hermes REST
Oracle (history) Pyth Benchmarks OHLCV
Entropy seed Pyth live prices → XOR hash → mulberry32 PRNG
Math Custom JS: Pearson, Gaussian H, NMI, CCF — no external libs
Hosting Vercel + Cloudflare DNS
Security CSP / HSTS / X-Frame-Options — OWASP compliant

Zero backend. Zero database. Everything client-side.


Key Design Decisions

1. Pyth prices as verifiable entropy source — not just data
The PRNG seed changes every 3 seconds with live oracle data. Each entropy computation is uniquely tied to the current market state. This is entropy about the market, from the market.

2. Gaussian H over Shannon binning
Quantile binning on own sample → uniform distribution → H = 3.0 for every asset. Gaussian differential entropy gives 9 nats of separation between USDC and DOGE. That's signal.

3. Pyth Benchmarks replaced Binance entirely
One API. Zero CORS. All 6 asset classes. 300 bars per request. Daily resolution = 90-day correlation history for any pair.

4. NMI reveals what Pearson hides
Pairs with |r| < 0.35 but NMI > 0.40 = structurally coupled assets invisible to every linear tool. These are real hidden connections.

5. Share Card for viral distribution
One click → 1200×1200 PNG → post on X. Every shared card has LIVE · PYTH ORACLE attribution.


Why This Matters

  • Risk: r > 0.85 between two positions = one concentrated risk, not two hedges
  • Alpha: BTC leads ETH by 2-3 ticks = actionable lead-lag signal
  • Regime: BTC/Gold correlation spike = macro is taking over crypto
  • Entropy: DOGE at H ≈ 0 during news = distribution breakdown, stop-losses meaningless
  • Hidden connections: NMI catches what Pearson misses — the real market structure

Built with ❤ by rustrell · Pyth Network Hackathon 2026
© 2026 rustrell. All rights reserved.

Top comments (0)