From b358b8e874a2645bf6cd14ee762b98f38c032629 Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Fri, 4 Feb 2022 12:10:44 -0500 Subject: [PATCH] Move `wma` fsp earlier in module --- piker/fsp/_momo.py | 52 +++++++++++++++++++++++----------------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/piker/fsp/_momo.py b/piker/fsp/_momo.py index 29e94f98..01e41c04 100644 --- a/piker/fsp/_momo.py +++ b/piker/fsp/_momo.py @@ -170,6 +170,32 @@ def _wma( return np.convolve(signal, weights, 'valid') +@fsp +async def wma( + + source, #: AsyncStream[np.ndarray], + length: int, + ohlcv: np.ndarray, # price time-frame "aware" + +) -> AsyncIterator[np.ndarray]: # maybe something like like FspStream? + ''' + Streaming weighted moving average. + + ``weights`` is a sequence of already scaled values. As an example + for the WMA often found in "techincal analysis": + ``weights = np.arange(1, N) * N*(N-1)/2``. + + ''' + # deliver historical output as "first yield" + yield _wma(ohlcv.array['close'], length) + + # begin real-time section + + async for quote in source: + for tick in iterticks(quote, type='trade'): + yield _wma(ohlcv.last(length)) + + @fsp async def rsi( @@ -224,29 +250,3 @@ async def rsi( down_ema_last=last_down_ema_close, ) yield rsi_out[-1:] - - -@fsp -async def wma( - - source, #: AsyncStream[np.ndarray], - length: int, - ohlcv: np.ndarray, # price time-frame "aware" - -) -> AsyncIterator[np.ndarray]: # maybe something like like FspStream? - ''' - Streaming weighted moving average. - - ``weights`` is a sequence of already scaled values. As an example - for the WMA often found in "techincal analysis": - ``weights = np.arange(1, N) * N*(N-1)/2``. - - ''' - # deliver historical output as "first yield" - yield _wma(ohlcv.array['close'], length) - - # begin real-time section - - async for quote in source: - for tick in iterticks(quote, type='trade'): - yield _wma(ohlcv.last(length))