Given a table t as
ticker time close
---------------------------------------------
IBM 2025.04.07D09:15:00.000000000 22161.6
IBM 2025.04.08D09:15:00.000000000 22535.85
IBM 2025.04.11D09:15:00.000000000 22828.55
IBM 2025.04.15D09:15:00.000000000 23328.55
IBM 2025.04.16D09:15:00.000000000 23437.
How can I efficiently (using perhaps functional update) update/add, grouped by ticker, columns MA10 ... MA90 to t which are the moving average mavg[n;close] where n ranges from 10 to 90?
Once that's done, how can I efficiently transform these columns MA10 ... MA90 to sMA10 ... sMA90 where depending on whether MA10 >= close we get a BUY signal, or SELL otherwise.
Thirdly, I want to be able to calculate the 'average' column named signal over all the sMA10 ... sMA90 be it either a BUY or SELL.
In other words, I am looking for one-liners instead of writing explicit statements or do loops for accomplishing the above.