> For the complete documentation index, see [llms.txt](https://docs.vela.exchange/vela-knowledge-base/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.vela.exchange/vela-knowledge-base/exchange/trading/positions/profit-loss-and-roi.md).

# Profit, Loss, and ROI

## Realized Profit and Losses&#x20;

Realized Profit and Loss (rPnL) are used to convey a position's total profit/ loss that has been resolved (paid or received). This includes all accumulated paid fees, such as the Open Position Fee, and is calculated as follows for each $$i$$ of all $$N$$partial closes.

$$
rPnL = paidFees + \sum\_{i=1}^N \begin{cases} (closePrice\_i - avgEntryPrice\_i)\times posQty\_i &\text{if } LONG \ (avgEntryPrice\_i - closePrice\_i)\times posQty\_i &\text{if } SHORT\end{cases}
$$

## Unrealized Profit and Losses&#x20;

Unrealized Profit and Loss (uPnL) track the profit or loss of an open position, taking into account all unpaid accrued fees

$$
uPnL = accruedFees +  \begin{cases} (markPrice - avgEntryPrice)\times posQty &\text{if } LONG \ (avgEntryPrice - markPrice)\times posQty &\text{if } SHORT\end{cases}
$$

Note: Paid fees and/or accrued fees can be either negative (losses to trader) or positive (profits to trader) which occurs in cases where the funding rate is negative (ie: Short position when LongOI > ShortOI).

## Return on Investment (ROI)

Return on Investment is used to establish how profitable a given trade is, and is a key metric in showcasing a trader's ability during competitions. We use the following calculation to determine position ROI for rPnL where max collateral is determined by the greatest number the collateral has reached for the position up until the time of each partial $$i$$ rPnL.

$$
ROI (rPnL) = \sum\_{i=1}^N rPnl\_i/maxCollateral\_i
$$

The ROI for uPnL is simply calculated as follows:

$$
ROI (uPnL) = uPnL/positionCollateral
$$


---

# 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, and the optional `goal` query parameter:

```
GET https://docs.vela.exchange/vela-knowledge-base/exchange/trading/positions/profit-loss-and-roi.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
