Calculations › Market: Forecasts

Show a symbol's recent price trend with its 7-day and 30-day forecast overlaid (edit the symbol)

The query

WITH hist AS (
  SELECT to_timestamp(tp.datetime)::date AS date, tp.price AS actual_price
  FROM ticketprice tp
  JOIN ticketname tn ON tn.id = tp.ticketnameid
  WHERE tn.ticket = 'AAPL'
  ORDER BY tp.datetime DESC
  LIMIT 60
),
fc AS (
  SELECT
    (ta.computed_at + (substring(ta.analysis_type FROM 'forecast_(\d+)d')::int || ' days')::interval)::date AS date,
    MAX(CASE WHEN ta.analysis_type = 'forecast_7d' THEN (ta.payload->>'price')::float END) AS forecast_7d_price,
    MAX(CASE WHEN ta.analysis_type = 'forecast_30d' THEN (ta.payload->>'price')::float END) AS forecast_30d_price
  FROM ticker_analysis ta
  WHERE ta.ticket = 'AAPL' AND ta.analysis_type IN ('forecast_7d','forecast_30d')
  GROUP BY 1
)
SELECT date, actual_price, NULL::float AS forecast_7d_price, NULL::float AS forecast_30d_price FROM hist
UNION ALL
SELECT date, NULL::float, forecast_7d_price, forecast_30d_price FROM fc
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

DateActual priceForecast 7d priceForecast 30d price
2026-07-08 313.39 — —
2026-07-09 316.22 — —
2026-07-10 315.32 — —
2026-07-13 317.31 — —
2026-07-14 314.86 — —
2026-07-15 327.50 — —
2026-07-16 333.26 — —
2026-07-17 333.74 — —
2026-07-20 326.59 — —
2026-07-21 327.74 — —
2026-07-22 325.89 — —
2026-07-23 321.66 — —
2026-07-24 333.02 — —
2026-07-27 336.91 — —
2026-07-28 340.08 — —

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