home | software | utility classes | moving average calculator
An example usage, showing a simple case:
This sample code outputs values:
These values are plotted below, where the pink series is the average over all values, and the blue series is the average over the previous 5 values. Notice how both series are identical until the 6th value, at which point the first value 'falls out' of the moving average's window.
You will also notice the smoothing effect the moving average function in this chart, where a jittery function (blue) is plotted alongside a 5-value and 10-value moving average.
CSV values from which this chart was produced were created using the following code:
Please feel free to provide feedback on this class . Bug reports are most appreciated when accompanied by a failing NUnit test case.
Authored by Drew Noakes, February 2005. Use freely, though keep this message in the source intact and report any bugs to me. I also appreciate seeing extensions, or simply hearing that you're using these classes. You may not copyright this work, though may use it in commercial/copyrighted works. Happy coding.