EMA

Created
Created
2025 Jan 27 21:41
Creator
Creator
Seonglae Cho
Editor
Edited
Edited
2025 Jan 27 21:48
Refs
Refs

Exponential smoothing or exponential moving average

EMAt=αxt+(1α)EMAt1 \text{EMA}_t = \alpha \cdot x_t + (1 - \alpha) \cdot \text{EMA}_{t-1} 
notion image
import numpy as np import matplotlib.pyplot as plt # Generate noisy data np.random.seed(42) # For reproducibility time = np.arange(1, 101) values = 50 + np.cumsum(np.random.randn(100) * 10) # Large noise # Calculate EMA alpha = 0.3 # Smoothing factor ema_direct = [] alpha = 0.3 for i, value in enumerate(values): if i == 0: ema_direct.append(value) # Initialize EMA with the first value else: ema_direct.append(alpha * value + (1 - alpha) * ema_direct[-1]) # Plot the noisy data and EMA plt.figure(figsize=(10, 6)) plt.plot(time, values, label='Noisy Data', alpha=0.7) plt.plot(time, ema_direct, label='Exponential Moving Average (EMA)', linewidth=2, color='orange') plt.title('Noisy Data with Exponential Moving Average') plt.xlabel('Time') plt.ylabel('Value') plt.legend() plt.grid(True) plt.show()
  • EMA0=x0EMA_0 = x_0
  • EMA applies more weight to the recent data exponentially for interpolation
 
 
 
 

Recommendations