Exponentially Weighted Moving Average (EWMA)

62 views (last 30 days)
A-Rod
A-Rod on 3 Apr 2024
Commented: A-Rod on 3 Apr 2024
Hello community, kindly let me ask for your help one more time.
I'm trying to apply this EWMA formula to my data:
EWMA(t) = a * x(t) + (1-a) * EWMA(t-1)
where :
a = the weight decided by the user
x = value of the series in current period
My data is:
EWMA(initial value) = 0.3
a = 0.3
x = [ .15 .11 .11 .1 .09 .12 .11 .09];
using the formula and above values I will get this:
EWMA = 0.3 * 0.15 + (1 - 0.3) * EWMA(initial value) 0.3 = 0.255
then I need to apply the formula to all my data but now using previous EWMA value EWMA(t-1), calculated above
EWMA = 0.3 * 0.11 + (1 - 0.3) * 0.255 = 0.2115
EWMA = 0.3 * 0.11 + (1 - 0.3) * 0.2115 = 0.18105
EWMA = 0.3 * 0.1 + (1 - 0.3) * 0.18105 = 0.1516735
EWMA = 0.3 * 0.09 + (1 - 0.3) * 0.156735 = 0.136714
EWMA = 0.3 * 0.12 + (1 - 0.3) * 0.136714 = 0.131700
EWMA = 0.3 * 0.11 + (1 - 0.3) * 0.131700 = 0.125190
EWMA = 0.3 * 0.09 + (1 - 0.3) * 0.125190 = 0.114633
any recomendation will be higly appreciated.

Answers (1)

Voss
Voss on 3 Apr 2024
Here's how you can perform the calculations you've listed:
% given:
a = 0.3;
x = [0.15 0.11 0.11 0.1 0.09 0.12 0.11 0.09];
N = numel(x);
EWMA = zeros(1,N+1);
EWMA(1) = 0.3; % given
for ii = 2:N+1
EWMA(ii) = a * x(ii-1) + (1-a) * EWMA(ii-1);
end
format long g
disp(EWMA.')
0.3 0.255 0.2115 0.18105 0.156735 0.1367145 0.13170015 0.125190105 0.1146330735

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!