diff --git a/piker/fsp/_volume.py b/piker/fsp/_volume.py index 735f3d8b..30397920 100644 --- a/piker/fsp/_volume.py +++ b/piker/fsp/_volume.py @@ -30,7 +30,20 @@ def wap( """ cum_weights = np.cumsum(weights) cum_weighted_input = np.cumsum(signal * weights) - return cum_weighted_input / cum_weights, cum_weighted_input, cum_weights + + # cum_weighted_input / cum_weights + # but, avoid divide by zero errors + avg = np.divide( + cum_weighted_input, + cum_weights, + where=cum_weights != 0 + ) + + return ( + avg, + cum_weighted_input, + cum_weights, + ) async def _tina_vwap( @@ -40,7 +53,6 @@ async def _tina_vwap( ) -> AsyncIterator[np.ndarray]: # maybe something like like FspStream? """Streaming volume weighted moving average. - Calling this "tina" for now since we're using HLC3 instead of tick. """