Moving average filter (also known as *rolling average*, *running average*)
is a time series filter which calculates running weighted sum of time series.

ALGLIB package provides you with dual licensed (open source and commercial) implementation of SMA/LRMA/EMA filters in several programming languages, including our flagship products:

- ALGLIB for C++, a high performance C++ library with great portability across hardware and software platforms
- ALGLIB for C#, a highly optimized C# library with two alternative backends: a pure C# implementation (100% managed code) and a high-performance native implementation (Windows, Linux) with same C# interface

1 Moving average filters

SMA (simple moving average)

EMA (exponential moving average)

LRMA (linear regression moving average)

2 Downloads section

Simple moving average filter, denoted as *SMA(k)*, is a finite impulse response filter.
For any moment *t* it returns average of previous *k* values (or *t* values, for *t<k*).
This filter has nice property that for any filter width *k* and time series length *N*
its output can be efficiently calculated in *O(N)* time (no dependence on *k*).

SMA(k) filter is implemented in ALGLIB by the filtersma function. An example of usage can be found in ALGLIB Reference manual: filters_d_sma.

**Note #1**

One major distinction is that between *centered* and *uncentered* versions of the filter.
Former uses both past and future values of time series, i.e. *FILTER(time=t) = AVG(..., x _{t-1 }, x_{t }, x_{t+1 }, ...)*.
Latter uses only past and present values to calculate filter output:

Exponential moving average filter, denoted as *EMA(k)*, is an infinite impulse response filter,
a transformation of time series according to the formula below:

EMA(k) filter is implemented in ALGLIB by the filterlema function. An example of usage can be found in ALGLIB Reference manual: filters_d_ema.

Linear regression moving average filter, denoted as *LRMA(k)*, is a finite impulse response filter,
which fits straight line to a sliding window with width *k*.
Although LRMA filtering costs more than simple or exponential moving average filters
(its running time is *O(N·k)*), linear regression moving average estimate tends to better follow the trend line.

LRMA(k) filter is implemented in ALGLIB by the filterlrma function. An example of usage can be found in ALGLIB Reference manual: filters_d_lrma.

*This article is licensed for personal use only.*

ALGLIB Project offers you two editions of ALGLIB:

**ALGLIB Free Edition**:

delivered for free

offers full set of numerical functionality

extensive algorithmic optimizations

no low level optimizations

non-commercial license

**ALGLIB Commercial Edition**:

flexible pricing

offers full set of numerical functionality

extensive algorithmic optimizations

high performance (SMP, SIMD)

commercial license with support plan

Links to download sections for Free and Commercial editions can be found below:

C++ library.

Delivered with sources.

Monolithic design.

Extreme portability.

Delivered with sources.

Monolithic design.

Extreme portability.

Delivered with sources.

VB.NET and IronPython wrappers.

Extreme portability.

Delphi wrapper around C core.

Delivered as precompiled binary.

Compatible with FreePascal.

Delivered as precompiled binary.

Compatible with FreePascal.

CPython wrapper around C core.

Delivered as precompiled binary.

Delivered as precompiled binary.