#!/usr/bin/env python3
"""Read the current GPU price index, pull history, and overlay it on the
long-run informational baseline."""
import os
import requests
import pandas as pd
BASE = "https://data-api.compute-index.com/v1"
TOKEN = os.environ["TOKEN"]
headers = {"Authorization": f"Bearer {TOKEN}"}
GPU_FAMILY = "hopper" # or "blackwell"
REGION = "US"
# Step 1: Latest blended transaction index (the settlement-benchmark series)
resp = requests.get(
f"{BASE}/txn-index/current",
headers=headers,
params={
"gpu_family": GPU_FAMILY,
"region_group": REGION,
"contract_type": "combined",
"index_type": "blended_sigmoid",
},
timeout=30,
)
resp.raise_for_status()
latest = resp.json()["data"][0]
print(f"{GPU_FAMILY}-{REGION}: ${latest['index_value']:.4f}/GPU/hr on {latest['date']}")
# Step 2: Full transaction history (up to the 730-day window)
resp = requests.get(
f"{BASE}/txn-index/history",
headers=headers,
params={
"gpu_family": GPU_FAMILY,
"region_group": REGION,
"contract_type": "combined",
"index_type": "blended_sigmoid",
"days_back": 730,
},
timeout=30,
)
resp.raise_for_status()
txn = pd.DataFrame(resp.json()["data"])
txn["date"] = pd.to_datetime(txn["date"])
# Step 3: Extend history with the informational baseline (no days_back cap,
# real data back to early 2024)
resp = requests.get(
f"{BASE}/info-index/history",
headers=headers,
params={"index_name": GPU_FAMILY, "region_group": REGION},
timeout=30,
)
resp.raise_for_status()
info = pd.DataFrame(resp.json()["data"])
info["date"] = pd.to_datetime(info["date"])
# Step 4: Merge into one frame — informational baseline + transaction overlay
merged = (
info[["date", "index_value"]]
.rename(columns={"index_value": "informational"})
.merge(
txn[["date", "index_value"]].rename(columns={"index_value": "transaction"}),
on="date",
how="left",
)
.sort_values("date")
)
print(f"\nInformational baseline: {len(info)} days "
f"({info['date'].min().date()} → {info['date'].max().date()})")
print(f"Transaction overlay: {len(txn)} days "
f"({txn['date'].min().date()} → {txn['date'].max().date()})")
print(merged.tail())
# merged.plot(x="date", y=["informational", "transaction"]) # with matplotlib