(series, beta, n_window)
| 102 | |
| 103 | |
| 104 | def ewma(series, beta, n_window): |
| 105 | nobs = len(series) |
| 106 | scalar = (1 - beta) / (1 + beta) |
| 107 | ma = [] |
| 108 | k = np.arange(n_window, 0, -1) |
| 109 | weights = np.r_[beta**k, 1, beta**k[::-1]] |
| 110 | for t in range(n_window, nobs - n_window): |
| 111 | window = series.iloc[t - n_window:t + n_window + 1].values |
| 112 | ma.append(scalar * np.sum(weights * window)) |
| 113 | return pd.Series(ma, |
| 114 | name=series.name, |
| 115 | index=series.iloc[n_window:-n_window].index) |
| 116 | |
| 117 | |
| 118 | m2_ewma = ewma( |
no test coverage detected
searching dependent graphs…