0

I wanted to verify my calculation for exponentially weighted moving average (EWMA) mean with the built in function of EWM. However, this is in equality in the calculations.

I created a dataframe of random number and then applying EWM and calculating mean. However, there isn't match in the answers.

import pandas as pd
df = pd.DataFrame(np.random.randn(5, 3), columns=['A', 'B', 'C'])
df.ewm(alpha=0.5).mean() # matrix using built in function

# Manual calculations

alpha = 0.5
A0 = df['A'][0]
A1 = alpha * df['A'][1] + (1-alpha) * A0
print((A0+A1)/2)

B0 = df['B'][0]
B1 = alpha * df['B'][1] + (1-alpha) * B0
print((B0+B1)/2)

C0 = df['C'][0]
C1 = alpha * df['C'][1] + (1-alpha) * C0
print((C0+C1)/2)

I'm comparing above 3 print statements with the second row of df.ewm() matrix. It doesn't match. Where am I doing wrong?

0 Answers0