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
| Symbol | Name | Sector | Price | YTD change |
|---|---|---|---|---|
| CODI | Compass Diversified | Industrials | 13.87 | 198.28 |
| SIVE.ST | Sivers Semiconductors AB (publ) | Technology | 12.42 | 190.19 |
| YUBICO.ST | Yubico AB | Technology | 198.50 | 171.92 |
| NOBI.ST | Nobia AB (publ) | Consumer Cyclical | 11.41 | 161.86 |
| FNM.ST | Ferronordic AB (publ) | Industrials | 114 | 157.34 |
| NANEXA.ST | Nanexa AB (publ) | Healthcare | 9.93 | 146.71 |
| ZAP.OL | Zaptec ASA | Industrials | 57.30 | 131.52 |
| GRANGX.ST | GRANGEX AB | Basic Materials | 26.30 | 129.49 |
| MILDEF.ST | MilDef Group AB (publ) | Industrials | 262.30 | 118.58 |
| EGTX.ST | Egetis Therapeutics AB (publ) | Healthcare | 11.06 | 113.93 |
| CINT.ST | Cint Group AB (publ) | Technology | 5.98 | 108.36 |
| MU | Micron Technology, Inc. | Technology | 646.95 | 105.11 |
| SUS.ST | Surgical Science Sweden AB (publ) | Healthcare | 63.25 | 103.77 |
| IMPC.ST | Impact Coatings AB (publ) | Industrials | 2.95 | 100.68 |
| LILA | Liberty Latin America Ltd. | Communication Services | 9.76 | 97.89 |
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