dense_rank max OVER 3 days?
Using CROSS JOIN LATERAL

The output is similar to your output, but please check again. Here's, I using lateral (as loop) to find the max value of someNume for the 3 surrounding days (it doesn't mention about performance).

SELECT tbl.date, tbl.somenum, tbl.name, tbl.elem, t2.max_somenum
FROM tbl
CROSS JOIN LATERAL (
  SELECT MAX(t2.somenum) AS max_somenum
  FROM tbl t2 
  WHERE t2.date &gt;= (tbl.date - interval '3 days') AND t2.date &lt;= (tbl.date + interval '3 days')
) t2
ORDER BY date;