From fa8920758385bd26c1c85a6190a08483b6c924c1 Mon Sep 17 00:00:00 2001 From: Tyler Goodlet Date: Thu, 23 Jun 2022 20:18:59 -0400 Subject: [PATCH] Use sign of the new size which indicates direction of position --- piker/pp.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/piker/pp.py b/piker/pp.py index 1bf3580e..0a67d04f 100644 --- a/piker/pp.py +++ b/piker/pp.py @@ -236,7 +236,7 @@ class Position(Struct): # - in this case we could recalc the be price to # be reverted back to it's prior value before the nearest term # trade was opened.? - dynamic_breakeven_price: bool = False, + # dynamic_breakeven_price: bool = False, ) -> (float, float): ''' @@ -263,12 +263,14 @@ class Position(Struct): # the size increases not when it decreases (i.e. the # position is being made smaller) self.be_price = ( - abs(size) * price # weight of current exec + # weight of current exec = (size * price) + cost + (abs(size) * price) + - copysign(1, size)*cost # transaction cost + (copysign(1, new_size) * cost) # transaction cost + + # weight of existing be price self.be_price * abs(self.size) # weight of previous pp - ) / abs(new_size) + ) / abs(new_size) # normalized by the new size: weighted mean. self.size = new_size