The Exponential Moving Average (EMA) is a weighted moving average that gives more importance to recent observations. Unlike the Simple Moving Average which weights all values equally, EMA applies exponentially decreasing weights to older data points, making it more responsive to recent changes.
Given a list of numeric values and a smoothing factor alpha (0 < alpha <= 1), compute the EMA for each position.
Initialize with the first value and apply the recursive formula:
EMA[0]=x[0] EMA[t]=α⋅x[t]+(1−α)⋅EMA[t−1]Higher alpha values make the EMA respond faster to recent changes, while lower alpha values produce a smoother signal.
Return one EMA value for each input value.
Input: values = [1, 2, 3, 4, 5], alpha = 0.5
Output: [1, 1.5, 2.25, 3.125, 4.0625]
Explanation: Each new EMA equally weights the current value and the previous EMA.
Input: values = [100, 0, 0, 0], alpha = 0.5
Output: [100, 50.0, 25.0, 12.5]
Initialize the output with the first input value.
Append alpha times the current value plus one minus alpha times the previous EMA.
Sign in to take notes on this problem
Accepts: array
Accepts: number
The Exponential Moving Average (EMA) is a weighted moving average that gives more importance to recent observations. Unlike the Simple Moving Average which weights all values equally, EMA applies exponentially decreasing weights to older data points, making it more responsive to recent changes.
Given a list of numeric values and a smoothing factor alpha (0 < alpha <= 1), compute the EMA for each position.
Initialize with the first value and apply the recursive formula:
EMA[0]=x[0] EMA[t]=α⋅x[t]+(1−α)⋅EMA[t−1]Higher alpha values make the EMA respond faster to recent changes, while lower alpha values produce a smoother signal.
Return one EMA value for each input value.
Input: values = [1, 2, 3, 4, 5], alpha = 0.5
Output: [1, 1.5, 2.25, 3.125, 4.0625]
Explanation: Each new EMA equally weights the current value and the previous EMA.
Input: values = [100, 0, 0, 0], alpha = 0.5
Output: [100, 50.0, 25.0, 12.5]
Initialize the output with the first input value.
Append alpha times the current value plus one minus alpha times the previous EMA.
Sign in to take notes on this problem
Accepts: array
Accepts: number