Add 16 period dollar vlm rates, drop ib rates for now

windows_fixes_yo
Tyler Goodlet 2022-02-04 14:44:54 -05:00
parent b358b8e874
commit 5274eb538c
1 changed files with 62 additions and 22 deletions

View File

@ -22,8 +22,15 @@ from tractor.trionics._broadcast import AsyncReceiver
from ._api import fsp from ._api import fsp
from ..data._normalize import iterticks from ..data._normalize import iterticks
from ..data._sharedmem import ShmArray from ..data._sharedmem import ShmArray
from ._momo import _wma
from ..log import get_logger
log = get_logger(__name__)
# NOTE: is the same as our `wma` fsp, and if so which one is faster?
# Ohhh, this is an IIR style i think? So it has an anchor point
# effectively instead of a moving window/FIR style?
def wap( def wap(
signal: np.ndarray, signal: np.ndarray,
@ -131,8 +138,6 @@ async def dolla_vlm(
chl3 = (a['close'] + a['high'] + a['low']) / 3 chl3 = (a['close'] + a['high'] + a['low']) / 3
v = a['volume'] v = a['volume']
from ._momo import wma
# on first iteration yield history # on first iteration yield history
yield { yield {
'dolla_vlm': chl3 * v, 'dolla_vlm': chl3 * v,
@ -203,11 +208,11 @@ async def dolla_vlm(
# our own instantaneous rate calcs which are all # our own instantaneous rate calcs which are all
# parameterized by a samples count (bars) period # parameterized by a samples count (bars) period
# 'trade_rate', 'trade_rate',
# 'dark_trade_rate', 'dark_trade_rate',
# 'dvlm_rate', 'dvlm_rate',
# 'dark_dvlm_rate', 'dark_dvlm_rate',
), ),
curve_style='line', curve_style='line',
) )
@ -236,13 +241,17 @@ async def flow_rates(
) -> AsyncIterator[ ) -> AsyncIterator[
tuple[str, Union[np.ndarray, float]], tuple[str, Union[np.ndarray, float]],
]: ]:
# dvlm_shm = dolla_vlm.get_shm(ohlcv)
# generally no history available prior to real-time calcs # generally no history available prior to real-time calcs
yield { yield {
# from ib
'1m_trade_rate': None, '1m_trade_rate': None,
'1m_vlm_rate': None, '1m_vlm_rate': None,
'trade_rate': None,
'dark_trade_rate': None,
'dvlm_rate': None,
'dark_dvlm_rate': None,
} }
ltr = 0 ltr = 0
@ -255,19 +264,50 @@ async def flow_rates(
vr = quote.get('volumeRate') vr = quote.get('volumeRate')
yield '1m_vlm_rate', vr or 0 yield '1m_vlm_rate', vr or 0
# NOTE: in theory we could dynamically allocate a cascade based on
# this call but not sure if that's too "dynamic" in terms of
# validating cascade flows from message typing perspective.
# attach to ``dolla_vlm`` fsp running
# on this same source flow.
dvlm_shm = dolla_vlm.get_shm(ohlcv)
# precompute arithmetic mean weights (all ones)
seq = np.full((period,), 1)
weights = seq / seq.sum()
async for quote in source: async for quote in source:
if quote: if not quote:
log.error("OH WTF NO QUOTE IN FSP")
continue
dvlm_wma = _wma(
dvlm_shm.array['dolla_vlm'],
period,
weights=weights,
)
yield 'dvlm_rate', dvlm_wma[-1]
# TODO: skip this if no dark vlm is declared
# by symbol info (eg. in crypto$)
dark_dvlm_wma = _wma(
dvlm_shm.array['dark_vlm'],
period,
weights=weights,
)
yield 'dark_dvlm_rate', dark_dvlm_wma[-1]
# XXX: ib specific schema we should # XXX: ib specific schema we should
# probably pre-pack ourselves. # probably pre-pack ourselves.
tr = quote.get('tradeRate') # tr = quote.get('tradeRate')
if tr is not None and tr != ltr: # if tr is not None and tr != ltr:
# print(f'trade rate: {tr}') # # print(f'trade rate: {tr}')
yield '1m_trade_rate', tr # yield '1m_trade_rate', tr
ltr = tr # ltr = tr
vr = quote.get('volumeRate') # # TODO: we *could* do an ohlc3
if vr is not None and vr != lvr: # vr = quote.get('volumeRate')
# print(f'vlm rate: {vr}') # if vr is not None and vr != lvr:
yield '1m_vlm_rate', vr # # print(f'vlm rate: {vr}')
lvr = vr # yield '1m_vlm_rate', vr
# lvr = vr