@@ -1675,9 +1675,22 @@ def roll_generic(object obj,
1675
1675
return output
1676
1676
1677
1677
1678
- def roll_window (ndarray[float64_t , ndim = 1 , cast = True ] values,
1679
- ndarray[float64_t , ndim = 1 , cast = True ] weights,
1680
- int minp , bint avg = True ):
1678
+ # ----------------------------------------------------------------------
1679
+ # Rolling sum and mean for weighted window
1680
+
1681
+
1682
+ def roll_weighted_sum (float64_t[:] values , float64_t[:] weights ,
1683
+ int minp ):
1684
+ return _roll_weighted_sum_mean(values, weights, minp, avg = 0 )
1685
+
1686
+
1687
+ def roll_weighted_mean (float64_t[:] values , float64_t[:] weights ,
1688
+ int minp ):
1689
+ return _roll_weighted_sum_mean(values, weights, minp, avg = 1 )
1690
+
1691
+
1692
+ def _roll_weighted_sum_mean (float64_t[:] values , float64_t[:] weights ,
1693
+ int minp , bint avg ):
1681
1694
"""
1682
1695
Assume len(weights) << len(values)
1683
1696
"""
@@ -1688,6 +1701,7 @@ def roll_window(ndarray[float64_t, ndim=1, cast=True] values,
1688
1701
1689
1702
in_n = len (values)
1690
1703
win_n = len (weights)
1704
+
1691
1705
output = np.zeros(in_n, dtype = float )
1692
1706
counts = np.zeros(in_n, dtype = float )
1693
1707
if avg:
@@ -1739,6 +1753,7 @@ def roll_window(ndarray[float64_t, ndim=1, cast=True] values,
1739
1753
1740
1754
return output
1741
1755
1756
+
1742
1757
# ----------------------------------------------------------------------
1743
1758
# Exponentially weighted moving average
1744
1759
0 commit comments