> For the complete documentation index, see [llms.txt](https://prerich-app.gitbook.io/prerich-app/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://prerich-app.gitbook.io/prerich-app/advanced/pnl-calculations.md).

# PnL Calculations

On the Prerich portfolio page, you will see a percentage displayed next to each coin you own. This percentage represents your Unrealized Profit and Loss (uPNL), indicating the performance of your investment in each token. Here's how we calculate it:

**Key Terms:**

* **uPNL (Unrealized Profit and Loss)**: The profit or loss on your investment that has not yet been realized.
* **Value**: The current value of your tokens measured in Solana.
* **Initial**: The initial amount spent to purchase the tokens, measured in Solana.
* **Solana Spent**: The amount of Solana used to buy the token.
* **Number of Tokens Sold**: The number of tokens in total you have sold.
* **Initial Token Balance**: The number of tokens you hold before this sell transaction.

**uPNL Calculation Formula:**

<figure><img src="/files/rPzMQcRp2L4dJJM1DeI4" alt=""><figcaption></figcaption></figure>

This formula helps us determine the unrealized profit or loss as a percentage of the initial investment.

**Adjusting Initial Investment:**

Depending on whether you are buying or selling tokens, the initial investment amount needs to be adjusted:

* **If you buy tokens**:
  * The initial investment increases by the amount of Solana spent.

<figure><img src="/files/dYE73vf44jUE5sy8eDU3" alt=""><figcaption></figcaption></figure>

* **If you sell tokens**:

  * The initial investment is adjusted based on the proportion of tokens sold relative to the initial token balance.

  <figure><img src="/files/0GcPa3vcK4bdiiygSxrl" alt=""><figcaption></figcaption></figure>


---

# 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://prerich-app.gitbook.io/prerich-app/advanced/pnl-calculations.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.
