Calculations › Market Trends
Show the cumulative return (indexed to 100) across all stocks, last 90 days
The query
-- graph market-wide: cumulative return (indexed to 100) across all stocks, last 90 days
WITH windowed AS (
SELECT tp.ticketnameid, to_timestamp(tp.datetime)::date AS date, tp.price
FROM ticketprice tp JOIN ticketname tn ON tn.id = tp.ticketnameid
WHERE tn.tickettype = 'stock' AND tp.price >= 0.5
AND tp.datetime >= EXTRACT(EPOCH FROM (NOW() - INTERVAL '90 days'))::bigint
),
indexed AS (
SELECT date, ticketnameid,
100 * price / FIRST_VALUE(price) OVER (PARTITION BY ticketnameid ORDER BY date) AS idx_value
FROM windowed
)
SELECT date, AVG(idx_value) AS market_index
FROM indexed GROUP BY date 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
| Date | Market index |
|---|---|
| 2026-07-03 | 100 |
| 2026-07-06 | 99.53 |
| 2026-07-07 | 98.81 |
| 2026-07-08 | 97.24 |
| 2026-07-09 | 97.96 |
| 2026-07-10 | 98.09 |
| 2026-07-13 | 97.91 |
| 2026-07-14 | 97.85 |
| 2026-07-15 | 97.95 |
| 2026-07-16 | 97.95 |
| 2026-07-17 | 97.62 |
| 2026-07-20 | 97.27 |
| 2026-07-21 | 97.52 |
| 2026-07-22 | 97.99 |
| 2026-07-23 | 96.94 |
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