I have calculated liquidation price using future liquidation price calculation
the problem: only when I use
cumB = 0 i get the correct liquidation price (checked using web platform)
This must be incorrect.
cumB should not be 0 with open position. expectation is that
cumB is maintenance margin calculated using current notional cap and the tax bracket method using the leverage brackets.
here is my python script used to calculate.
- this assumes one position open at a time. hence: tmm & upnl = 0
- this assumes i am using one way instead of hedge mode long&short = 0
def get_liquidation_price(self): # this method ignores the hedge mode # wallet balance wb = self.get_wallet_balance() # @TODO this needs to use other position maintenance margin # maintenance margin of all other contracts, excluding current contract. # if it is an isolated margin mode, then TMM=0 tmm = 0 # @TODO this needs to use other position upnl # unrealized pnl of all other contracts, excluding current contract # if it is an isolated margin mode, then UPNL=0 upnl = 0 # maintenance amount of both position (one-way mode) # unsure what this number is, but its not maintenance margin before liquidation. # perhaps this is the number after liquidation. cumb = 0 # direction of BOTH position, 1 as long position, -1 as short position side1both = 1 if self.__current_trade_side == OrderSide.BUY else -1 # absolute value of BOTH position size (one-way mode) position1both = self.get_current_futures_position_amount() # entry price of BOTH position (one-way mode) ep1both = self.__get_current_futures_position_entry_price() # Maintenance margin rate of BOTH position (one-way mode) mmb = self.__get_maintenance_margin_rate() return (wb - tmm + upnl + cumb - side1both * position1both * ep1both) /\ (position1both * mmb - side1both * position1both)
is there fault in my calculations? this does give correct calculations only when
cumb = 0. any explainations on why
cumb must be 0?