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