Add trade "rates" (i.e. trade counts) support B)

Though it's not per-tick accurate, accumulate the number of "trades"
(i.e. the "clearing rate" - maybe this is a better name?) per bar
inside the `dolla_vlm` fsp and average and report wmas of this in the
`flow_rates` fsp.
windows_fixes_yo
Tyler Goodlet 2022-02-04 16:46:48 -05:00
parent e4244e96a9
commit 73faafcfc1
1 changed files with 29 additions and 9 deletions

View File

@ -115,7 +115,12 @@ async def tina_vwap(
@fsp(
outputs=('dolla_vlm', 'dark_vlm'),
outputs=(
'dolla_vlm',
'dark_vlm',
'trade_count',
'dark_trade_count',
),
curve_style='step',
)
async def dolla_vlm(
@ -145,8 +150,8 @@ async def dolla_vlm(
}
i = ohlcv.index
output = vlm = 0
dvlm = 0
output = dvlm = vlm = 0
dark_trade_count = trade_count = 0
async for quote in source:
for tick in iterticks(
@ -165,8 +170,8 @@ async def dolla_vlm(
li = ohlcv.index
if li > i:
i = li
vlm = 0
dvlm = 0
trade_count = dark_trade_count = dvlm = vlm = 0
# TODO: for marginned instruments (futes, etfs?) we need to
# show the margin $vlm by multiplying by whatever multiplier
@ -178,13 +183,17 @@ async def dolla_vlm(
# print(f'dark_trade: {tick}')
key = 'dark_vlm'
dvlm += price * size
output = dvlm
yield 'dark_vlm', dvlm
dark_trade_count += 1
yield 'dark_trade_count', dark_trade_count
else:
# print(f'vlm: {tick}')
key = 'dolla_vlm'
vlm += price * size
output = vlm
yield 'dolla_vlm', vlm
trade_count += 1
yield 'trade_count', vlm
# TODO: plot both to compare?
# c, h, l, v = ohlcv.last()[
@ -193,8 +202,6 @@ async def dolla_vlm(
# tina_lvlm = c+h+l/3 * v
# print(f' tinal vlm: {tina_lvlm}')
yield key, output
@fsp(
# TODO: eventually I guess we should support some kinda declarative
@ -287,6 +294,12 @@ async def flow_rates(
weights=weights,
)
yield 'dvlm_rate', dvlm_wma[-1]
trade_rate_wma = _wma(
dvlm_shm.array['trade_count'],
period,
weights=weights,
)
yield 'trade_rate', trade_rate_wma[-1]
# TODO: skip this if no dark vlm is declared
# by symbol info (eg. in crypto$)
@ -297,6 +310,13 @@ async def flow_rates(
)
yield 'dark_dvlm_rate', dark_dvlm_wma[-1]
dark_trade_rate_wma = _wma(
dvlm_shm.array['dark_trade_count'],
period,
weights=weights,
)
yield 'dark_trade_rate', dark_trade_rate_wma[-1]
# XXX: ib specific schema we should
# probably pre-pack ourselves.
# tr = quote.get('tradeRate')