In the fields of statistics, data science, and financial analysis, understanding how to track the progression of data over time is crucial. One of the most fundamental tools for this purpose is the Cumulative Moving Average (CMA). Unlike other moving averages that focus on a specific "window" of time, the CMA provides a running average of all data points collected from the beginning of a series up to the current moment.
This makes the CMA an essential metric for understanding long-term trends and the overall behavior of a dataset as it grows.
At its most basic level, the Cumulative Moving Average is simply the arithmetic mean of all observations in a sequence. If we have a set of \( n \) observations, denoted as \( x_1, x_2, \dots, x_n \), the CMA for the \( n \)-th observation is calculated by summing all the values and dividing by the total count of those values.
The standard formula for the CMA at step \( n \) is expressed as:
$$CMA_n = \frac{1}{n} \sum_{i=1}^{n} x_i$$In this equation:
While the standard formula is easy to understand, it becomes computationally expensive as \( n \) becomes very large. To calculate the \( 1,000,000 \)-th average using the standard formula, you would have to sum one million numbers every single time a new data point arrives. This is inefficient for real-time streaming data.
To solve this, we use a recursive formula. This allows us to calculate the current average using only the previous average and the new data point, significantly reducing the computational load.
The recursive formula is defined as:
$$CMA_n = CMA_{n-1} + \frac{x_n - CMA_{n-1}}{n}$$This formula tells us that the new average is the old average plus a fraction of the difference between the new value and the old average. This "correction" term, \( \frac{x_n - CMA_{n-1}}{n} \), ensures that the average shifts appropriately to incorporate the new information.
To understand why the recursive formula works, we can derive it from the standard summation formula. Let's start with the definition of the \( n \)-th average:
$$CMA_n = \frac{x_1 + x_2 + \dots + x_{n-1} + x_n}{n}$$We know that the sum of the first \( n-1 \) terms can be expressed in terms of the previous average: \( \sum_{i=1}^{n-1} x_i = (n-1) \cdot CMA_{n-1} \). Substituting this back into our equation, we get:
$$CMA_n = \frac{(n-1) \cdot CMA_{n-1} + x_n}{n}$$By expanding the numerator, we obtain:
$$CMA_n = \frac{n \cdot CMA_{n-1} - CMA_{n-1} + x_n}{n}$$Finally, splitting the fraction yields the recursive form:
$$CMA_n = \frac{n \cdot CMA_{n-1}}{n} + \frac{x_n - CMA_{n-1}}{n} = CMA_{n-1} + \frac{x_n - CMA_{n-1}}{n}$$It is important to distinguish the CMA from other common types of moving averages used in technical analysis and signal processing:
The Cumulative Moving Average is widely used in various domains where continuous data streams are present: