Calculating PNL

Spot Markets

For spot markets, realized profit and loss (rPNL) is calculated based on the difference between the buy and sell prices of an asset. Using the First In, First Out (FIFO) method, the formula is:

rPNL=i=1nQi(Psell,iPbuy,i)\text{rPNL} = \sum\limits_{i=1}^{n} Q_i \cdot (P_{\text{sell},i} - P_{\text{buy},i})

Where:

  • QiQ_i: Quantity of the asset sold in the 𝑖-th transaction.

  • Psell,iP_{\text{sell},i}: Price at which the asset was sold in the 𝑖-th transaction.

  • Pbuy,iP_{\text{buy},i}: Price at which the corresponding quantity of the asset was purchased, based on FIFO.

  • nn: Total number of sell transactions considered.

Example

Let’s calculate rPNL step by step based on the following trades:

  1. Date A: Buy 50 INJ at price P(A)P(A).

  2. Date B: Sell 200 INJ at price P(B)P(B).

  3. Date C: Sell 50 INJ at price P(C)P(C).

  4. Date D: Buy 10 INJ at price P(D)P(D).

  5. Date E: Sell 20 INJ at price P(E)P(E).

Step-by-Step rPNL Calculation

  1. Initial rPNL:

    • At Date A, nothing has been sold, so rPNL = 0.

  2. rPNL at Date B:

    • The user sells 200 INJ but has only bought 50 INJ at P(A)P(A), making them net short by 150 INJ.

    • rPNL=50×(P(B)P(A))rPNL = 50\times (P(B)-P(A))

  3. rPNL at Date C:

    • The user sells another 50 INJ, remaining net short. Since no new purchases have been made, the rPNL calculation remains unchanged:

    • rPNL=50×(P(B)P(A))rPNL = 50\times(P(B) - P(A))

  4. rPNL at Date D:

    • The user buys 10 INJ at P(D)P(D), which does not immediately affect the rPNL.

    • The rPNL remains: 50×(P(B)P(A))50\times(P(B)-P(A)).

  5. rPNL at Date E:

    • The user sells 20 INJ, of which 10 INJ were purchased at P(D)P(D) and the remaining 10 INJ were part of the net short position.

    • The rPNL is calculated as: rPNL=[50×(P(B)P(A))]+[10×(P(E)P(D))]rPNL = [50\times (P(B)-P(A))]+[10\times(P(E)-P(D))]

      • 50×(P(B)P(A))50\times(P(B)-P(A)): Previously accrued PNL from the initial sale of 50 INJ.

      • 10×(P(E)P(D))10\times(P(E)-P(D)): Newly accrued PNL from selling 10 INJ bought at P(D)P(D).

    • At this point, the user remains net short by 190 INJ, as they have sold more INJ than they purchased.

Derivatives Markets

For derivatives markets, rPNL calculation is very straightforward. Herein, rPNL is calculated for each trade when a position is closed. The chain emits detailed trade logs that include the rPNL for each individual trade. These values are then aggregated to determine a trader’s total rPNL.

This approach ensures that rPNL is recorded accurately and in real-time, with additional adjustments made for scenarios like liquidations or funding payments.

Last updated