@@ -1489,7 +1489,7 @@ def roll_weighted_var(const float64_t[:] values, const float64_t[:] weights,
1489
1489
1490
1490
def ewma (const float64_t[:] vals , const int64_t[:] start , const int64_t[:] end ,
1491
1491
int minp , float64_t com , bint adjust , bint ignore_na ,
1492
- const float64_t[:] deltas ) -> np.ndarray:
1492
+ const float64_t[:] deltas = None ) -> np.ndarray:
1493
1493
"""
1494
1494
Compute exponentially-weighted moving average using center-of-mass.
1495
1495
@@ -1502,7 +1502,8 @@ def ewma(const float64_t[:] vals, const int64_t[:] start, const int64_t[:] end,
1502
1502
com : float64
1503
1503
adjust : bool
1504
1504
ignore_na : bool
1505
- deltas : ndarray (float64 type )
1505
+ deltas : ndarray (float64 type ), optional. If None , implicitly assumes equally
1506
+ spaced points (used when `times` is not passed )
1506
1507
1507
1508
Returns
1508
1509
-------
@@ -1511,14 +1512,17 @@ def ewma(const float64_t[:] vals, const int64_t[:] start, const int64_t[:] end,
1511
1512
1512
1513
cdef:
1513
1514
Py_ssize_t i , j , s , e , nobs , win_size , N = len (vals), M = len (start)
1514
- const float64_t[:] sub_deltas , sub_vals
1515
+ const float64_t[:] sub_vals
1516
+ const float64_t[:] sub_deltas = None
1515
1517
ndarray[float64_t] sub_output , output = np.empty(N, dtype = np.float64)
1516
1518
float64_t alpha , old_wt_factor , new_wt , weighted_avg , old_wt , cur
1517
- bint is_observation
1519
+ bint is_observation , use_deltas
1518
1520
1519
1521
if N == 0:
1520
1522
return output
1521
1523
1524
+ use_deltas = deltas is not None
1525
+
1522
1526
alpha = 1. / (1. + com)
1523
1527
old_wt_factor = 1. - alpha
1524
1528
new_wt = 1. if adjust else alpha
@@ -1529,7 +1533,8 @@ def ewma(const float64_t[:] vals, const int64_t[:] start, const int64_t[:] end,
1529
1533
sub_vals = vals[s:e]
1530
1534
# note that len(deltas) = len(vals) - 1 and deltas[i] is to be used in
1531
1535
# conjunction with vals[i+1]
1532
- sub_deltas = deltas[s:e - 1 ]
1536
+ if use_deltas:
1537
+ sub_deltas = deltas[s:e - 1 ]
1533
1538
win_size = len (sub_vals)
1534
1539
sub_output = np.empty(win_size, dtype = np.float64)
1535
1540
@@ -1547,7 +1552,10 @@ def ewma(const float64_t[:] vals, const int64_t[:] start, const int64_t[:] end,
1547
1552
if weighted_avg == weighted_avg:
1548
1553
1549
1554
if is_observation or not ignore_na:
1550
- old_wt *= old_wt_factor ** sub_deltas[i - 1 ]
1555
+ if use_deltas:
1556
+ old_wt *= old_wt_factor ** sub_deltas[i - 1 ]
1557
+ else :
1558
+ old_wt *= old_wt_factor
1551
1559
if is_observation:
1552
1560
1553
1561
# avoid numerical errors on constant series
0 commit comments