Speeding Indicator Calculations by Limiting Historical Bars
Summary
The document presents a practical way to reduce the work required when a strategy needs only the latest one or two outputs from a technical indicator. Instead of passing the entire price history into a library function, pass only the recent bars that can affect the requested output. For a rolling moving average of length N, it recommends supplying the latest N bars for the current value, or N plus one when the previous value is also needed.
The reasoning is that a library may calculate the indicator repeatedly across the full input series, even when earlier outputs are unused. Shortening the input can therefore reduce computation. The method depends on the indicator’s memory: rolling indicators may need a bounded window, while recursive calculations can depend on earlier values and require a longer history. The note gives no benchmark or numerical speedup, and users should verify that the retained history is sufficient for the indicator and library implementation they use.
Key ideas
- Pass only the recent price bars needed for the indicator values a strategy will use.
- A rolling indicator of length N generally needs at least N bars for its current value.
- Requesting a preceding value may require retaining an additional bar.
- Recursive indicators can depend on older values and may need a substantially longer history.
- The document explains the optimization but provides no measured speedup.
Tags
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.