Implementing exponentially weighted moving averages in C++ and Python
This is a straightforward coding problem that tests your ability to translate a recurrence relation into clean, efficient code. It appears frequently in quantitative finance interviews because EWMA is a fundamental technique for smoothing noisy time-series data—particularly returns and volatility estimates.
The problem gives you an explicit formula: at each step, blend the current observation with the previous average using a fixed decay parameter (alpha). The key is to iterate through the series up to the terminal day, applying the update rule correctly at each step. Since you only need the previous EWMA value to compute the next one, a single-pass loop with O(1) space is both natural and required. Pay attention to the boundary condition (day 1) and ensure your arithmetic handles floating-point precision appropriately.
- Iterative accumulation and state management
- Off-by-one errors in 1-indexed time series
- Floating-point accuracy in financial calculations