Change name `be_price` -> `ppu` throughout codebase

ppu_history
Tyler Goodlet 2022-07-27 12:08:13 -04:00
parent a0c238daa7
commit ae71168216
6 changed files with 38 additions and 37 deletions

View File

@ -383,7 +383,7 @@ async def update_and_audit_msgs(
symbol=ibppmsg.symbol, symbol=ibppmsg.symbol,
currency=ibppmsg.currency, currency=ibppmsg.currency,
size=p.size, size=p.size,
avg_price=p.be_price, avg_price=p.ppu,
) )
msgs.append(msg) msgs.append(msg)
@ -430,7 +430,7 @@ async def update_and_audit_msgs(
symbol=p.symbol.front_fqsn(), symbol=p.symbol.front_fqsn(),
# currency=ibppmsg.currency, # currency=ibppmsg.currency,
size=p.size, size=p.size,
avg_price=p.be_price, avg_price=p.ppu,
) )
if validate and p.size: if validate and p.size:
raise ValueError( raise ValueError(

View File

@ -126,7 +126,7 @@ class Allocator(Struct):
l_sub_pp = self.units_limit - abs_live_size l_sub_pp = self.units_limit - abs_live_size
elif size_unit == 'currency': elif size_unit == 'currency':
live_cost_basis = abs_live_size * live_pp.be_price live_cost_basis = abs_live_size * live_pp.ppu
slot_size = currency_per_slot / price slot_size = currency_per_slot / price
l_sub_pp = (self.currency_limit - live_cost_basis) / price l_sub_pp = (self.currency_limit - live_cost_basis) / price
@ -158,7 +158,7 @@ class Allocator(Struct):
if size_unit == 'currency': if size_unit == 'currency':
# compute the "projected" limit's worth of units at the # compute the "projected" limit's worth of units at the
# current pp (weighted) price: # current pp (weighted) price:
slot_size = currency_per_slot / live_pp.be_price slot_size = currency_per_slot / live_pp.ppu
else: else:
slot_size = u_per_slot slot_size = u_per_slot
@ -200,7 +200,7 @@ class Allocator(Struct):
Position( Position(
symbol=sym, symbol=sym,
size=order_size, size=order_size,
be_price=price, ppu=price,
bsuid=sym, bsuid=sym,
) )
) )
@ -229,8 +229,8 @@ class Allocator(Struct):
abs_pp_size = abs(pp.size) abs_pp_size = abs(pp.size)
if self.size_unit == 'currency': if self.size_unit == 'currency':
# live_currency_size = size or (abs_pp_size * pp.be_price) # live_currency_size = size or (abs_pp_size * pp.ppu)
live_currency_size = abs_pp_size * pp.be_price live_currency_size = abs_pp_size * pp.ppu
prop = live_currency_size / self.currency_limit prop = live_currency_size / self.currency_limit
else: else:
@ -303,7 +303,7 @@ def mk_allocator(
# if the current position is already greater then the limit # if the current position is already greater then the limit
# settings, increase the limit to the current position # settings, increase the limit to the current position
if alloc.size_unit == 'currency': if alloc.size_unit == 'currency':
startup_size = startup_pp.size * startup_pp.be_price startup_size = startup_pp.size * startup_pp.ppu
if startup_size > alloc.currency_limit: if startup_size > alloc.currency_limit:
alloc.currency_limit = round(startup_size, ndigits=2) alloc.currency_limit = round(startup_size, ndigits=2)

View File

@ -259,7 +259,7 @@ class PaperBoi:
Position( Position(
Symbol(key=symbol), Symbol(key=symbol),
size=size, size=size,
be_price=price, ppu=price,
bsuid=symbol, bsuid=symbol,
) )
) )
@ -283,7 +283,7 @@ class PaperBoi:
# inferred from the pair? # inferred from the pair?
currency='', currency='',
size=pp.size, size=pp.size,
avg_price=pp.be_price, avg_price=pp.ppu,
) )
await self.ems_trades_stream.send(pp_msg) await self.ems_trades_stream.send(pp_msg)

View File

@ -129,7 +129,7 @@ class Position(Struct):
# "breakeven price" above or below which pnl moves above and below # "breakeven price" above or below which pnl moves above and below
# zero for the entirety of the current "trade state". # zero for the entirety of the current "trade state".
be_price: float ppu: float
# unique backend symbol id # unique backend symbol id
bsuid: str bsuid: str
@ -167,8 +167,8 @@ class Position(Struct):
fqsn = s.front_fqsn() fqsn = s.front_fqsn()
size = d.pop('size') size = d.pop('size')
be_price = d.pop('be_price') ppu = d.pop('ppu')
d['size'], d['be_price'] = self.audit_sizing(size, be_price) d['size'], d['ppu'] = self.audit_sizing(size, ppu)
if self.expiry is None: if self.expiry is None:
d.pop('expiry', None) d.pop('expiry', None)
@ -206,32 +206,32 @@ class Position(Struct):
def audit_sizing( def audit_sizing(
self, self,
size: Optional[float] = None, size: Optional[float] = None,
be_price: Optional[float] = None, ppu: Optional[float] = None,
) -> tuple[float, float]: ) -> tuple[float, float]:
''' '''
Audit either the `.size` and `.be_price` values or equvialent Audit either the `.size` and `.ppu` values or equvialent
passed in values against the clears table calculations and passed in values against the clears table calculations and
return the calc-ed values if they differ and log warnings to return the calc-ed values if they differ and log warnings to
console. console.
''' '''
size = size or self.size size = size or self.size
be_price = be_price or self.be_price ppu = ppu or self.ppu
csize = self.calc_size() csize = self.calc_size()
cbe_price = self.calc_ppu() cppu = self.calc_ppu()
if size != csize: if size != csize:
log.warning(f'size != calculated size: {size} != {csize}') log.warning(f'size != calculated size: {size} != {csize}')
size = csize size = csize
if be_price != cbe_price: if ppu != cppu:
log.warning( log.warning(
f'be_price != calculated be_price: {be_price} != {cbe_price}' f'ppu != calculated ppu: {ppu} != {cppu}'
) )
be_price = cbe_price ppu = cppu
return size, be_price return size, ppu
def update_from_msg( def update_from_msg(
self, self,
@ -243,7 +243,7 @@ class Position(Struct):
symbol = self.symbol symbol = self.symbol
lot_size_digits = symbol.lot_size_digits lot_size_digits = symbol.lot_size_digits
be_price, size = ( ppu, size = (
round( round(
msg['avg_price'], msg['avg_price'],
ndigits=symbol.tick_size_digits ndigits=symbol.tick_size_digits
@ -254,7 +254,7 @@ class Position(Struct):
), ),
) )
self.be_price = be_price self.ppu = ppu
self.size = size self.size = size
@property @property
@ -264,7 +264,7 @@ class Position(Struct):
terms. terms.
''' '''
return self.be_price * self.size return self.ppu * self.size
# TODO: idea: "real LIFO" dynamic positioning. # TODO: idea: "real LIFO" dynamic positioning.
# - when a trade takes place where the pnl for # - when a trade takes place where the pnl for
@ -444,7 +444,7 @@ class Position(Struct):
# in order to make the recurrence relation math work # in order to make the recurrence relation math work
# inside ``.calc_size()``. # inside ``.calc_size()``.
self.size = clear['accum_size'] = self.calc_size() self.size = clear['accum_size'] = self.calc_size()
self.be_price = clear['ppu'] = self.calc_ppu() self.ppu = clear['ppu'] = self.calc_ppu()
return clear return clear
@ -479,7 +479,7 @@ class PpTable(Struct):
info={}, info={},
), ),
size=0.0, size=0.0,
be_price=0.0, ppu=0.0,
bsuid=t.bsuid, bsuid=t.bsuid,
expiry=t.expiry, expiry=t.expiry,
) )
@ -501,7 +501,7 @@ class PpTable(Struct):
# minimize clears tables and update sizing. # minimize clears tables and update sizing.
for bsuid, pp in updated.items(): for bsuid, pp in updated.items():
pp.size, pp.be_price = pp.audit_sizing() pp.size, pp.ppu = pp.audit_sizing()
return updated return updated
@ -534,7 +534,7 @@ class PpTable(Struct):
# if bsuid == qqqbsuid: # if bsuid == qqqbsuid:
# breakpoint() # breakpoint()
pp.size, pp.be_price = pp.audit_sizing() pp.size, pp.ppu = pp.audit_sizing()
if ( if (
# "net-zero" is a "closed" position # "net-zero" is a "closed" position
@ -846,7 +846,8 @@ def open_pps(
clears[tid] = clears_table clears[tid] = clears_table
size = entry['size'] size = entry['size']
be_price = entry['be_price'] # TODO: remove but, handle old field name for now
ppu = entry.get('ppu', entry.get('be_price', 0))
expiry = entry.get('expiry') expiry = entry.get('expiry')
if expiry: if expiry:
@ -855,7 +856,7 @@ def open_pps(
pp = pp_objs[bsuid] = Position( pp = pp_objs[bsuid] = Position(
Symbol.from_fqsn(fqsn, info={}), Symbol.from_fqsn(fqsn, info={}),
size=size, size=size,
be_price=be_price, ppu=ppu,
expiry=expiry, expiry=expiry,
bsuid=entry['bsuid'], bsuid=entry['bsuid'],
@ -868,7 +869,7 @@ def open_pps(
) )
# audit entries loaded from toml # audit entries loaded from toml
pp.size, pp.be_price = pp.audit_sizing() pp.size, pp.ppu = pp.audit_sizing()
try: try:
yield table yield table

View File

@ -106,8 +106,8 @@ async def update_pnl_from_feed(
# compute and display pnl status # compute and display pnl status
order_mode.pane.pnl_label.format( order_mode.pane.pnl_label.format(
pnl=copysign(1, size) * pnl( pnl=copysign(1, size) * pnl(
# live.be_price, # live.ppu,
order_mode.current_pp.live_pp.be_price, order_mode.current_pp.live_pp.ppu,
tick['price'], tick['price'],
), ),
) )
@ -357,7 +357,7 @@ class SettingsPane:
# last historical close price # last historical close price
last = feed.shm.array[-1][['close']][0] last = feed.shm.array[-1][['close']][0]
pnl_value = copysign(1, size) * pnl( pnl_value = copysign(1, size) * pnl(
tracker.live_pp.be_price, tracker.live_pp.ppu,
last, last,
) )
@ -557,7 +557,7 @@ class PositionTracker:
pp = position or self.live_pp pp = position or self.live_pp
self.update_line( self.update_line(
pp.be_price, pp.ppu,
pp.size, pp.size,
self.chart.linked.symbol.lot_size_digits, self.chart.linked.symbol.lot_size_digits,
) )
@ -571,7 +571,7 @@ class PositionTracker:
self.hide() self.hide()
else: else:
self._level_marker.level = pp.be_price self._level_marker.level = pp.ppu
# these updates are critical to avoid lag on view/scene changes # these updates are critical to avoid lag on view/scene changes
self._level_marker.update() # trigger paint self._level_marker.update() # trigger paint

View File

@ -610,7 +610,7 @@ async def open_order_mode(
startup_pp = Position( startup_pp = Position(
symbol=symbol, symbol=symbol,
size=0, size=0,
be_price=0, ppu=0,
# XXX: BLEH, do we care about this on the client side? # XXX: BLEH, do we care about this on the client side?
bsuid=symbol, bsuid=symbol,