Calculations › Market Overview

What % of stocks in the market are up today?

The query

-- KPI market-wide: % of stocks up today (market breadth / advance-decline)
WITH latest_two AS (
  SELECT tp.ticketnameid, tp.price,
         LAG(tp.price) OVER (PARTITION BY tp.ticketnameid ORDER BY tp.datetime) AS prev_price,
         ROW_NUMBER() OVER (PARTITION BY tp.ticketnameid ORDER BY tp.datetime DESC) AS rn
  FROM ticketprice tp JOIN ticketname tn ON tn.id = tp.ticketnameid
  WHERE tn.tickettype = 'stock'
    AND tp.datetime >= EXTRACT(EPOCH FROM (NOW() - INTERVAL '10 days'))::bigint
)
SELECT ROUND(100.0 * COUNT(*) FILTER (WHERE price > prev_price) / NULLIF(COUNT(*) FILTER (WHERE prev_price IS NOT NULL),0), 1) AS pct_stocks_up_today
FROM latest_two WHERE rn = 1 AND prev_price IS NOT NULL;

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

% up today
45.10

Live output, first 1 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