In the financial domain, we usually need to calculate the value of the aggregate window in the time series data stream, using as an example a moving average, say, we have the following data stream (T is the timestamp, and V is the actual vlaue):
[T0,V0],[T1,V1],[T2,V2],[T3,V3],[T4,V4],[T5,V5],[T6,V6],[T7,V7],[T8,V8],[T9,V9],[T10,1V0],......
to calculate a moving average of 3 from the stream we get:
avg([T0,V0],[T1,V1],[T2,V2]), avg([T1,V1],[T2,V2],[T3,V3]), avg([T2,V2],[T3,V3],[T4,V4]), avg([T3,V3],[T4,V4],[T5,V5]), avg([T4,V4],[T5,V5],[T6,V6]),...
To calculate the moving average, it seems that we could do this:
- build a Observable from the source stream
- build a Observable from the source stream by combining values ββinto groups
- using the aggregate operator to calculate the final results from the Observable in step 2.
Steps 1 and 3 are trivial to implement, however, for step 2 it seems that the current RxJava does not have a built-in operator for creating groups of moving windows, the window / groupBy operator does not seem appropriate in this case, and I did not find an easy way to compose a solution from the existing operators. can anyone suggest how to do this in RxJava "elegantly"?