Calculations › Market Trends

Show a rolling 30-day volatility trend for the stock market, last 180 days

The query

-- graph market-wide: rolling 30-day volatility trend for the stock market, last 180 days
WITH daily AS (
  SELECT to_timestamp(tp.datetime)::date AS date, AVG(tp.price) AS avg_price
  FROM ticketprice tp JOIN ticketname tn ON tn.id = tp.ticketnameid
  WHERE tn.tickettype = 'stock'
    AND tp.datetime >= EXTRACT(EPOCH FROM (NOW() - INTERVAL '180 days'))::bigint
  GROUP BY 1
),
daily_return AS (
  SELECT date, (avg_price - LAG(avg_price) OVER (ORDER BY date)) / NULLIF(LAG(avg_price) OVER (ORDER BY date),0) * 100 AS ret
  FROM daily
)
SELECT date, STDDEV(ret) OVER (ORDER BY date ROWS BETWEEN 29 PRECEDING AND CURRENT ROW) AS rolling_volatility_30d
FROM daily_return
ORDER BY date;

Runs against Cryptobi's market tables — ticketname (symbols), ticketprice (daily prices and volume) and symbolmetadata (sector, exchange, market cap and other reference fields).

Current output

DateRolling volatility 30d
2026-04-06 —
2026-04-07 —
2026-04-08 21.98
2026-04-09 17.17
2026-04-10 14.75
2026-04-13 13.10
2026-04-14 11.97
2026-04-15 11.04
2026-04-16 10.30
2026-04-17 9.74
2026-04-20 9.20
2026-04-21 8.74
2026-04-22 8.35
2026-04-23 8.01
2026-04-24 7.70

Live output, first 15 rows, refreshed periodically. Model estimates are trend projections from recent prices, not financial advice.

Run this on your own holdings, change it, or write your own in SQL or Python — then put it on a dashboard or have it emailed on a schedule. Free, no credit card.

Sign Up Free

Related calculations