Conformal Prediction in Python: Prediction Intervals That Keep Their Promised Coverage, Tested on 2,739 Henry Hub Forecasts

On 2,739 one-week Henry Hub forecasts from 2016 to November 2026, a 90% Gaussian interval built from training residuals covered 50.0% of outcomes and split conformal calibrated on one year covered 74.3%. Conformalized quantile regression with adaptive conformal inference covered 90.2%. The Python, the finite-sample math and what it costs in width.

Conformal prediction in Python chart: realized coverage of six 90% prediction intervals for one-week Henry Hub natural gas price moves, 2016 to November 2026. A Gaussian interval from training residuals covered 50.0%, raw quantile regression 76.2%, split conformal calibrated on 2015 74.3%, conformalized quantile regression calibrated on 2015 85.3%, rolling conformalized quantile regression 89.7% and adaptive conformal inference 90.2%

A 90% prediction interval makes a checkable promise: over many forecasts, the outcome lands inside it nine times in ten. Conformal prediction in Python is the shortest route I know to an interval that keeps that promise without assuming the errors are normal. I tested six ways of building a 90% interval on the daily Henry Hub natural gas spot price, 2,739 one-week forecasts made from January 2016 to November 17, 2026. The usual Gaussian band from training residuals covered 50.0%. Split conformal calibrated on 2015 covered 74.3%. Conformalized quantile regression with adaptive conformal inference covered 90.2%.

Most of what follows explains the gap between 74.3% and 90.2%. Conformal prediction's guarantee is real, but it rests on one assumption that a commodity price breaks most winters. Restoring it takes a few lines of Python and costs width: the interval that kept its promise was 39% wider at the median than the one calibrated once on 2015.

What a split conformal interval promises

Split conformal prediction needs three things: a fitted model, a calibration set the model never trained on, and a score that measures how wrong the model was on each calibration point. For a point forecast the score is the absolute residual, sᵢ = |yᵢ − ŷ(xᵢ)|. Take the ⌈(n+1)(1−α)⌉/n empirical quantile of the n calibration scores, call it q̂, and the interval for a new point is ŷ(x) ± q̂.

If the calibration and test points are exchangeable (any ordering of them is equally likely, which i.i.d. data satisfies), the coverage of that interval is bounded on both sides:

1 − α ≤ P(Y_n+1 ∈ C(X_n+1)) ≤ 1 − α + 1 / (n + 1)

The lower bound holds for any model and any error distribution, and the upper bound needs only that scores have no ties. That is the appeal: a bad model gets wide intervals, not wrong ones. Two limits come with it, and both matter below. The guarantee is marginal, an average over all test points, so it can hold overall while failing for a group such as winter weeks. And it holds only under exchangeability, which a time series with volatility regimes does not have.

How many calibration points you need

The guarantee is an average over calibration draws too. Any one calibration set gives an interval whose coverage is itself random. With l = ⌊(n+1)α⌋, coverage given the calibration set follows Beta(n+1−l, l), and Angelopoulos and Bates conclude that about 1,000 calibration points is enough for most purposes. Here the Beta distribution is computed, then checked by simulation on heavy-tailed scores (a t distribution with 4 degrees of freedom, 20,000 calibration draws each):

import numpy as np
from scipy import stats

ALPHA, TRIALS, rng = 0.10, 20_000, np.random.default_rng(7)

for n in (100, 250, 1000):
    l = int(np.floor((n + 1) * ALPHA))
    beta = stats.beta(n + 1 - l, l)
    lo, hi = beta.ppf([0.05, 0.95])
    cal = np.abs(rng.standard_t(df=4, size=(TRIALS, n)))
    k = int(np.ceil((n + 1) * (1 - ALPHA)))            # k-th smallest score
    q = np.sort(cal, axis=1)[:, k - 1]
    true_cov = 2 * stats.t(df=4).cdf(q) - 1
    s_lo, s_hi = np.quantile(true_cov, [0.05, 0.95])
    print(f"n={n:5d}  quantile level {k}/{n} = {k / n:.3f}  "
          f"mean coverage {beta.mean():.4f} (sim {true_cov.mean():.4f})  "
          f"90% of calibration draws give {lo:.3f} to {hi:.3f} "
          f"(sim {s_lo:.3f} to {s_hi:.3f})  P(cov < 0.88) = {beta.cdf(0.88):.3f}")
n=  100  quantile level 91/100 = 0.910  mean coverage 0.9010 (sim 0.9010)  90% of calibration draws give 0.848 to 0.945 (sim 0.848 to 0.945)  P(cov < 0.88) = 0.226
n=  250  quantile level 226/250 = 0.904  mean coverage 0.9004 (sim 0.9003)  90% of calibration draws give 0.868 to 0.930 (sim 0.868 to 0.929)  P(cov < 0.88) = 0.141
n= 1000  quantile level 901/1000 = 0.901  mean coverage 0.9001 (sim 0.9001)  90% of calibration draws give 0.884 to 0.915 (sim 0.884 to 0.915)  P(cov < 0.88) = 0.021

The simulation matches the Beta formula to the third decimal, and the t distribution makes no difference, which is the distribution-free part working as advertised. The practical number is the middle row. One year of daily data is about 250 calibration points, and 90% of the time that calibration set yields an interval whose true coverage lies somewhere from 86.8% to 93.0%. There is a 14.1% chance it sits below 88% before anything about the data changes. A thousand points narrows that to 88.4% to 91.5%.

Conformal prediction in Python on Henry Hub prices

The test needs a series where the assumption is known to break. The daily Henry Hub spot price, published by the U.S. Energy Information Administration and carried by FRED as DHHNGSP, is a good one: long stretches near $3 per million Btu, then cold snaps that move it several times over within days. In the series, the price went from $8.42 on January 22, 2026 to $30.72 on January 23, during Winter Storm Fern, and from $11.32 to $23.86 between February 16 and 17, 2021.

The target is the one-week move, the log change in price over the next five trading days. The features are things known at the close: the last 1, 5 and 20 days of returns, 20 and 60 day volatility, the gap to the 60-day average and the month. A gradient-boosted model trained on 2008 to 2014 produces the point forecast and the 5th and 95th percentiles. 2015 is the calibration year, and every forecast made from January 2016 to November 17, 2026 is the test, 2,739 in all. The model is fit once and never retrained, on purpose: the question is what each interval method does when the world drifts away from the training years.

Six methods, all aiming at 90%:

  1. Gaussian, fit once: the point forecast ± 1.645 times the standard deviation of the training residuals. A common default in forecasting dashboards.
  2. Quantile regression, raw: the model's own 5th and 95th percentiles, no calibration.
  3. Split conformal: absolute residuals, calibrated on 2015.
  4. Conformalized quantile regression (CQR): Romano, Patterson and Candès's score, calibrated on 2015.
  5. Rolling CQR: the same score, recalibrated each day on the latest 250 known scores.
  6. Adaptive conformal inference (ACI): rolling CQR whose target level adjusts after every miss, from Gibbs and Candès.

CQR starts from the quantile forecasts instead of a point forecast, so the interval can be wide in a volatile week and narrow in a calm one. Its score is how far the outcome fell outside the raw quantile band (negative when inside):

s_i = maxq̂_α/2(X_i) − Y_i, Y_i − q̂_1−α/2(X_i)

The conformal step then widens or narrows the whole band by the calibrated quantile of those scores.

ACI keeps the rolling window and also moves the level it asks for. After each forecast is scored, err_t is 1 for a miss and 0 for a hit, and

α_t+1 = α_t + γ (α − err_t)

A miss lowers α_t by 0.9γ, which widens the next interval; a hit raises it by 0.1γ. Gibbs and Candès prove that, with no assumption at all on how the data are generated, the long-run miss rate stays near α:

|1 / TΣ_t=1^Terr_t − α| ≤ (maxα_1, 1 − α_1 + γ) / (γ T)

With γ = 0.005 (the value they use), α₁ = 0.10 and T = 2,739, the right side is 0.905 / 13.695 ≈ 0.066. That bound is loose; the point is that it holds for any sequence, including one with a January 2026 in it.

One detail trips up most time series implementations. A forecast made on day t is about day t + 5, so its score does not exist until five trading days later. Both rolling methods below use only scores whose outcomes are already known, and ACI updates α_t with the miss from five days back.

"""Conformal prediction intervals for one-week Henry Hub price moves.

Data: FRED series DHHNGSP (Henry Hub natural gas spot price, daily, $/MMBtu,
source U.S. Energy Information Administration). Download it with
    https://fred.stlouisfed.org/graph/fredgraph.csv?id=DHHNGSP
or pass any CSV whose first column is the date and second the price.

Every interval targets 90% coverage of the 5-trading-day-ahead log price change.
"""
import sys
import numpy as np
import pandas as pd
from sklearn.ensemble import HistGradientBoostingRegressor

ALPHA, H, SEED = 0.10, 5, 0
path = sys.argv[1] if len(sys.argv) > 1 else "DHHNGSP.csv"
px = pd.read_csv(path, parse_dates=[0], na_values=".")
px.columns = ["date", "price"]
px = px.dropna().query("date >= '2008-01-01'").set_index("date")["price"]

# Features known at the close of day t, target = log(P[t+H] / P[t])
lp = np.log(px)
r1 = lp.diff()
X = pd.DataFrame({
    "r1": r1, "r5": lp.diff(5), "r20": lp.diff(20),
    "vol20": r1.rolling(20).std(), "vol60": r1.rolling(60).std(),
    "gap60": lp - lp.rolling(60).mean(),
    "month": px.index.month,
})
y = lp.shift(-H) - lp
df = X.assign(y=y).dropna()
feats = list(X.columns)

train = df.loc["2008":"2014"]
cal = df.loc["2015"]
test = df.loc["2016":]
print(f"train {len(train)}  calibration {len(cal)}  test {len(test)}  "
      f"test ends {test.index[-1].date()}")

def hgb(loss, q=None):
    kw = dict(max_iter=300, learning_rate=0.05, max_leaf_nodes=15,
              min_samples_leaf=40, random_state=SEED)
    return HistGradientBoostingRegressor(loss=loss, quantile=q, **kw) if q else \
        HistGradientBoostingRegressor(loss=loss, **kw)

point = hgb("squared_error").fit(train[feats], train.y)
qlo = hgb("quantile", ALPHA / 2).fit(train[feats], train.y)
qhi = hgb("quantile", 1 - ALPHA / 2).fit(train[feats], train.y)

def preds(d):
    return point.predict(d[feats]), qlo.predict(d[feats]), qhi.predict(d[feats])

def conformal_q(scores, alpha):
    """Split conformal quantile: the ceil((n+1)(1-alpha))/n empirical quantile."""
    n = len(scores)
    level = np.ceil((n + 1) * (1 - alpha)) / n
    return np.inf if level > 1 else np.quantile(scores, level, method="higher")

m_cal, lo_cal, hi_cal = preds(cal)
m, lo, hi = preds(test)
yt = test.y.values

out = {}
# 1. Gaussian interval from in-sample residual spread
sd = np.std(train.y - point.predict(train[feats]))
out["Gaussian, fit once"] = (m - 1.645 * sd, m + 1.645 * sd)
# 2. Raw quantile regression
out["Quantile regression, raw"] = (lo, hi)
# 3. Split conformal on absolute residuals, calibrated on 2015
qa = conformal_q(np.abs(cal.y.values - m_cal), ALPHA)
out["Split conformal, 2015 calibration"] = (m - qa, m + qa)
# 4. Conformalized quantile regression (CQR), calibrated on 2015
cqr_cal = np.maximum(lo_cal - cal.y.values, cal.y.values - hi_cal)
qc = conformal_q(cqr_cal, ALPHA)
out["CQR, 2015 calibration"] = (lo - qc, hi + qc)

# 5 and 6. Rolling CQR and adaptive conformal inference (Gibbs and Candes 2021).
# A forecast made on day t is scored only once its outcome is known, H days later.
all_lo = np.r_[lo_cal, lo]; all_hi = np.r_[hi_cal, hi]; all_y = np.r_[cal.y.values, yt]
scores = np.maximum(all_lo - all_y, all_y - all_hi)
start, W, GAMMA = len(cal), 250, 0.005
roll_lo, roll_hi, aci_lo, aci_hi = (np.empty(len(yt)) for _ in range(4))
alpha_t, alpha_path = ALPHA, []
for i in range(len(yt)):
    t = start + i
    window = scores[max(0, t - H - W + 1): t - H + 1]   # scores whose outcomes are known
    q_roll = conformal_q(window, ALPHA)
    roll_lo[i], roll_hi[i] = all_lo[t] - q_roll, all_hi[t] + q_roll
    # ACI: update alpha_t with the error of the forecast whose outcome just arrived
    j = t - H
    if j >= start:
        err = float(not (aci_lo[j - start] <= all_y[j] <= aci_hi[j - start]))
        alpha_t = alpha_t + GAMMA * (ALPHA - err)
    alpha_path.append(alpha_t)
    # alpha_t <= 0 (or too small for the window) means the whole real line
    q_aci = conformal_q(window, min(alpha_t, 1.0)) if alpha_t > 0 else np.inf
    aci_lo[i], aci_hi[i] = all_lo[t] - q_aci, all_hi[t] + q_aci
out["CQR, rolling 250 days"] = (roll_lo, roll_hi)
out["Adaptive conformal (ACI)"] = (aci_lo, aci_hi)

years = test.index.year
winter = test.index.month.isin([12, 1, 2])
rows = []
for name, (a, b) in out.items():
    cov = (yt >= a) & (yt <= b)
    by_year = pd.Series(cov, index=years).groupby(level=0).mean()
    roll = pd.Series(cov).rolling(250).mean()
    width = np.median(np.exp(b) - np.exp(a)) * 100  # median width, % of price
    rows.append(dict(method=name, coverage=cov.mean(), winter=cov[winter].mean(),
                     infinite_days=int(np.isinf(b).sum()),
                     worst_year=by_year.min(), worst_year_is=int(by_year.idxmin()),
                     min_250d=roll.min(), max_250d=roll.max(), median_width_pct=width))
res = pd.DataFrame(rows).set_index("method")
pd.set_option("display.width", 200)
print(res.round(3).to_string())

# Winter Storm Fern: forecasts made Jan 14 to Jan 23, 2026 (outcomes Jan 21 to Jan 30)
fern = (test.index >= "2026-01-14") & (test.index <= "2026-01-23")
for name, (a, b) in out.items():
    cov = (yt >= a) & (yt <= b)
    print(f"{name:36s} forecasts made Jan 14 to Jan 23, 2026: "
          f"{cov[fern].sum()} of {fern.sum()} covered")

# The latest forecast: the interval for the five trading days after the last close
xl = X.dropna().iloc[[-1]]
p_last = px.loc[xl.index[0]]
lo_l, hi_l = qlo.predict(xl[feats])[0], qhi.predict(xl[feats])[0]
q_now = conformal_q(scores[len(scores) - W:], min(alpha_t, 1.0)) if alpha_t > 0 else np.inf
print(f"last close {xl.index[0].date()} ${p_last:.2f}; final ACI alpha_t {alpha_t:.4f}; "
      f"ACI 90% range for {H} trading days ahead: "
      f"${p_last * np.exp(lo_l - q_now):.2f} to ${p_last * np.exp(hi_l + q_now):.2f}")
print(f"alpha_t range over test: {min(alpha_path):.4f} to {max(alpha_path):.4f}")
wk = lp.diff(5).dropna()
vol = wk.groupby(wk.index.year).std()
print("std of one-week log changes:", vol.loc[[2015, 2021, 2022, 2026]].round(3).to_dict(),
      "| years after 2015 with higher std:", int((vol.loc[2016:] > vol.loc[2015]).sum()), "of", len(vol.loc[2016:]))
ap = pd.Series(alpha_path, index=test.index)
print(f"lowest alpha_t {ap.min():.4f} on {ap.idxmin().date()}; "
      f"alpha_t on 2026-01-14 {ap.loc['2026-01-14']:.4f}, on 2026-02-27 {ap.loc['2026-02-27']:.4f}")

What each interval actually covered

Run on the series as FRED held it on November 30, 2026 (the last observation is November 24), the script's results are:

Method (target 90%)Coverage, 2016 to 2026Dec to Feb weeksWorst yearMedian width, % of price
Gaussian, fit once50.0%40.2%27.6% (2022)13.9%
Quantile regression, raw76.2%69.7%68.1% (2021)23.5%
Split conformal, 2015 calibration74.3%65.6%48.4% (2022)26.1%
CQR, 2015 calibration85.3%78.5%76.4% (2022)29.9%
CQR, rolling 250 days89.7%83.3%84.0% (2022)37.9%
Adaptive conformal (ACI)90.2%84.7%86.0% (2022)41.5%

The Gaussian band is the cautionary one. Its spread came from residuals on the training data, which a boosted model fits closely, so the band was far too narrow before any regime change: it covered half the outcomes it promised to cover nine times in ten. Held-out residuals fix that part, and split conformal on 2015 already does better than the Gaussian band, but 2015 was a calm year for gas. The standard deviation of one-week log changes was 7.2% that year, lower than in 10 of the 11 years since; it was 26.3% in 2021 and 32.8% so far in 2026. A threshold learned in 2015 was too small for those years, and split conformal covered 48.4% of weeks in 2022.

CQR helps because the quantile model already knows that a high-volatility week deserves a wider band, and calibration corrects its overall scale. Fixed on 2015, it still fell short at 85.3%. Recalibrating daily on the last 250 scores brought it to 89.7%, and letting ACI move the level as misses arrived brought it to 90.2%, with the worst calendar year at 86.0% and the worst 250-day stretch at 82.8%.

Coverage was bought with width. ACI's median interval spans 41.5% of the price over a week, against 29.9% for CQR fixed on 2015 and 13.9% for the Gaussian band. The rolling methods carry the scores of the last 250 forecasts, so one volatile stretch keeps their intervals wide for about a year after it.

Winter Storm Fern: what no interval caught

ACI's guarantee is about the long-run miss rate, not any single week. Seven forecasts were made between January 14 and January 23, 2026, for outcomes from January 21 to 30. The four fixed methods covered none of them. Rolling CQR and ACI covered one of seven each. No model trained on lagged prices predicts a jump from $8.42 to $30.72 in a day, and an interval built from the last year of scores does not either.

What ACI does is learn from the misses. Its α_t was 0.101 on January 14; by February 27 it had fallen to 0.046, so the interval was being drawn at about the 95th percentile of recent scores instead of the 90th. The lowest α_t in the whole test, 0.0265, came on February 26, 2021, nine days after the 2021 spike. Then the hits pull it back up, 0.1γ at a time, and the interval narrows again. Over the full test it moved between 0.0265 and 0.1475.

A worked interval for this week, with a Kansas City reading

On November 24, 2026, the Henry Hub spot price was $3.30 in the FRED series. Using the latest α_t (0.127, above 0.10 because recent forecasts have been covered more often than nine times in ten), the ACI interval for five trading days later runs from $2.59 to $3.90. That is a demonstration of the method, not a market view, and the model has not been retrained since 2014.

The Kansas City Fed's Tenth District Energy Survey asks energy firms in the district for expected Henry Hub prices. Its October 9 release put the average expectation at $3.35 six months out and $3.57 a year out, and the average price needed for drilling to be profitable at $3.59. A conformal interval is the natural companion to numbers like those: a one-week range from $2.59 to $3.90 around a $3.30 price says how far the price can move from a single expectation within a week, and an interval that kept 90.2% coverage from 2016 to November 2026 tells a fuel buyer in Kansas City how much to trust it. My earlier piece on scoring EIA's Henry Hub forecasts covers the point-forecast side of the same question.

Where this breaks

Coverage here is marginal. Winter weeks ran at 84.7% even under ACI, so a buyer who only cares about December to February is getting less than 90%, and no conformal method fixes that without conditioning on the season or on volatility explicitly. The targets also overlap: consecutive one-week forecasts share four of their five days, so misses come in clusters, and the effective number of independent tests is closer to 550 than 2,739. One model, one seed and one series sit behind these numbers; the paid edition below runs the conformal methods on three more series and three horizons.

Gaussian intervals are not wrong in principle. Built from held-out residuals of a model that is not overfit, they can do well in calm years. The problem is that nothing in the method tells you when they stop being right, and conformal calibration does. For classification, where the matching question is whether a score of 0.8 means 80%, see model calibration in Python.

The paid edition

The paid edition on Substack extends this in three directions: fixed CQR, rolling CQR and ACI on WTI crude, the 10-year Treasury yield and the broad dollar index, Henry Hub at 1, 5 and 20 trading days ahead, and a sensitivity grid over ACI's step size and window length (one setting produced infinite intervals on 418 of 2,739 days). It includes conformal_toolkit.py, a reusable module for rolling CQR and ACI that handles the forecast horizon correctly, and a 10-point checklist for auditing any prediction interval before it reaches a decision. Subscribe free for new articles by email, or get a Team License for a forecasting or risk team.

About the author

Brian Curry leads Vector1, a research, applied science and machine learning lab in Kansas City that runs on a proprietary agentic operating system he designed. The lab works across data science, machine learning, AI and agentic systems, causal modeling, and system design and architecture. Over the past decade, he has directed data science, machine learning, applied and agentic AI, advanced analytics, and data architecture initiatives across major enterprises from $4 billion to $125 billion. Vector1's work includes Gedanken Galaxy (patent pending) and the open-source Python libraries PyCausalSim, for causal discovery and simulation, and Papilon, a complex systems framework for Bayesian marketing mix modeling. He previously founded KC AI Lab, expanding the regional practitioner network to over 1,500 members. His open-source frameworks, benchmarks, and research are available at vector1.ai.

More on forecasting, econometrics and commodity modeling is in the Econometrics, Economic Forecasting & Commodity Modeling research area.

Sources

Related research