I have a stream of market data events with (Price, Trade Time) properties.
I want to calculate the simple average for past time windows for every new market data event. Simple average = Sum of trade prices / # of events
However, the tricky part is that I want to calculate this for multiple sub-timewindows from the current event time. So, say the simple average for [t-0 min, t-2 min] , [t-2 min, t-4 min], [t-4 min, t-6 min], ...
These time windows would be recalculated for each new event.
Right now I just use multiple streams and sum up the prices and events over [t-0 min, t-2 min], [t-0 min, t-4 min], t-0 min, t-6 min], ... and find their individual simple averages through subtraction. There must be a better way of doing this, possible using only one or two streams?