What is the best formula to get, for example, the 6 month moving average of a stock’s rank for a particular ranking system?
Avg(Rank, RankPrev(5), RankPrev(10), RankPrev(16), RankPrev(21), RankPrev(26))
This averages 6 snapshots of a ranking system rank across a 26-week (~6 month) window.
Rank is the current rank and doesn't count against the 5 RankPrev() call limit.
The five RankPrev() offsets are spaced roughly 5 weeks apart to cover the period evenly.
Avg() handles the arithmetic and automatically discards any NAs. So if a stock didn't exist 26 weeks ago, the average is computed from however many valid samples remain rather than returning NA.
Thanks Walter! Much appreciated
1 Like