PNL

PnL on DerivaDEX falls into two categories: realized and unrealized. PnL is realized when the PNL Settlement takes place. Unrealized PnL factors into your open margin fraction.

PnL settlement

DerivaDEX settles all traders' PNLs periodically. Settlement occurs approximately every 8 hours worth of blocks (~2400 blocks). The settlement frequency can be modified via DerivaDAO governance.

PNL settlement takes place for every open position a trader has with the following two steps:

  1. All unrealized PNL becomes realized PNL: at all points in time, users have a strategy collateral value, which are tokens they rightfully possess (on the exchange, but noncustodially in their, and only their, possession). Open positions also have an unrealized PNL with respect to the mark price that can be thought of as paper profits or losses. When PNL settlement occurs, this unrealized PNL realizes, thereby crediting/debiting your strategy collateral accordingly. Net-net, in some sense, nothing has really changed as your strategy value is unchanged. Moreover, how the exchange considers your strategy when assessing liquidations is also unchanged since margin fraction looks at your strategy value, which as mentioned, is unchanged.

  2. The open position's average entry price resets to the current mark price: Given that DerivaDEX realizes unrealized PNL relative to a given mark price, in order to ensure that the strategy value proceeds as it would have even if PNL settlement were to not have taken place, the average entry price must now be set to the current mark price.

Example

Let's take a look at an example to illustrate. Imagine Alice has deposited 1000 USDC as collateral on DerivaDEX and goes long 5 ETHPERP at a price of 2000 USD. Imagine 8 hours from now, at the time of PNL settlement, the mark price of ETHPERP has risen to 3000 USD.

The following two scenarios demonstrate how PNL settlement works - please take note that scenario 1 is NOT how DerivaDEX handles things. DerivaDEX uses scenario 2. Both are presented, however, to more clearly describe what happens:

  • Scenario 1 (no PNL settlement): Alice has an unrealized PNL of 5000 USD given that she is long 5 ETHPERP contracts and the price has risen by 1000 USD each relative to her average entry price of 2000 USDC. If she were to withdraw, she could withdraw (imagine an unrealistic no-liquidation paradigm for a second where you don't need any collateral to support open positions) a maximum of 1000 USDC since that is her strategy collateral despite her strategy value of 6000 USDC. She could then choose to close her long position to realize the additional 5000 USDC unrealized profit, and then withdraw that amount, reaching the total of 6000 USDC that her strategy was worth.

  • Scenario 2 (PNL settlement): Once again, Alice has an unrealized PNL of 5000 USD given that she is long 5 ETHPERP contracts and the price has risen by 1000 USD each. This unrealized PNL is realized upon PNL settlement, thus her strategy collateral will now actually be 6000 USDC, matching her strategy value of 6000 USDC (although the unrealized component of this is now 0 USDC since the average entry price was just set to the current mark price of 3000 USD). If she were to withdraw, she could withdraw (imagine an unrealistic no-liquidation paradigm for a second where you don't need any collateral to support open positions) a maximum of 6000 USDC since that is her strategy collateral. She could then choose to close her long position that she still has, but this would actually realize 0 USDC of unrealized PNL. In the end, she was able to withdraw the same amount of collateral as in scenario 1, but this approach is much more desirable for traders and versatile, hence is adopted by DerivaDEX.

Unrealized PnL

Your unrealized PnL is the profit or loss that has accrued to your position either since it was opened, or since the last settlement epoch (whichever occurred more recently).

Unrealized_pnl = position_balance * position_side * (mark_price - position_avg_entry_price)

position_side = 1 (long), -1 (short)

Total Unrealized PnL is the unrealized PnL across all positions.

Position balance is the size of your position (i.e., 1 ETHPERP).

Realized PnL

Realized PnL is updated when position are closed or when a settlement epoch occurs.

Last updated