Exponentially Weighted Moving Average (EWMA)

66 次查看(过去 30 天)
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.

回答(1 个)

Voss
Voss 2024-4-3
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

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by