An Exact, Efficient Simple Moving Average Implementation
Summary
The document introduces an implementation of the simple moving average intended to address shortcomings the author sees in existing versions. It argues that some implementations become slower as the lookback period grows because they repeatedly loop over data, while others use shortcuts that approximate the exact average. It also says some are difficult to use.
The proposed version is described as exact, efficient across longer periods, and straightforward to use, including from code. The document gives no algorithm, code, benchmark, or numerical comparison to substantiate those claims, so readers cannot assess its speed or accuracy from the text alone. It notes that moving the implementation out of a class and into the main loop might improve speed slightly, at the cost of flexibility and reuse. The material is therefore a brief motivation for an implementation, rather than a full explanation of how to calculate or apply the indicator.
Key ideas
- The author identifies repeated looping as a possible cause of slower moving average calculations over longer periods.
- Some implementations may trade exactness for an approximate shortcut.
- The proposed version is presented as exact and easier to use, but its implementation details and benchmarks are not provided.
- Moving code into the main loop is suggested as a possible minor speed improvement, with reduced flexibility as a tradeoff.
Tags
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.