#
Mark Price Cap: Preserving Portfolio Correlations During Liquidations
One of the major risks that an exchange trading leveraged products faces is that the bankruptcy of one of its member's accounts can lead to the bankruptcy of the whole exchange. In the world of traditional centralized financial markets, this risk is usually temporarily borne by the exchange when an account is in a situation of bankruptcy until the client sends more equity to the exchange to cover the additional losses it incurred. The exchange can usually tolerate a negative balance on one of the member’s accounts because it has the means to contact and request the additional funds, or even take them forcibly if necessary.
In the world of decentralized financial markets however, this is impossible for 2 reasons. Firstly because every account must have a positive balance at all times. This is often an inviolable constraint of the settlement mechanism itself such as blockchains. Secondly because often the traders themselves are not known by the exchange, or they are out of legal reach of the exchange, so retrieving the funds is not an option.
In this document we will consider a cryptocurrency derivatives exchange where traders can buy and sell a number of Futures contracts. The contracts are marked by an external price source which provide regular indicative price updates for all the instruments. Those prices are used to calculate the profit or losses of an account’s positions. If a mark moves down, long positions are making a loss, meanwhile short positions are making gains. Conversely if a mark moves up, short positions make a loss and long positions make gains. In either direction, due to the leveraged nature of Futures contracts, there is a point where a position has a loss that equates to the accounts deposited funds. At this point, the account is considered bankrupt. If the mark moves past that point, then it has a net negative equity.
Liquidating accounts that have negative equity can lead to the bankruptcy of the exchange itself. The Nekuti engine, like many other platforms, implements a system of mark control where the marks are capped to the first bankruptcy. This ensures that no account can lose more than their available equity as a result of a mark update. The purpose of this document is to explain the principles of the mark capped calculation in the Nekuti Matching Engine.
#
Existing solutions
The problem of liquidating accounts with negative equity has been solved in several different ways that are now considered industry standards.
- Socialized losses: The exchange has a special account called the insurance fund. When accounts get liquidated, their positions and remaining maintenance margin are passed on to the insurance fund. Because of the maintenance margin, the insurance fund can usually hedge those position at a small profit. These profits allow the insurance fund to cover the losses when it liquidates an account with negative equity. If the insurance fund itself has negative equity, a haircut is applied to all profit making traders to cover the gap.
- ADL (Auto-Deleveraging): Similar to the solution above, there is an insurance fund to absorb position and margin of the liquidated accounts. When the insurance fund itself has negative equity, its positions are netted against the positions of other traders, at a price that allows the insurance fund to cover its own losses and ends up flat in positions and balance. Usually the candidates to absorb the insurance funds positions are ranked by some combination of leverage and unrealized pnl.
- Mark Price Cap: In the two approaches above, if the losses are large enough, there may not be sufficient equity on the other side of the position to cover the losses. The winning traders might have closed their positions and walked away with their gains, and the ADL workflow, or the haircut, has to apply to losing traders, which might cause further liquidations. To close this gap, some exchanges implement a mark price cap so that a new mark update cannot leave an account with negative equity. In some implementations, the insurance fund is deleveraged at the previous mark, in other implementation the marks at capped at some safe value between the previous mark and the new mark.
The Nekuti Matching Engine implements a version of ADL + Mark Price Cap where the marks are capped at the first bankruptcy price, that is at the point where the first bankrupt account has exactly 0 equity. This documentation explains how that works.
#
Mathematical Framework
Consider an exchange of n different margined Futures instruments, and their current marked price OP_n (original price of the n-th instrument). A mark update imposes a new set of marks NP_n (new price of the n-th instrument). We consider that the mark updates contains a new mark for every instrument, even if that mark is equal to the previous mark. In a n-dimensional price space, we define the point O, the original prices, as O=\begin{bmatrix} OP_0 \\ ... \\ OP_n \end{bmatrix} and the point N, the new prices, as N=\begin{bmatrix} NP_0 \\ ... \\ NP_n \end{bmatrix}. We can draw the vector \vec{ON}=\begin{bmatrix} NP_0 - OP_0 \\ ... \\ NP_n - OP_n \end{bmatrix}.
In the below example, BTC moves from 112.469 to 110.253 and ETH moves from 4.952 to 3.789
We consider the price movement from O to N to be a continuous slide of marks along the vector \vec{ON}. As prices move along that vector, some accounts might become bankrupt. The aim will be to find out of those accounts, which one becomes bankrupt first, and cap the prices there. In other words, interrupt the price movement at the exact point where the first account reaches 0 equity.
For each account we can draw the bankruptcy line which is made of all the price points where the account has 0 equity. With an account that has an initial balance of B a position in BTC of Q_A entered at price EP_A and a position in ETH of Q_B at EP_B, the bankruptcy line follows the linear equation:
B + Q_A ( x - EP_A ) + Q_B ( y - EP_B ) = 0
In n-dimension the bankruptcy line becomes a n-1 dimension bankruptcy membrane with the following equation: B + \sum_{k=1}^n { Q_k ( x_k - EP_k ) } = 0 where x_k is the price coordinate of the instrument k
In the example below, the account initial balance is 5000, position in BTC is 50 entered at 150 and ETH is 60 entered at 90. The current prices for BTC and ETH are 100 and 100
The positions are long, so as long as the new mark point remains above the bankruptcy line, the account is not bankrupt. If a new mark ticks and comes below the line, the account has negative equity and is bankrupt. This is illustrated in the example below:
#
Sequential Liquidation
One might wonder why this approach is necessary, why not just looking at each instrument. It’s important to consider the whole set of marks together and that the mark movement is a continuous slide from the origin price point to the new price point. Considering mark price caps for each instrument sequentially would mean applying a mark change for the first instrument, capping its mark if an account is bankrupt at the new price, then applying the new mark of the second instrument and so on. This approach prevents accounts with correlated and opposing positions from allowing the gains of one to “save” the other. This type of portfolio is actually quite common. An account might have a position in an instrument and a hedge in another correlated instrument, or simply a swap between a near term and a long term futures for example. Applying mark price cap for each instrument sequentially means that the portfolio doesn’t benefit from the high correlation between the prices of the two opposing positions.
Let's consider an example where an account has two positions opposing each other and that their prices are correlated, so they both move by roughly the same amount. The account has 50 BTC at 110 and -50 ETH at 111. The account initial balance is 500, the current marks are (140, 135) and the proposed marks are (70, 65). As we will see in this scenario, considering mark price cap and liquidation for each instrument independently can have adverse effects, either for the account that gets liquidated when it shouldn't, or for the exchange that caps the marks too aggressively when the account is not bankrupt, potentially leaving other accounts with less risk than they should.
In the next section we will see how the Nekuti Matching Engine solves this problem by always maintaining the proportionality between the movement of all the marks that are included in a mark update. (Even the marks of instruments that the first bankrupt account has no position in)
#
Distance to bankruptcy calculation
Throughout this calculation we will use the following notation:
- Q_n = position size for the nth instrument
- EP_n = entry price for the position on the nth instrument
- OP_n = current (original) price of the nth instrument
- NP_n = new (proposed) price of the nth instrument
- CP_n = capped price of the nth instrument
- B = current account balance
- U(i) = unrealized PnL at mark update i
We consider the mark updates to be a discrete series of price coordinates. We identify each of them by an incremental counter i
At every mark update, the engine considers, for every account:
The total pnl at current mark and new mark:
U(i) = \sum_{k=1}^n { Q_k ( OP_k - EP_k ) }
U(i+i) = \sum_{k=1}^n { Q_k ( NP_k - EP_k ) }
The total equity at the current mark defined as the size of its available margin and the current unrealized pnl of all its positions. We assume this quantity is positive, otherwise the account is already bankrupt and should have been liquidated at the previous mark update.
E = B + U(i)
The sum of all additional losses incurred by the account as a result of the new mark.
L = U(i+1) - U(i)
The ratio between the two quantities tells us how much of the mark movement the account can tolerate and still remain solvent. This ratio is the distance to bankruptcy of the account.
d = -E / L
In practical terms, if an account's current equity is 10, and the new mark creates an additional pnl of -20, the account can only afford to lose half of that (-10), thus the distance to bankruptcy is -E / L = 1/2. If we apply 1/2 of the intended mark movement, the accounts additional losses would equal -10 which exactly matches the current equity, bringing the equity to 0 after the new capped marks are applied.
- A ratio between 0 and 1 means that the account will be bankrupt if we apply the full mark change. As we saw in the example above, a ratio of ½ implies that the marks can only be moved by half of their intended movement before the account reaches 0 equity.
- If the ratio is greater than 1 it means that the account loses equity but remains solvent after the mark update.
- A negative ratio means that the account is profiting overall from this mark update.
All the accounts that have a ratio between 0 and 1 are made bankrupt as a result of the mark change. The account with the smallest ratio is the one that gets bankrupt the earliest. So we apply the distance to bankruptcy ratio d to all the marks that are updated in the next tick. The distance to bankruptcy D_n for the instrument n is the total price movement that can be applied for the account's equity to be 0, as a ratio of the total intended price movement.
D_n = d (NP_n - OP_n)
And the capped price is the original price plus the distance to bankruptcy
CP_n = OP_n + D_n
#
Verification
We calculated a capped mark CPn for every instrument. Let’s verify the consistency of the math by recalculating the total unrealized PnL of the account at the capped mark:
U(i+1) = \sum_{k=1}^n { Q_k (CP_k - EP_k) }\\ U(i+1) = \sum_{k=1}^n { Q_k (OP_k + d (NP_k - OP_k) - EP_k) }\\
Then by recognizing that \sum_{k=1}^n { Q_k (OP_k - EP_k) } = U(i) and \sum_{k=1}^n { Q_k (NP_k - OP_k) } = U(i+1) - U(i) we have :
U(i+1) = U(i) + d ( U(i+1) - U(i) )\\ U(i+1) = U(i) + -(( B + U(i) ) / (U(i+1) - U(i) )) ( U(i+1) - U(i) )\\ U(i+1) = -B\\
With the chosen mark price caps, the total PnL is equal and opposite to the balance, so the total equity is 0. Since PnL is a linear function of the price, we know that if the account had positive equity before and 0 equity at the chosen mark cap, which is only partway along the intended price movement, then that must mean that the equity is negative anywhere after the chosen marks cap.
#
Illustration
Let's consider this practical example.
An account has a position in BTC of 50 entered at 150 and a position in ETH of 60 entered at 90. The account margin balance is 5000.
The current price of BTC is 100 and ETH is 100. The prices drop to 75 and 30 respectively.
First let's calculate the current unrealized pnl of the account.
U(i) = 50 ( 100 - 150 ) + 60 ( 100 - 90 )\\ U(i) = - 2500 + 600\\ U(i) = - 1900
The account is currently losing 1.9m
U(i) = 50 ( 75 - 100 ) + 60 ( 30 - 100 )\\ U(i) = - 1250 - 4200\\ U(i) = - 5450
Due to the new price movement the account loses an additional 5.45m
We calculate the distance to bankruptcy ratio as
d = -(B + U(i)) / (U(i+1) - U(i)) \\ d = -(5000 - 1900) / -5450\\ d = 0.5688073394495413\\
As we can see the distance to bankruptcy ratio is between 0 and 1 which confirms that the account is bankrupted by the new marks. So we apply this ratio to curtail the mark update and limit the losses of the account:
BTC = 100 + 0.5688073394495413 ( 75 - 100 )\\ ETH = 100 + 0.5688073394495413 ( 30 - 100 )\\
BTC = 85.77981651376147\\ ETH = 60.18348623853211\\
Verification: at this price the pnl is
BTC = 50 (85.77981651376147 - 150)\\ ETH = 60 (60.18348623853211 - 90)\\
BTC = -3211.009174311927\\ ETH = -1788.990825688073\\
U(i+1) = -5000 = -B
#
Inverse futures
The Nekuti Matching Engine supports inverse Futures. Those are contracts where the traded asset also serves as the margin currency. For example, in a Bitcoin inverse future, traders post Bitcoin as collateral to trade Bitcoin contracts, with profit/loss calculated in Bitcoin rather than USD. The cost of a position in an inverse Futures is -Q_n / EP_n and the current PnL is calculated as Q_n (1/EP_n - 1/OP_n)
With instruments, we calculate the total pnl as:
U(i) = \sum_{k=1}^n { Q_k ( 1 / EP_k - 1 / OP_k ) }
The bankruptcy line is the solution to the following non-linear equation $$ B + \sum_^n { Q_k ( 1 / EP_k - 1 / x_k ) } = 0
Below is an illustration of the bankruptcy surface in the case of an inverse instrument (BTC) and a linear instrument (ETH)
The non-linear relationship between price and PnL creates complications for bankruptcy distance calculations, making the bankruptcy boundary a hyperbole rather than a straight line. There is no longer a linear relationship between the price space (where coordinates represent instrument prices) and the equity space (where coordinates represent gains or loss of equity). Furthermore, due to the convexity of the bankruptcy surface, there is no guarantee that by capping the price movement at some point along the way, we don't accidentally make an account bankrupt that shouldn't be. As we can see in the graph below, this account does not get bankrupted by the new mark, but if we decide to cap the price movement half way due to another account becoming bankrupt, this account would be bankrupt as well, and we would need to recalculate a new cap.
However, we can turn the problem back into a linear equation by applying a reciprocal transform to the axis in the price space: x \rightarrow -1/x. This changes the coordinates OP_k and NP_k to -1/OP_k and -1/NP_k. We can do this because we know the price space is made of strictly positive coordinates. This is an important constraint that allows to preserve the continuous and monotonous property of the inverse function and transpose the solution of the equation back to the price space.
This moves the equation into the equity space, where it is a linear equation.
B + \sum_{k=1}^n { Q_k ( 1 / EP_k - x_k ) } = 0 where x_k is the inverse of the price of the instrument k
We calculate the factor d in the same way as for Linear futures:
d = -E / L
And, we can calculate the linear distance between the inverse of prices. The price movement between the current mark and the new mark is thus:
D_n = d (1 / OP_n - 1 / NP_n)
In order to calculate the new capped price for instrument n, we need to remember that D_n is a distance between inverted price coordinates. So to calculate the actual capped price, we need to cancel out the -1/x transform. So we subtract the distance instead of adding it, then we invert the result to get back to the price coordinate:
1 / CP_n = 1/OP_n - d (1/OP_n - 1/NP_n))
so
CP_n = 1 / (1/OP_n - d (1/OP_n - 1/NP_n)))
There can be a mix of linear and inverse instruments in the same price space, as long as we apply the reciprocal transform to all the inverse instruments so that the equation to find the bankrupt account remains linear.
We have seen that solving this equation in the linear equity space, allows to cap linearly along the price movement vector and not cause the accidental bankruptcy of an account. But since we cap the price movement linearly in the equity space, how does that translate in the price space ? Can a mark movement no longer enter and exit the bankruptcy surface and cause accidental liquidation ?
When we reverse the reciprocal transform and move back to the price space, we notice that we are not moving linearly from the current price to the new price. Instead, the price vector warps around the bankruptcy surface and never crosses it. Because of the continuous and monotonous property of the reciprocal transform, we know that the equation in the equity space has the same number of solutions than the one in the price space, i.e 0 or 1 solution (remember that the price space is made of strictly positive coordinates). So we know that the price movement will not accidentally enter and exit the bankruptcy surface of an account.
#
Verification
Verification in the case of one linear instrument (1) and one inverse instrument (2):
U(i+1) = Q_1 (CP_1 - EP_1) + Q_2(1/EP_2 - 1/CP_2)\\ U(i+1) = Q_1 (OP_1 + d (NP_1 - OP_1) - EP_1) + Q_2 (1 / EP_2 - 1/OP_2 + d (1/OP_2 - 1/NP_2)) \\ U(i+1) = Q_1 (OP_1 - EP_1) + Q_2 (1 / EP_2 - 1/OP_2 ) + d (Q_1 (NP_1 - OP_1) + Q_2 (1/OP_2 - 1/NP_2)) \\ U(i+1) = U(i) + d (U(i+1) - U(i)) \\ U(i+1) = U(i) - (B + U(i)) (U(i+1) - U(i)) / (U(i+1) - U(i)) \\ U(i+1) = - B\\