I want to calculate a 5-day moving average for each stock, i.e. the resulting table will have the schema:
( date: …; sym: …; mavg: …)
and it will have 75 rows (for each stock, i have 30 days; 5-day moving average means for each stock i will have 25 days * 3 stocks = 75 days) [may be off by 1 somewhere but u get what i mean]
What’s the best way of doing this? wj? sublist each column? Else?
My actual problem is not moving average, but a more complex function, so can’t use mavg for example.
Reason I ask - seems like calculating vector functions over rolling windows of time series tables should be common enough to have a well known idiom.
It really depends on what you are trying to do. wj is probably the most straight forward to use but could be considered a bit brute force. You can sometimes use aj equivalently with better performance (calculating a sum or vwap over a window is a common example). Alternatively look at scan and use that with your function. It’s good to look at some of the k definitions of the in built moving functions and see how they work- mmin for example was an eye opener for me.