Volatility context

View as MarkdownOpen the editor

Volatility context is a start-of-day summary card for this symbol's options, not a history.

Its headline answers: do later-ending options cost more, do puts (bets on a fall) cost more, are options pricey? Later-ending options costing more (contango) is the calm shape, and pricier puts mean traders fear a drop. The third weighs implied volatility (how big a move option prices expect) against realized volatility (how much price actually moved). Use it for a quick read before you trade options, on any chart whose symbol has listed options.

Under the hood: the recipe reads options_chain.cells on the live bar with the atm and delta_band page views (Data sources, Chain page views). So the chart reads only the two strikes around each expiry's price and, on the expiry nearest 30 days, the contracts around 25 delta. The options kit's ExpectedMoves gives the at-the-money term and the front expected move (The canonical numbers). IvTerm gives the 25 delta wings and the 9 and 30-day IVs. It also uses oneSigmaMove, optionsAsOfMs and optionsTradeDay (Options kit). TextBuilder.expiry writes the front expiry's label (A second builder). A CandleList of the chart's own daily candles gives the realized volatility (Calendar periods and candle lists). A render.hud card with no look word shows it all (HUD cards, The default look). It is also the vol-context template, the Volatility Context card under HUDs in the editor's starter list, and it compiles as written.

The wrun indicator

// Volatility Context: a start-of-day summary card for this symbol's options, not a history. Its headline answers three
// questions in words. Do later-ending options cost more? Contango is that calm, usual shape, and backwardation means
// near-term stress. Do puts (bets on a fall) cost more than calls (bets on a rise)? Puts rich means traders pay up to
// guard against a drop. Are options pricey? Implied volatility (how big a move option prices expect) above realized
// volatility (how much price actually moved) flags pricey options. Tiles add the expected move (how far option prices
// say the stock can move). It runs to the next expiry (the day the option ends). They also show today's move in 1σ
// moves (one standard deviation), and which side, puts or calls, is cheap. Use it for a quick read before you trade
// options.
//
// Technical notes: one card that reads the chart's own option chain the way a volatility desk opens its day. The term
// structure: the 30-day and 90-day at-the-money IV at constant maturity (the options kit's ExpectedMoves, interpolated
// in total variance between the expiries around it) and their slope, contango when the 90-day sits more than 1% over
// the 30-day, backwardation when it sits more than 1% under, flat between. The skew: the 25 delta put IV minus the 25
// delta call IV at the expiry nearest 30 days, over the 30-day IV: puts rich above 0.06, calls rich below 0, flat
// between; the risk reversal beside it in vol points, call minus put. IV against realized: the 30-day IV over the
// realized volatility of the last 21 daily log returns of the chart's own daily candles (the sample standard deviation,
// annualized over 252 trading days a year, 365 on crypto, which trades every day). The front expiry: the first after
// today on the market's own calendar, its days to go and its expected move (0.85 of the at-the-money straddle,
// ExpectedMoves' rule, the one every options card reads). A card at the bottom of the pane leads with one plain line
// (Contango, puts rich, IV over realized). The chain rides the live bar only: history bars draw nothing; it is read at
// its as-of, the live bar's close, an OPRA expiry live and priced until 15 minutes past its 16:00 stamp.
//
// Three readings beside them from the same chain. Sigma: today's close against the session's open (the open of the
// trade day's first bar on the market's clock: the UTC day on crypto, the CME trade date, the New York date) over the
// day's 1σ move, the open x the chain's 1-day ATM IV (ExpectedMoves.horizonIv) x sqrt(1/252) (oneSigmaMove), with the
// budget left. Term 9 over 30: IvTerm's 9-day over its 30-day constant-maturity ATM IV, each interpolated in total
// variance between the expiries around it, none with fewer than two: contango under 0.99, backwardation over 1.01, flat
// between. The tilt: the 25 delta put IV minus the call IV at the expiry nearest 30 days, in vol points (the risk
// reversal turned round), naming the cheap side: calls cheap at +0.5 or more, puts cheap at -0.5 or less, balanced
// between.

section("Volatility");
param.int("rv_days", 21, { min: 5, max: 60, label: "Realized vol, days", description: "How many daily price changes the realized volatility measures. 21 is about a month of trading days." });
param.choice("rv_year", ["auto", "252", "365"], "auto", { label: "Realized vol year", description: "Days a year the daily moves scale to. Auto picks 365 on crypto, which trades every day, and 252 elsewhere." });
param.number("rate_pct", 4, { min: 0, max: 20, step: 0.25, label: "Interest rate, percent", description: "The interest rate that projects a US stock's price to each expiry. Futures and crypto options do not need it." });
input("close", ohlcv.close); // the chart's own close: spot where a contract reports no underlying
input("chain", options_chain.cells, { max_cells: 16000, venue: "auto", page_views: ["atm", "delta_band"], center: 0, expiry: 30, rate: "@rate_pct", description: "This symbol's options: US listed options on a stock, CME options on a future, Deribit options on BTC and ETH. It reads each expiry's two strikes around the price and, on the expiry nearest 30 days, those around 25 delta." }); // [strike, expiry_ms, side, oi, gamma, delta, mark_iv, underlying, multiplier, vega] per contract, in the chain's order
input("daily", candles.cells, { interval: "1d", bars: 64, description: "The newest 64 closed daily candles, for the realized volatility" }); // [offset_ms, open, high, low, close, volume] per candle, oldest first
market.zone(); // the market's clock: 0 UTC (crypto), 1 New York (US stocks), 2 Chicago (CME): the calendar, the liveness, the rate and the year
chart.interval_sec(); // the bar's length: the chain's as-of is the live bar's close time, the block naming none
// The readings, data-only: the card's tiles read them and the Console can too. Each is NaN on history bars.
output("iv30", none, overlay, { description: "The 30-day at-the-money IV, in percent. Live bar only." });
output("iv90", none, overlay, { description: "The 90-day at-the-money IV, in percent. Past the last expiry, it reads that expiry's IV." });
output("term_slope", none, overlay, { description: "How far the 90-day IV sits above or below the 30-day IV, in percent" });
output("term_regime", none, overlay, { description: "The term structure: 0 backwardation (slope under -1%), 1 flat or no reading, 2 contango (slope over +1%)" });
output("rr25", none, overlay, { description: "The 25 delta risk reversal at the expiry nearest 30 days: call IV minus put IV, in IV points" });
output("skew_scaled", none, overlay, { description: "The 25 delta put IV minus the call IV, divided by the 30-day IV: the number behind the skew verdict" });
output("skew_regime", none, overlay, { description: "The skew: 0 calls rich (under 0), 1 flat or no reading, 2 puts rich (over 0.06)" });
output("skew_days", none, overlay, { description: "Days until the expiry the skew reads, the one nearest 30 days" });
output("rv21", none, overlay, { description: "How much the price actually moved over the last 21 trading days by default, as a yearly percent" });
output("iv_rv_ratio", none, overlay, { description: "The 30-day IV divided by the realized volatility" });
output("ivrv_regime", none, overlay, { description: "IV against realized: 0 under, 1 at it or no reading, 2 over" });
output("front_days", none, overlay, { description: "Days until the front expiry, the first after today on the market's calendar" });
output("front_move", none, overlay, { description: "The front expiry's expected move, in price: 0.85 of its at-the-money straddle (a call plus a put at one strike)" });
output("front_move_pct", none, overlay, { description: "The front expiry's expected move, in percent of the price" });
output("sigma", none, overlay, { description: "Today's move from the session's open, in 1σ moves (one standard deviation) of the 1-day IV" });
output("sigma_left", none, overlay, { description: "How much of today's 1σ move is left: 1 minus the size of Sigma, never below 0" });
output("sigma_band", none, overlay, { description: "The Sigma tile's colour: 0 under 0.5, 1 under 1, 2 down 1 or more, 3 up 1 or more" });
output("term_9_30", none, overlay, { description: "The 9-day at-the-money IV divided by the 30-day one. Empty with fewer than two expiries." });
output("tilt", none, overlay, { description: "The 25 delta put IV minus the call IV at the expiry nearest 30 days, in IV points. At +0.5 or more, calls are the cheap side." });
string("read", { max_bytes: 64 }); // the headline: the three verdicts in one line, or why there is no reading
string("title", { max_bytes: 64 }); // the card's title: the front expiry and its days to go
string("term_text", { max_bytes: 40 }); // the term tile: the word and the slope
string("skew_text", { max_bytes: 40 }); // the skew tile: the word and the scaled skew
string("ivrv_text", { max_bytes: 40 }); // the realized tile: the word and the ratio
string("short_term_text", { max_bytes: 40 }); // the 9 over 30 tile: the word and the ratio
string("tilt_text", { max_bytes: 40 }); // the tilt tile: the cheap side and the tilt

// The card: the headline, each verdict as its own tile, the numbers under them as rows.
render.hud("vol_context", {
  position: "bottom_center",
  title: "{{title}}",
  columns: 2,
  tiles: [
    tile.pill("Volatility", "read", { headline: true }),
    tile.pill("Term, 90 over 30 days", "term_text"),
    tile.pill("25 delta skew", "skew_text"),
    tile.pill("IV against realized", "ivrv_text"),
    tile.value("Front expected move", "front_move", { format: "price" }),
    tile.pill("Term, 9 over 30 days", "short_term_text"),
    tile.pill("Tilt, put minus call", "tilt_text"),
    tile.value("Sigma today", "sigma", { format: "0.00", color_by: "sigma_band", colors: ["theme.muted", "theme.text", "theme.down", "theme.up"] }),
    tile.rows([
      ["IV, 30 days", "iv30", "0.00"],
      ["IV, 90 days", "iv90", "0.00"],
      ["Term slope, %", "term_slope", "0.00"],
      ["Risk reversal, call minus put", "rr25", "0.00"],
      ["Skew over IV, put minus call", "skew_scaled", "0.000"],
      ["Realized vol", "rv21", "0.00"],
      ["IV over realized", "iv_rv_ratio", "0.00"],
      ["Front move, %", "front_move_pct", "0.00"],
      ["Sigma budget left", "sigma_left", "0.00"],
    ]),
  ],
});

const TUPLE = 10; // f64s per contract: strike, expiry_ms, side, oi, gamma, delta, mark_iv, underlying, multiplier, vega
const MAX_DAYS = 64; // the daily candles kept: the stream's depth
const CONTANGO = 0.01; // the slope past which the term is contango (and under minus it, backwardation)
const PUT_RICH = 0.06; // the scaled skew past which puts are rich (under 0, calls are)
const SIGMA_YEARS: f64 = 1.0 / 252.0; // one trading day: the day's 1σ move is the open x the 1-day IV x sqrt(1/252)
const DAY_MS: f64 = 86400000.0;
const FLAT_TERM = 0.01; // the 9 over 30 ratio's flat band, each side of 1
const BALANCED = 0.5; // the tilt, vol points, under which neither side is cheap
const days = new CandleList(MAX_DAYS); // the newest closed daily candles, kept from the stream
const term = new IvTerm(64); // the chain's 25 delta wings at the expiry nearest 30 days
const expiryText = new TextBuilder(16); // the front expiry's label, the kit's spelling, copied into the title
let moves = new ExpectedMoves(1); // every live expiry's forward, at-the-money IV and expected move; built in onStart()

let rvDays = 21; // settings, read in onStart()
let yearDays = 252.0;
let rate = 0.04;
let zone = 0;
let intervalMs = 0.0; // the bar's length in milliseconds; 0 where the host writes none
let coarse = false; // a chart coarser than a day: a bar is no session, so Sigma reads none
let nowMs: f64 = NaN; // the chain's as-of, the live bar's close
let close: f64 = NaN; // this bar
let t: f64 = NaN;
let atm30: f64 = NaN; // the readings, measured on the live bar, as decimals
let atm90: f64 = NaN;
let slope: f64 = NaN;
let callWing: f64 = NaN;
let putWing: f64 = NaN;
let skewScaled: f64 = NaN;
let skewDays: f64 = NaN;
let realized: f64 = NaN;
let overRealized: f64 = NaN;
let front = -1;
let frontDays: f64 = NaN;
let frontMove: f64 = NaN;
let frontMovePct: f64 = NaN;
let sessionDay: f64 = NaN; // the trade day the newest bar sits in, on the market's clock
let sessionOpen: f64 = NaN; // the open of that trade day's first bar; NaN while the run opened inside it
let sigma: f64 = NaN; // the three readings beside the chain's, live bar only
let sigmaLeft: f64 = NaN;
let term930: f64 = NaN;
let tilt: f64 = NaN;

function onStart(): void {
  moves = new ExpectedMoves(in_chain_max_cells); // its buffers are its only allocation
  rvDays = i32(p_rv_days());
  zone = i32(p_market_zone());
  intervalMs = p_chart_interval_sec() * 1000.0;
  coarse = intervalMs > DAY_MS;
  const year = i32(p_rv_year());
  yearDays = year == 1 ? 252.0 : year == 2 ? 365.0 : zone == 0 ? 365.0 : 252.0; // crypto trades every day of the year
  rate = zone == 1 ? p_rate_pct() / 100.0 : 0.0; // only a stock's spot needs carrying to each forward
}

// ── Realized volatility: the sample standard deviation of the last rvDays daily log returns, annualized ──
function realizedVol(): f64 {
  const held = days.count();
  if (held < rvDays + 1) return NaN; // rvDays returns need rvDays + 1 closes
  let sum = 0.0;
  for (let k = held - rvDays; k < held; k += 1) {
    const before = days.close(k - 1);
    const after = days.close(k);
    if (!(before > 0.0) || !(after > 0.0)) return NaN;
    sum += Math.log(after / before);
  }
  const mean = sum / f64(rvDays);
  let squares = 0.0;
  for (let k = held - rvDays; k < held; k += 1) {
    const r = Math.log(days.close(k) / days.close(k - 1)) - mean;
    squares += r * r;
  }
  return Math.sqrt(squares / f64(rvDays - 1)) * Math.sqrt(yearDays);
}

// ── The chain, measured on the live bar ──
function measure(n: i32): void {
  const cells = in_chain_view(); // the live chain in place: the first n values of the build's own buffer
  nowMs = optionsAsOfMs(t * 1000.0, intervalMs); // the chain's as-of: the live bar's close time
  moves.load(cells, n, nowMs, close, zone);
  term.load(cells, n, nowMs, close, zone, rate);
  atm30 = moves.horizonIv(30.0 / 365.0);
  atm90 = moves.horizonIv(90.0 / 365.0);
  slope = atm30 > 0.0 && atm90 > 0.0 ? atm90 / atm30 - 1.0 : NaN;
  const e = term.nearest(30.0); // the anchor whose time to expiry is nearest 30 days
  callWing = term.deltaIv(e, 1.0, 0.25);
  putWing = term.deltaIv(e, -1.0, 0.25);
  skewScaled = atm30 > 0.0 ? (putWing - callWing) / atm30 : NaN; // put minus call over the 30-day IV, as the label reads it
  skewDays = term.days(e);
  realized = realizedVol();
  overRealized = realized > 0.0 && atm30 > 0.0 ? atm30 / realized : NaN;
  const todayKey = optionsTradeDay(nowMs, zone);
  front = -1; // the first expiry after today on the market's calendar, whatever its IV
  for (let e = 0; e < moves.expiries(); e += 1) {
    if (optionsTradeDay(moves.expiry(e), zone) > todayKey) {
      front = e;
      break;
    }
  }
  frontDays = front >= 0 ? optionsTradeDay(moves.expiry(front), zone) - todayKey : NaN;
  frontMove = moves.expectedMove(front); // NaN with no front
  frontMovePct = (frontMove / moves.forward(front)) * 100.0;
}

// ── The three readings beside the chain's, on the live bar ──
function anchorCount(): i32 { // IvTerm's anchors: expiries after today with an at-the-money IV
  let held = 0;
  for (let e = 0; e < term.expiries(); e += 1) {
    if (term.days(e) >= 1.0 && term.years(e) > 0.0 && !isNaN(term.atmIv(e))) held += 1;
  }
  return held;
}
function bandOf(s: f64): f64 { // 0 under 0.5, 1 under 1, 2 at 1 or more down, 3 at 1 or more up; NaN with no sigma
  if (isNaN(s)) return NaN;
  const a = Math.abs(s);
  return a < 0.5 ? 0.0 : a < 1.0 ? 1.0 : s < 0.0 ? 2.0 : 3.0;
}
function measureMore(): void {
  if (!coarse) {
    sigma = (close - sessionOpen) / oneSigmaMove(sessionOpen, moves.horizonIv(1.0 / 365.0), SIGMA_YEARS); // NaN without an open or an IV
    sigmaLeft = isNaN(sigma) ? NaN : Math.max(0.0, 1.0 - Math.abs(sigma));
  }
  term930 = anchorCount() >= 2 ? term.iv(9.0) / term.iv(30.0) : NaN;
  tilt = (putWing - callWing) * 100.0; // NaN without both wings
}

// ── The card's words ──
function termCode(): f64 { // 0 backwardation, 1 flat, 2 contango; NaN with no slope
  if (isNaN(slope)) return NaN;
  return slope > CONTANGO ? 2.0 : slope < -CONTANGO ? 0.0 : 1.0;
}
function skewCode(): f64 { // 0 calls rich, 1 flat, 2 puts rich; NaN with no skew
  if (isNaN(skewScaled)) return NaN;
  return skewScaled > PUT_RICH ? 2.0 : skewScaled < 0.0 ? 0.0 : 1.0;
}
function ratioCode(): f64 { // 0 under realized, 1 at it, 2 over; NaN with no ratio
  if (isNaN(overRealized)) return NaN;
  return overRealized > 1.0 ? 2.0 : overRealized < 1.0 ? 0.0 : 1.0;
}
function sbSigned(v: f64): void { // +6.20 / -3.10, two decimals; a value that rounds to zero reads +0.00
  if (Math.abs(v) < 0.005) {
    sb_text("+0.00");
    return;
  }
  if (v > 0.0) sb_text("+");
  sb_f64(v, 2);
}
function writeWords(): void {
  const termAt = termCode();
  const skewAt = skewCode();
  const ratioAt = ratioCode();
  // The headline: the verdicts that have a reading, the first one capitalized.
  sb_clear();
  let parts = 0;
  if (!isNaN(termAt)) {
    sb_text(termAt == 2.0 ? "Contango" : termAt == 0.0 ? "Backwardation" : "Flat term");
    parts += 1;
  }
  if (!isNaN(skewAt)) {
    if (parts > 0) sb_text(", ");
    if (skewAt == 2.0) sb_text(parts > 0 ? "puts rich" : "Puts rich");
    else if (skewAt == 0.0) sb_text(parts > 0 ? "calls rich" : "Calls rich");
    else sb_text(parts > 0 ? "skew flat" : "Skew flat");
    parts += 1;
  }
  if (!isNaN(ratioAt)) {
    if (parts > 0) sb_text(", ");
    sb_text(ratioAt == 2.0 ? "IV over realized" : ratioAt == 0.0 ? "IV under realized" : "IV at realized");
    parts += 1;
  }
  if (parts == 0) sb_text("No implied volatility in this symbol's options");
  str_read_sb();
  // The tiles.
  sb_clear();
  if (isNaN(termAt)) sb_text("No term");
  else {
    sb_text(termAt == 2.0 ? "Contango, " : termAt == 0.0 ? "Backwardation, " : "Flat, ");
    sbSigned(slope * 100.0);
    sb_text("%");
  }
  str_term_text_sb();
  sb_clear();
  if (isNaN(skewAt)) sb_text("No 25 delta wing");
  else {
    sb_text(skewAt == 2.0 ? "Puts rich, " : skewAt == 0.0 ? "Calls rich, " : "Flat, ");
    sb_f64(skewScaled, 3);
  }
  str_skew_text_sb();
  sb_clear();
  if (realized == 0.0) sb_text("Realized vol is zero");
  else if (isNaN(realized)) {
    sb_text("Needs ");
    sb_int(rvDays + 1);
    sb_text(" daily closes");
  } else if (isNaN(ratioAt)) sb_text("No 30-day IV");
  else {
    sb_text(ratioAt == 2.0 ? "IV over realized, " : ratioAt == 0.0 ? "IV under realized, " : "IV at realized, ");
    sb_f64(overRealized, 2);
    sb_text("x");
  }
  str_ivrv_text_sb();
  // The title: the front expiry and its days to go.
  sb_clear();
  sb_text("Volatility context, ");
  if (front < 0) sb_text("no expiry after today");
  else {
    sb_text("front ");
    expiryText.clear().expiry(moves.expiry(front), nowMs, zone); // the expiry's trade date: 16 Oct, or 15 Jan '27 in another year
    for (let i = 0; i < expiryText.length(); i += 1) sb_char(load<u8>(<usize>expiryText.ptr() + <usize>i));
    sb_text(" in ");
    sb_int(i64(frontDays));
    sb_text(frontDays == 1.0 ? " day" : " days");
  }
  str_title_sb();
}

function writeMoreWords(): void { // the 9 over 30 tile and the tilt tile, n/a without their reading
  sb_clear();
  if (isNaN(term930)) sb_text("n/a");
  else {
    sb_text(term930 > 1.0 + FLAT_TERM ? "Backwardation, " : term930 < 1.0 - FLAT_TERM ? "Contango, " : "Flat, ");
    sb_f64(term930, 2);
  }
  str_short_term_text_sb();
  sb_clear();
  if (isNaN(tilt)) sb_text("n/a");
  else {
    sb_text(tilt >= BALANCED ? "Calls cheap, " : tilt <= -BALANCED ? "Puts cheap, " : "Balanced, ");
    sbSigned(tilt);
    sb_text(" pts");
  }
  str_tilt_text_sb();
}

// onBar() runs once per bar: every bar feeds its daily block to the list (an empty one too) and notes its session; the
// live bar measures the chain and writes the readings (NaN on history rows) and the card's words.
function onBar(): void {
  close = bar.close();
  t = bar.time();
  days.load(in_daily_view(), in_daily_cells(), t);
  // The session: the first bar of each trade day opens it; the run's first trade day opened before the run did.
  const day = optionsTradeDay(t * 1000.0, zone);
  if (isFinite(day) && day != sessionDay) {
    sessionOpen = isNaN(sessionDay) ? NaN : bar.open();
    sessionDay = day;
  }
  let measured = false;
  let chainCells = -1;
  if (bar.isLast()) {
    chainCells = in_chain_cells();
    if (chainCells >= TUPLE && !isNaN(close) && !isNaN(t)) {
      measure(chainCells);
      measured = moves.expiries() > 0;
    }
  }
  out_iv30(measured ? atm30 * 100.0 : NaN);
  out_iv90(measured ? atm90 * 100.0 : NaN);
  out_term_slope(measured ? slope * 100.0 : NaN);
  out_rr25(measured ? (callWing - putWing) * 100.0 : NaN);
  out_skew_scaled(measured ? skewScaled : NaN);
  out_skew_days(measured ? skewDays : NaN);
  out_rv21(measured ? realized * 100.0 : NaN);
  out_iv_rv_ratio(measured ? overRealized : NaN);
  out_front_days(measured ? frontDays : NaN);
  out_front_move(measured ? frontMove : NaN);
  out_front_move_pct(measured ? frontMovePct : NaN);
  const live = bar.isLast();
  out_term_regime(measured && !isNaN(termCode()) ? termCode() : live ? 1.0 : NaN);
  out_skew_regime(measured && !isNaN(skewCode()) ? skewCode() : live ? 1.0 : NaN);
  out_ivrv_regime(measured && !isNaN(ratioCode()) ? ratioCode() : live ? 1.0 : NaN);
  if (measured) writeWords();
  else if (live) {
    // The live bar carried nothing to measure: the headline says why, so the card is never a row of blanks.
    sb_clear();
    sb_text(chainCells < TUPLE ? "Waiting for the options chain" : "No expiry is still trading");
    str_read_sb();
    sb_clear();
    sb_text("Volatility context, nothing to read yet");
    str_title_sb();
  }
  sigma = NaN;
  sigmaLeft = NaN;
  term930 = NaN;
  tilt = NaN;
  if (measured) measureMore();
  out_sigma(sigma);
  out_sigma_left(sigmaLeft);
  out_sigma_band(bandOf(sigma));
  out_term_9_30(term930);
  out_tilt(tilt);
  if (live) writeMoreWords();
}

How it works

The at-the-money term. ExpectedMoves reads every live expiry's forward, the median underlying its contracts quote, and its at-the-money IV: the mean of the mark IVs listed at the strike nearest that forward. It loads at the chain's as-of, optionsAsOfMs(): the live bar's close time, never its open, on the market's zone, so an OPRA expiry stays live and priced until 15 minutes past its 16:00 stamp. horizonIv(30 / 365) and horizonIv(90 / 365) interpolate between the expiries around each horizon in total variance (IV squared times years), the same at-the-money IV the Expected Move card reads at those horizons. Past the last listed expiry a horizon reads the last expiry's IV. term_slope is iv90 / iv30 - 1 in percent: over +1% is contango (the further month richer, the calm shape), under -1% backwardation (the near month richer, the stressed shape), flat between.

The 25 delta skew. At the expiry whose time to expiry is nearest 30 days, deltaIv() reads the call IV and the put IV where each side's delta is 0.25, interpolated between the two listed strikes around it. skew_scaled is the put IV minus the call IV, over the 30-day IV: above 0.06 the puts are rich (protection costs more than upside), below 0 the calls are rich, flat between. rr25 is the same pair the other way round, call IV minus put IV in vol points, the risk reversal as a desk quotes it: a negative rr25 and a positive skew_scaled say the same thing.

IV against realized. The daily input is the chart's own daily candles, the newest 64 closed ones, kept in a CandleList that every bar feeds. On the live bar the realized volatility is the sample standard deviation of the last rv_days (21) daily log returns, annualized over 252 trading days a year, or over 365 on crypto, which trades every day (the Realized vol year setting picks either by hand). iv_rv_ratio is the 30-day IV over it: above 1 the options price more movement than the market delivered.

The front expiry. The first expiry after today on the market's own calendar (optionsTradeDay(): New York on a US stock, Chicago on CME, UTC on crypto), its days to go, and its expected move: ExpectedMoves.expectedMove(), 0.85 of its at-the-money straddle on its forward at the chain's as-of, in price and in percent of the forward.

Sigma. Every bar notes its trade day on the market's clock (optionsTradeDay()), and the first bar of each trade day opens a session at its open; the run's first trade day opened before the run did, so it has none. On the live bar sigma is the live close minus the session's open over oneSigmaMove(open, iv, 1 / 252), the open times the chain's 1-day IV (ExpectedMoves.horizonIv(1 / 365)) times the square root of one trading day; sigma_left is the budget left (1 minus its size, floored at 0) and sigma_band the band that colours the Sigma tile: muted under 0.5, the text ink under 1, the up or down colour from 1 on. The strip of the past 60 sessions is drawn by Skew history, which reads the daily statistics each past session needs.

Term 9 over 30. IvTerm.iv(9) over IvTerm.iv(30): each constant-maturity at-the-money IV interpolated in total variance between the two anchors around it (expiries after today with an at-the-money IV; before the first anchor its IV, past the last its IV), and none with fewer than two anchors. Under 0.99 is contango (the near IV under the far, the calm shape), over 1.01 backwardation, flat between, the tile naming it beside the ratio (Backwardation, 1.20).

The tilt. The 25 delta put IV minus the call IV at the expiry nearest 30 days, the same deltaIv() pair the skew reads, in vol points: the risk reversal turned round, so tilt is minus rr25. The tile names the cheap side: calls cheap at +0.5 or more (the puts are dearer), puts cheap at -0.5 or less, balanced between (Calls cheap, +1.20 pts).

The card reads the outputs. The headline joins the three verdicts that have a reading, in plain words; the three tiles under it carry each verdict with its number (Contango, +6.20%, Puts rich, 0.083, IV over realized, 1.24x), then the front expected move in price, the 9 over 30 tile, the tilt tile and the Sigma tile, and nine rows: the two IVs, the slope, the risk reversal, the scaled skew, the realized volatility, the ratio, the front move in percent and Sigma's budget left. The title names the front expiry by its label and its days to go (Volatility context, front 16 Oct in 1 day); an expiry in another year reads its year (15 Jan '27).

What the settings do

  • Realized vol, days: How many daily price changes the realized volatility measures: 21 is about a month of trading days.
  • Realized vol year: Days a year the moves scale to: auto picks 365 on crypto, which trades every day, and 252 elsewhere.
  • Interest rate, percent: The rate that projects a US stock's price to each expiry, which futures and crypto options do not need.
  • Volatility: Three verdicts in one line: the term structure, the skew and IV against realized.
  • Term, 90 over 30 days: Contango, the calm and usual shape: 90-day implied volatility tops 30-day by over 1%. Backwardation, the stressed shape with near dates pricier: it trails by over 1%. Flat in between.
  • 25 delta skew: Puts rich (pricier) when the put's implied volatility tops the call's by over 6% of the 30-day level. Calls rich when the put's is lower. Flat in between.
  • IV against realized: The 30-day IV divided by realized volatility: over 1x, options charge more than recent moves.
  • Front expected move: How far options expect the price to move by the next expiry, in price terms.
  • Term, 9 over 30 days: The 9-day IV over the 30-day IV: under 0.99 is contango, over 1.01 backwardation.
  • Tilt, put minus call: The 25 delta put's implied volatility minus the call's: the reverse of the risk reversal line. At +0.5 or more, calls are the cheap side. At -0.5 or less, puts are. In between, it reads balanced.
  • Sigma today: Today's move from the open in 1σ moves (one standard deviation), the size the 1-day IV calls normal.
  • IV, 30 days: The 30-day implied volatility, as a yearly percent.
  • IV, 90 days: The 90-day implied volatility, as a yearly percent.
  • Term slope, %: How far the 90-day IV sits above or below the 30-day IV, in percent.
  • Risk reversal, call minus put: The 25 delta call's IV minus the put's, in IV points: below zero, puts cost more.
  • Skew over IV, put minus call: The put's IV minus the call's, divided by the 30-day IV: the number behind the skew verdict.
  • Realized vol: How much the price actually moved over the last 21 trading days by default, as a yearly percent.
  • IV over realized: The 30-day IV divided by realized volatility.
  • Front move, %: The expected move to the next expiry, in percent of the price.
  • Sigma budget left: How much of a normal day's 1σ move is left, from 1 down to 0.

Where it runs

It works on charts of coins that Deribit (a crypto options exchange) lists options for. Those are BTC, ETH, SOL and the rest of its list. A copy you run from the editor (the code panel beside the chart) reads those coins' options. On a US stock chart it reads that stock's US listed options. On a CME (Chicago futures exchange) futures chart it reads the options on that future. Every indicator reads US listed options, 15 minutes behind unless you have real-time US options data. Every indicator in your browser reads CME options too, once you accept the CME market data terms. They run 10 minutes behind unless you have real-time CME data, and the legend names the source. Editor copies, your published copies and Protected copies (their code stays on OpenMarket's servers) all read US listed options. So does a copy run with Run on Cloud (the editor switch that runs it on OpenMarket's servers). A Protected copy and a Run on Cloud copy do not run on a CME chart. The daily candles come from this chart's own market on every chart.

When data is missing

The headline always says why it has no verdict. It reads "Waiting for the options chain" while the live bar has no options data yet. It reads "No expiry is still trading" when every listed expiry has stopped trading. It reads "No implied volatility in this symbol's options" when no expiry has an at-the-money IV. Each tile says what it lacks. "No term" means the term structure has no reading. "No 25 delta wing" means the expiry nearest 30 days lacks a strike on one side of 25 delta. That happens when the options list only strikes near the price. "Needs 22 daily closes" means there are too few daily candles yet. "Realized vol is zero" means every daily move was the same. The 9 over 30 tile reads "n/a" with fewer than two expiries after today that have an at-the-money IV. The tilt tile reads "n/a" when the expiry nearest 30 days lacks a 25 delta strike on one side. Sigma shows nothing until today has an open, and on charts with bars longer than a day. Lines with no reading show "-".

Customize it

  • A shorter or longer realized window. Set rv_days to 10 for the last two weeks or 60 for a quarter; the stream holds 64 closed days.
  • Another year. Set Realized vol year to 365 on a market that trades every day, or 252 to compare a crypto chart with a stock's numbers.
  • A calendar day on crypto. Sigma prices one trading day as 1/252 of a year on every venue; on a coin that trades every day, set SIGMA_YEARS to 1.0 / 365.0.
  • Another rate. Change Interest rate, percent when short rates move; it only moves a US stock's forwards, so the at-the-money strike and the wings' deltas.

Run it

  1. In the editor's Explorer, press the Templates icon ("Browse starter templates") and pick Volatility Context under HUDs.
  2. Press Run on a BTC chart: the card appears at the bottom centre once the chain arrives, titled by the front expiry.
  3. At the editor's Console prompt, type iv30, term_slope and iv_rv_ratio to read the term and the realized ratio on the live bar, and sigma, term_9_30 and tilt for the three readings beside them.

Concepts used