# Yield Calculation

## Understand Yield in Stella

In Stella, the definition of **"Yield"** is the **remaining value** of the position in US dollars at the time of closing the position after repaying the debts and returning the leveragoors’ initial input.

$$
\text{Yield} = \text{PositionValue}-\text{BorrowValue}-\text{InputValue}
$$

Where the value of each part is calculated as follows

$$
\text{PositionValue} = \text{LPTokenAmount} \cdot \text{Price}*{\text{LPToken}} + \text{RewardTokenAmount} \cdot \text{Price}*{\text{RewardToken}}
$$

$$
\text{BorrowValue} = \text{BorrowAmount} \cdot \text{Price}\_{\text{BorrowToken}}
$$

$$
\text{InputValue} = \text{InputAmount} \cdot \text{Price}\_{\text{InputToken}}
$$

### Annualized Yield

In Stella, we need to calculate the annualized yield in order to determine how much profit should be shared between the lenders and leveragoors

$$
\text{Yield}*{\text{APR}} = \frac{\text{Yield}}{(\text{BorrowValue}+\text{InputValue})} \cdot \frac{365\cdot24\cdot60\cdot60}{(\text{ts}*{\text{close}}-\text{ts}\_{\text{open}})}
$$

> $$\text{ts}\_{\text{close}}$$ = timestamp at the the time of closing the position
>
> $$\text{ts}\_{\text{open}}$$ = timestamp at the time where the position was opened

### Example

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

* Alice input 1000 USDC and open a position with leverage 4x on Uniswap V3 ETH/USDC 0.3% strategy by borrowing 2 ETH and 1000 USDC where ETH\@1000
* As time passed for **exactly 30 days**, Alice's position accrue the trading fee and her current position composition is 2.1 ETH + 2100 USDC where ETH price is still the same @1000
* Alice closes the position getting the yield of **$200 over 30 days**
* So, Alice's position yield is

&#x20;                $$\textsf{= }  (\textsf{2.1} \cdot \textsf{$1000} + \textsf{$2100}) - (\textsf{2} \cdot \textsf{$1000} + \textsf{$1000}) - (\textsf{$1000}) \ \textsf{= } \textsf{$4200} - \textsf{$3000} - \textsf{$1000} \ \textsf{= } \textsf{$200}$$

* **Yield = $200**
* **Annualized Yield** = **60.83%**


---

# Agent Instructions: 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.stellaxyz.io/stella-doc/stella-yield/yield-calculation.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.
