Calculations › Market Discovery
Where does each material sit in its own 52-week range?
The query
-- table market-wide: where each material sits in its own 52-week range
WITH window_prices AS (
SELECT tp.ticketnameid, tp.price, tp.datetime
FROM ticketprice tp JOIN ticketname tn ON tn.id = tp.ticketnameid
WHERE tn.tickettype = 'material'
AND tp.datetime >= EXTRACT(EPOCH FROM NOW())::bigint - 365*86400
),
bounds AS (
SELECT ticketnameid, MIN(price) AS low_52w, MAX(price) AS high_52w
FROM window_prices GROUP BY ticketnameid
),
latest AS (
SELECT DISTINCT ON (ticketnameid) ticketnameid, price AS price_now
FROM window_prices ORDER BY ticketnameid, datetime DESC
)
SELECT tn.ticket AS symbol, COALESCE(NULLIF(sm.name, tn.ticket), tn.ticketname, tn.ticket) AS name,
l.price_now, b.low_52w, b.high_52w,
(l.price_now - b.low_52w) / NULLIF(b.high_52w - b.low_52w, 0) * 100 AS pct_of_52w_range
FROM latest l
JOIN bounds b ON b.ticketnameid = l.ticketnameid
JOIN ticketname tn ON tn.id = l.ticketnameid
LEFT JOIN symbolmetadata sm ON sm.ticketnameid = l.ticketnameid
ORDER BY pct_of_52w_range ASC NULLS LAST
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 | Price | Low 52w | High 52w | % of 52w range |
|---|---|---|---|---|---|
| PL=F | Platinum Jan 27 | 1312.40 | 1241.40 | 2852.40 | 4.41 |
| PA=F | Palladium Dec 26 | 891 | 831.10 | 2169.90 | 4.47 |
| SI=F | Silver Dec 26 | 43.70 | 40.05 | 115.08 | 4.86 |
| GC=F | Gold Dec 26 | 3668.50 | 3515.40 | 5318.40 | 8.49 |
| NG=F | Natural Gas Dec 26 | 3.49 | 2.52 | 7.46 | 19.61 |
| KC=F | Coffee Dec 26 | 280.85 | 244.40 | 411.95 | 21.75 |
| HG=F | Copper Dec 26 | 5.60 | 5.16 | 6.80 | 26.76 |
| ZW=F | Chicago SRW Wheat Futures,Dec-2 | 591 | 506.25 | 767 | 32.50 |
| ZC=F | Corn Futures,Dec-2026 | 463 | 402 | 543 | 43.26 |
| CL=F | Crude Oil Dec 26 | 83.08 | 55.27 | 112.95 | 48.21 |
| BZ=F | Brent Crude Oil Last Day Financial Futures | 90.84 | 58.92 | 118.35 | 53.71 |
| CT=F | Cotton Mar 26 | 81.07 | 61.06 | 91.70 | 65.31 |
| CC=F | Cocoa Dec 26 | 5385 | 2798 | 6650 | 67.16 |
| SB=F | Sugar #11 Mar 27 | 18.81 | 13.31 | 21.13 | 70.33 |
| ZS=F | Soybean Futures,Jan-2027 | 1266.25 | 1023.25 | 1328 | 79.74 |
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