> For the complete documentation index, see [llms.txt](https://docs.battle.fyi/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.battle.fyi/trading/pnl.md).

# P\&L Calculation

Your profit and loss (P\&L) updates in real time. Here's the exact math.

## Unrealized P\&L (open position)

```
Unrealized P&L = direction * ((currentPrice - entryPrice) / entryPrice) * positionSize * leverage
```

Where:

* `direction` = +1 for long, -1 for short
* `currentPrice` = live price from Pyth Network
* `entryPrice` = price when you opened the position
* `positionSize` = the margin you put in (before leverage)
* `leverage` = your leverage multiplier

**Maximum loss is capped at your position size.** You can never lose more than the margin you put in on a single trade.

## Long example

You go long BTC at $60,000 with $1,000 at 10x leverage.

BTC moves to $60,600 (a 1% increase):

```
P&L = 1 * ((60,600 - 60,000) / 60,000) * 1,000 * 10
P&L = 1 * 0.01 * 1,000 * 10
P&L = +$100
```

BTC moves to $59,400 (a 1% decrease):

```
P&L = 1 * ((59,400 - 60,000) / 60,000) * 1,000 * 10
P&L = 1 * (-0.01) * 1,000 * 10
P&L = -$100
```

## Short example

You go short ETH at $3,000 with $500 at 5x leverage.

ETH drops to $2,940 (a 2% decrease):

```
P&L = -1 * ((2,940 - 3,000) / 3,000) * 500 * 5
P&L = -1 * (-0.02) * 500 * 5
P&L = +$50
```

ETH rises to $3,060 (a 2% increase):

```
P&L = -1 * ((3,060 - 3,000) / 3,000) * 500 * 5
P&L = -1 * 0.02 * 500 * 5
P&L = -$50
```

## Portfolio value

```
Portfolio Value = Starting Balance + Realized P&L + Unrealized P&L
```

* **Realized P\&L** = sum of all closed positions' P\&L
* **Unrealized P\&L** = sum of all open positions' current P\&L

## Return %

This is how you're ranked on the leaderboard:

```
Return % = ((Portfolio Value - Starting Balance) / Starting Balance) * 100
```

A return of +5% means your portfolio is worth 5% more than when you started. That's what matters for scoring and elimination.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.battle.fyi/trading/pnl.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
