> ## Documentation Index
> Fetch the complete documentation index at: https://docs.derivadex.com/llms.txt
> Use this file to discover all available pages before exploring further.

# PnL Realization and Settlement

> How DerivaDEX realizes PnL: fill-time realization, periodic settlement every 24 hours, mark-price-based collateral updates, and average-entry-price resets on open positions.

DerivaDEX tracks unrealized PnL on open positions continuously, then realizes that PnL into USDC collateral at defined points.

## How PnL is realized

PnL becomes realized in two different ways.

| Path                    | When it happens                        | What changes                                                                            |
| ----------------------- | -------------------------------------- | --------------------------------------------------------------------------------------- |
| Trade-fill realization  | When a fill closes or reduces exposure | The fill realizes trade PnL immediately into strategy collateral                        |
| Periodic PnL settlement | At the periodic settlement boundary    | The remaining unrealized PnL on each open position is realized into strategy collateral |

Periodic PnL settlement is separate from funding. A settlement cycle can contain both actions, but they are not the same calculation.

## Periodic settlement calculation

At periodic settlement, DerivaDEX marks each open position to the current **mark price** (the fair-risk price used for margin and liquidation), realizes that unrealized PnL into USDC collateral, and resets the position's average entry price to the settlement mark.

```text theme={null}
settlement_pnl = unrealized_pnl(mark_price)
new_collateral = old_collateral + settlement_pnl
new_avg_entry_price = mark_price
position_size and side stay the same
```

| Effect              | Result                                   |
| ------------------- | ---------------------------------------- |
| Unrealized gain     | Credited to strategy collateral in USDC  |
| Unrealized loss     | Debited from strategy collateral in USDC |
| Average entry price | Reset to the settlement mark price       |
| Position size       | Unchanged                                |
| Position side       | Unchanged                                |

If the unrealized PnL on a position is zero at the settlement mark, the periodic settlement step does not change collateral for that position.

## Timing

Periodic PnL settlement runs on its own cadence inside the broader settlement-epoch schedule.

| Parameter              |               Value | Notes                                                                                    |
| ---------------------- | ------------------: | ---------------------------------------------------------------------------------------- |
| PnL settlement cadence |    Every `24` hours | The public baseline realizes open-position PnL once every three 8-hour settlement epochs |
| Price input            |          Mark price | The same fair-risk price used for margin and liquidation                                 |
| Balance updated        | Strategy collateral | The result is a `STRATEGY_UPDATE` with reason `PnlSettlement`                            |
| Markets covered        |     Perpetual swaps | The public product set does not currently include expiry contracts                       |

## Relationship to other balance changes

PnL settlement is one of several ways a strategy balance can change.

| Balance change              | Event reason                            | Notes                                               |
| --------------------------- | --------------------------------------- | --------------------------------------------------- |
| Deposit or withdrawal       | `Deposit`, `Withdraw`, `WithdrawIntent` | On-chain collateral movements                       |
| Trade fill                  | `Trade`                                 | Fill-time realized PnL and non-DDX fees             |
| Periodic PnL settlement     | `PnlSettlement`                         | Realizes remaining unrealized PnL on open positions |
| Funding                     | `FundingPayment`                        | Periodic transfer between longs and shorts          |
| Fees in collateral currency | `Fee`                                   | Charged in USDC when fees are not paid in DDX       |

When a settlement cycle contains both periodic PnL settlement and funding, PnL settlement happens first and funding follows.

## Worked settlement cases

These examples show the periodic settlement step for one open position.

| Position before settlement                | Settlement mark | Periodic settlement result                                         |
| ----------------------------------------- | --------------: | ------------------------------------------------------------------ |
| Long `1` ETHP with average entry `2,000`  |         `2,050` | `+50` USDC realized to collateral; average entry resets to `2,050` |
| Long `1` ETHP with average entry `2,000`  |         `1,950` | `-50` USDC realized to collateral; average entry resets to `1,950` |
| Short `2` ETHP with average entry `2,000` |         `1,980` | `+40` USDC realized to collateral; average entry resets to `1,980` |

## Related references

* [Margin Requirements](/reference-public/margin-requirements)
* [Price Feeds and Mark Price Inputs](/reference-public/price-feeds-and-mark-price-inputs)
* [Funding Rate Logic](/reference-public/funding-rate-logic)
* [Product and Trading Specifications](/reference-public/product-and-trading-specifications)
* [Order and Account Event Reference](/reference-public/order-and-account-event-reference)
