Calculations › Market Discovery

Show the top 20 best year-to-date performing stocks with sector (ideas to research)

The query

-- table market-wide: top 20 best YTD performers (stocks)
WITH latest AS (
  SELECT DISTINCT ON (tp.ticketnameid) tp.ticketnameid, tp.price AS price_now
  FROM ticketprice tp JOIN ticketname tn ON tn.id = tp.ticketnameid
  WHERE tn.tickettype = 'stock'
  ORDER BY tp.ticketnameid, tp.datetime DESC
),
year_start AS (
  SELECT DISTINCT ON (tp.ticketnameid) tp.ticketnameid, tp.price AS price_start
  FROM ticketprice tp JOIN ticketname tn ON tn.id = tp.ticketnameid
  WHERE tn.tickettype = 'stock'
    AND tp.datetime >= EXTRACT(EPOCH FROM DATE_TRUNC('year', NOW()))::bigint
  ORDER BY tp.ticketnameid, tp.datetime ASC
)
SELECT tn.ticket AS symbol, COALESCE(sm.name, tn.ticketname, tn.ticket) AS name, sm.sector,
       l.price_now, (l.price_now - y.price_start) / NULLIF(y.price_start,0) * 100 AS ytd_pct_change
FROM latest l
JOIN year_start y ON y.ticketnameid = l.ticketnameid
JOIN ticketname tn ON tn.id = l.ticketnameid
LEFT JOIN symbolmetadata sm ON sm.ticketnameid = l.ticketnameid
WHERE y.price_start >= 1
  AND ABS((l.price_now - y.price_start) / NULLIF(y.price_start,0) * 100) <= 300
ORDER BY ytd_pct_change DESC
LIMIT 20;

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

SymbolNameSectorPriceYTD change
MU Micron Technology, Inc. Technology 1065.11 237.68
NOBI.ST Nobia AB (publ) Consumer Cyclical 13.72 214.73
INTC Intel Corporation Technology 120.23 205.31
FLUI.ST Fluicell AB (publ) Healthcare 29.30 193.00
AMD Advanced Micro Devices, Inc. Technology 611.76 173.75
NANEXA.ST Nanexa AB (publ) Healthcare 10.54 161.86
GRANGX.ST GRANGEX AB Basic Materials 28.95 152.62
ZAP.OL Zaptec ASA Industrials 62.10 150.91
CINT.ST Cint Group AB (publ) Technology 5.98 108.36
FNM.ST Ferronordic AB (publ) Industrials 92 107.67
IMPC.ST Impact Coatings AB (publ) Industrials 2.95 100.68
MILDEF.ST MilDef Group AB (publ) Industrials 240.50 100.42
HAUTO.OL Höegh Autoliners ASA Industrials 189.80 93.97
VESTUM.ST Cynca Nordic AB (publ) Industrials 16.52 88.80
BWLPG.OL BW LPG Limited Energy 241 88.72

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