Skip to main content
Track Exponential smoothing
5 / 41
Library

1990issue C041-2

Integer construction of moving averages and exponential smoothing

Integer arithmetic can be much faster than floating-point arithmetic on many computer systems, but overflow and results smaller than one make moving-average construction harder. Editorial reading: a moving-average or exponential-smoothing forecast built from ordered prices is unfinished until overflow limits, multiply-before-divide order, and an integer-safe smoother algebra are stated explicitly.

  • Integer arithmetic can be much faster than floating-point arithmetic on many computer systems, but integer overflow and results smaller than one make moving-average construction harder.
  • Overflow is most likely in long-lookback linear moving averages, where summed weights can reach the tens of thousands. A 200-period linear moving average of integer prices between 200000 and 300000, with total weight 20100, can push an intermediate weighted sum above 4 billion and past the 32-bit signed ceiling of 2147483647.
  • In integer arithmetic the order of multiply and divide changes the result: with factors 2, 1, and 2, multiplying first then dividing yields 1, while dividing first yields 0. Accurate construction uses deferred division, which simple and linear moving averages typically already do.
  • The usual exponential-smoothing factor of 2 divided by lookback plus one cannot be stored in an integer variable. An equivalent update adds the previous smoothed value to twice the current residual and divides last by a precomputed lookback plus one.
Entries in this reading2 entries

Integer arithmetic and moving-average construction

Integer arithmetic can be much faster than floating-point arithmetic on many computer systems, but overflow and results smaller than one make moving-average construction harder.

A simple moving average equally weights a fixed lookback of ordered observations and is usually accumulated first, then divided once at the end. A linear moving average is a recency-weighted average whose weights rise in a straight line, so the sum of the weights grows quickly with lookback and can overflow an integer accumulator. Exponential smoothing is a recursive forecast that blends the latest observation with the previous smoothed value, conventionally through a factor of two divided by lookback plus one.

Overflow in long-lookback linear averages

Integer overflow is a running product or sum that exceeds the largest representable integer, including the 32-bit signed ceiling of 2147483647. Overflow is most likely in long-lookback linear moving averages because the summed weights can reach the tens of thousands.

A 200-period linear moving average of a price series stored as integers between 200000 and 300000, with total weight 20100, can produce an intermediate weighted sum above 4 billion, which exceeds that 32-bit signed maximum.

Construction can limit overflow by dividing a running weighted sum before it exceeds the integer range, by trapping overflow and switching to floating-point arithmetic, or by scaling stored prices so the product-sum cannot overflow.

When multiply and divide change places

In integer arithmetic the order of multiply and divide changes the result. With factors 2, 1, and 2, multiplying first then dividing yields 1, while dividing first yields 0.

That early divide is truncation: loss of a fractional result when integer division is performed before later multiplications, collapsing a nonzero quantity to zero. Accurate integer construction postpones division until the last step. Deferred division rearranges a moving-average or smoothing formula so every multiplication finishes before a single terminal division, which simple and linear moving averages typically already do.

An integer update for exponential smoothing

The usual exponential-smoothing factor of 2 divided by lookback plus one is a fraction between 0 and 1 and cannot be stored in an integer variable.

An equivalent integer exponential update adds the previous smoothed value to twice the current residual and divides last by lookback plus one, a denominator that can be precomputed. That keeps the smoother inside the same deferred-division discipline used for the averages.

Educational research material, not investment advice. Historical source context does not establish present-day performance.
5 of 41 in the Exponential smoothing track
19901-11 pp.Next on Exponential smoothingConstructing incremental moving average filtersWhen many dates are required, a routine that fills an entire output series in one pass avoids repeating a single-date average call at each date.
All readings on this track · 41 readings
  1. 1984Matching average age across price filters
  2. 1984Residual-impact construction of exponential smoothers
  3. 1988Constructing simple and exponential moving averages as specified filters
  4. 1989Evaluating smoothed free reserves and funds-discount spreads
  5. 1990Integer construction of moving averages and exponential smoothing
  6. 1990Constructing incremental moving average filters
  7. 1991Constructing a double-smoothed stochastic oscillator
  8. 1991Constructing an exponential average from a smoothing weight
  9. 1991Constructing a double-smoothed momentum oscillator family
  10. 1991Competing certainty rules from exponential-average conditions
  11. 1991Hybrid construction of a mechanical timing system from smoothed signals
  12. 1991Constructing an exponential smoother from a moving-average length
  13. 1991Equivalent relative-strength-index constructions from a ratio and from smoothed momentum
  14. 1991Constructing the true strength index from double-smoothed momentum
  15. 1991True strength index from signed, double-smoothed momentum
  16. 1992Constructing exponential averages from simple lookbacks
  17. 1992Constructing exponential averages by the smoothing constant, startup length and lag
  18. 1992Nested range smoothing and windowed high-low damping
  19. 1992A weekly equity stance from the discount-bill spread
  20. 1993Double-smoothed stochastics momentum index construction
  21. 1993Constructing the true strength index with double exponential smoothing
  22. 1994Polarized fractal efficiency with a shared exponential smoother
  23. 1994Five-interval exponential smoothing of ten-interval signed path-efficiency
  24. 1994Hand-ranked price-volume series with stacked smoothing and stochastic
  25. 1995Range expansion filter on multi-horizon averages
  26. 1995The exponential smoothing constant from averaging lag
  27. 1997Construct a nested-average rainbow band and oscillator
  28. 1998Filter stacks that combine a moving average with exponential smoothing
  29. 2002Smoothed relative-strength construction from wilder-averaging and a price prefilter
  30. 2003Reverse-engineered RSI price targets
  31. 2004Piecewise trend quality from moving-average reversals
  32. 2004Nested smoothing recipes versus unaudited oscillator experiments
  33. 2008Weight construction beyond the N-day label
  34. 2010A consensus filter for objective RSI and smoothing construction
  35. 2012Sentiment-zone oscillator from signed closes
  36. 2012Classic RSI one-over-N smoothing versus the standard exponential average
  37. 2013Why exponential smoothing uses two over n plus one
  38. 2015Constructing ratio indicators with moving-average and exponential-smoothing weights
  39. 2015Slow relative-strength index from an exponentially smoothed price
  40. 2017Rebuilding the relative strength index as open-scale buy-sell pressure
  41. 2017Comparing Wilder and exponential smoothing inside a relative-strength index
All 183 readings tagged Exponential smoothing
Also on Exponential smoothing5 readings