exp_weighted_avg()

Aggregate. Calculates an exponential weighted average.

Syntax

exp_weighted_avg ( expression, period-expression )

Parameters

expression

A numeric expression for which a weighted value is computed.

period-expression

A numeric expression specifying the period for which the average is computed.

Usage

An exponential moving average (EMA) function applies weighting factors to values that decrease exponentially. The weighting for each older data point decreases exponentially, giving more importance to recent observations while not discarding older observations and allowing for descriptive statistical analysis.

The degree of weighting decrease is expressed as a constant smoothing factor α, a number between 0 and 1. α may be expressed as a percentage, so a smoothing factor of 10% is equivalent to α=0.1. Alternatively, α may be expressed in terms of N time periods. For example,

N=19 is equivalent to α=0.1.

The observation at a time period t is designated Yt, and the value of the EMA at any time period t is designated St. S1 is undefined. You can initialize S2 in a number of different ways, most commonly by setting S2 to Y1, though other techniques exist, such as setting S2 to an average of the first four or five observations. The prominence of the S2 initialization's effect on the resultant moving average depends on α; smaller α values make the choice of S2 relatively more important than larger α values, since a higher α discounts older observations faster.

This type of moving average reacts faster to recent price changes than a simple moving average. The 12- and 26-day EMAs are the most popular short-term averages, and they are used to create indicators like the moving average convergence divergence (MACD) and the percentage price oscillator (PPO). In general, the 50- and 200-day EMAs are used as signals of long-term trends.

The weighted average function could be used for benchmarking over a particular time horizon.