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

# How Yield Accrues

> How each kind of position earns, how the API calculates PnL, and what each APY number means.

Positions earn in different ways depending on where the funds sit. This page explains how each one grows, how the API turns that into PnL, and what each APY field measures, so the numbers you show users are accurate.

## How each position grows

| Position | How it earns | What changes |
| - | - | - |
| **Vault** (Earn) | The vault puts deposits to work and adds the income to its assets. | The number of shares stays the same while each share is worth more. `balance` is the shares' current value in the underlying token. |
| **Aave** (Earn) | Borrowers pay interest to lenders. | The balance itself grows every block. |
| **Pendle PT** ([Fixed Earn](/v2/Products/Fixed-Earn)) | The PT is bought at a discount and redeems at full value at maturity. The discount is the fixed yield. | The PT balance stays the same. Its value moves with market rates before maturity and reaches full value at maturity. |
| **Tokenized assets** | Equities follow the stock price. RWA yield tokens (such as mTBILL) grow through their NAV, the price of one token. | The price. |

## Credit: interest earned and paid

Credit positions don't have a single PnL. Collateral can earn a supply rate (`supply_apy`), and debt grows at the borrow rate (`borrow_apy`). The API reports each side separately:

* `interest_earned` on each collateral position: `amount_supplied + total_withdrawn - total_deposited`
* `interest_paid` on each debt position: `amount_borrowed + total_repaid - total_borrowed`

`total_usd_value` is the account's net value: collateral minus debt.

## How PnL is calculated

Earn and Tokenized Assets calculate PnL with FIFO (first in, first out) cost basis:

1. Every deposit or purchase becomes a lot with its own cost. For a vault, a lot is the shares received and the share price paid.
2. A withdrawal or sale uses up the oldest lots first. `realized_pnl` grows by the amount received minus the cost of the lots used.
3. `unrealized_pnl` is the current value minus the cost of everything still held.
4. `total_pnl` is realized plus unrealized. `total_pnl_percent` divides it by `total_deposited`, the sum of all deposits.

Earn reports PnL in the position's own asset: the underlying token for vaults and Aave, and SY units for Pendle PT. Tokenized Assets reports it in USD, taking the cost from the USDC paid in the same transaction.

### Example

A user makes two deposits into a USDC vault, then withdraws part of the position:

| Step | Share price | Shares | What happens |
| - | - | - | - |
| Deposit 100 USDC | 1.00 | +100 | Lot 1: 100 shares that cost 1.00 each |
| Deposit 50 USDC | 1.02 | +49.02 | Lot 2: 49.02 shares that cost 1.02 each |
| Withdraw 63 USDC | 1.05 | -60 | The 60 shares come from lot 1 and cost 60, so the user realizes a profit of 3 |

What's left is 40 shares from lot 1 (cost 40) and 49.02 shares from lot 2 (cost 50), worth 89.02 × 1.05 = 93.47 USDC. The position then reports:

| Field | Value |
| - | - |
| `total_deposited` | 150 |
| `current_value` | 93.47 |
| `unrealized_pnl` | 93.47 - 90 = 3.47 |
| `realized_pnl` | 3 |
| `total_pnl` | 6.47 |
| `total_pnl_percent` | 6.47 / 150 × 100 = 4.31 |

## What the APY numbers mean

| Field | Where | What it measures | Unit |
| - | - | - | - |
| `apy_7d`, `apy_30d`, `apy_90d` | Earn vault positions | The vault's share-price growth over the last 7, 30 or 90 days, annualized without compounding | Percent: `5.12` = 5.12% |
| `apy` | Earn Aave positions | Aave's current supply rate, compounded every second | Percent |
| `implied_apy` | Earn Pendle PT positions | The fixed rate the market offers new buyers today. A user's own rate was set by the price they paid. | Percent |
| `supply_apy`, `borrow_apy` | Credit positions | The current rates on collateral and debt | Percent |
| `apy_7d`, `apy_30d` | [Tokenized Assets markets](/v2/api-reference/tokenized-assets/list-markets) | NAV growth over the last 7 or 30 days, annualized with compounding. RWA yield assets only. | Fraction: `0.0512` = 5.12% |

<Warning>
  Tokenized Assets APYs are fractions, while every other APY on this page is a percentage. Multiply them by 100 before you show them next to Earn or Credit rates.
</Warning>

None of these numbers is a promise. Vault and Tokenized Assets APYs look back over a window, and Aave and Credit rates change with supply and demand. Only a Pendle PT held to maturity earns a fixed rate. APY fields can be `null`, for example when there isn't enough history yet.

## Good to know

* **Vault APYs are net of the vault's own fees**, because they're measured from the share price.
* **PnL can lag right after a transaction.** The current value is read live from the chain, while PnL is built from indexed transaction history. For a short time after a deposit or withdrawal, the two can disagree.
* **Tokenized Assets PnL is `null` when the cost is unknown**, for example for tokens sent into the account from outside, since there's no purchase price to measure against.
* **Performance fees use the same numbers.** A `PERFORMANCE` [embedded fee](/v2/Products/Embedded-fees) on an Earn withdrawal is a share of that withdrawal's realized profit, calculated with the same FIFO cost basis.

## Next

<Card title="Withdraw Funds" icon="arrow-right" href="/v2/account-lifecycle/withdraw-funds">
  Exit positions and send tokens back to the user's wallet.
</Card>
