Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Moving average
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Cumulative average== In a '''cumulative average''' ('''CA'''), the data arrive in an ordered datum stream, and the user would like to get the average of all of the data up until the current datum. For example, an investor may want the average price of all of the stock transactions for a particular stock up until the current time. 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 ''n'' values <math>x_1. \ldots, x_n</math> up to the current time: <math display="block">\textit{CA}_n = {{x_1 + \cdots + x_n} \over n}\,.</math> 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 points every time a new datum arrived. However, it is possible to simply update cumulative average as a new value, <math>x_{n+1}</math> becomes available, using the formula <math display="block">\textit{CA}_{n+1} = {{x_{n+1} + n \cdot \textit{CA}_n} \over {n+1}}.</math> Thus the current cumulative average for a new datum is equal to the previous cumulative average, times ''n'', plus the latest datum, all divided by the number of points received so far, ''n''+1. When all of the data arrive ({{math|1=''n'' = ''N''}}), then the cumulative average will equal the final average. It is also possible to store a running total of the data as well as the number of points and dividing the total by the number of points to get the CA each time a new datum arrives. The derivation of the cumulative average formula is straightforward. Using <math display="block">x_1 + \cdots + x_n = n \cdot \textit{CA}_n</math> and similarly for {{math|''n'' + 1}}, it is seen that <math display="block">x_{n+1} = (x_1 + \cdots + x_{n+1}) - (x_1 + \cdots + x_n)</math> <math display="block">x_{n+1} = (n + 1) \cdot \textit{CA}_{n + 1} - n \cdot \textit{CA}_n </math> Solving this equation for <math>\textit{CA}_{n+1}</math> results in <math display="block">\begin{align} \textit{CA}_{n+1} & = {x_{n+1} + n \cdot \textit{CA}_n \over {n+1}} \\[6pt] & = {x_{n+1} + (n + 1 - 1) \cdot \textit{CA}_n \over {n+1}} \\[6pt] & = {(n + 1) \cdot \textit{CA}_n + x_{n+1} - \textit{CA}_n \over {n+1}} \\[6pt] & = {\textit{CA}_n} + {{x_{n+1} - \textit{CA}_n} \over {n+1}} \end{align}</math>
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)