Jump to content

Moving Average/Cumulative Moving Average

From Wikiversity


Cumulative moving average - discrete

[edit | edit source]

In a cumulative moving average, the data arrive in an ordered datum stream with , and the user would like to get the average of all of the data up until the current datum point . For example, an investor may want the average price of all of the stock transactions for a particular stock up until the current time . The starting point of data collection is . As each new transaction occurs, the average price at the time of the transaction can be calculated for all of the transactions up to that point using the cumulative average, typically an equally weighted average of the sequence of t+1 values up to the current time :

The brute-force method to calculate this would be to store all of the data and calculate the sum and divide by the number of datum points every time a new datum point arrived. However, it is possible to simply update cumulative average as a new value, becomes available, using the formula:

Thus the current cumulative average for a new datum point is equal to the previous cumulative average at time t-1, times t, plus the latest datum point, all divided by the number of points received so far, n+1. When all of the datum points arrive (), then the cumulative average will equal the final average. It is also possible to store a running total of the datum point as well as the number of points and dividing the total by the number of datum points to get the CMA each time a new datum point arrives.

The derivation of the cumulative average formula is straightforward. Using

and similarly for t + 1, it is seen that

Solving this equation for results in:

Cumulative moving average - continuous

[edit | edit source]

If we consider a continuous measurement of values e.g. a force at time . The objective is to smooth the values with a continous aggregated moving average. We look a time span in the past. As probability distribution we use a uniform distribution (mathematics) for the intervall . The density function is:

.

Application on the cumulative moving average definition in time for continuous probability distriubtions we get: