I am calculating the time-based EWMA, as defined:
where:
On the following example data frame df:
index time x
0 1 5
1 1.3 4
2 1.4 8
3 2.8 3
For example, at time 3:
I know that in python we can use df['ewma'] = df['x'].ewm(alpha = c)
to calculate the simple ewma, but here c
can only be a fixed float.
My question is: how do I handle changing parameter c? I could iterate through the entire df recursively to get the answers, but it seems really unsophisticated.
Any advice on how I could approach this problem? Thank you in advance!