Use `numpy.divide()` to avoid divide-by-zero
parent
7c7b31ebbe
commit
e89d3f9560
|
@ -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.
|
||||
|
||||
"""
|
||||
|
|
Loading…
Reference in New Issue