Calculating APY

Due to the vast amount of data involved and the limitations in indexing speed, it is impractical to query blockchains every time a new block is added. Instead, we calculate yield using accrued interest, an obtainable figure for most yield-bearing products. This allows APY to be extrapolated from limited data points.

Simple interest

We use the following formula to calculate APY for simple (i.e., not compounding) interest:

APY=interest rate×yeartime \text{APY} = \text{interest rate} \times \frac{\text{year}}{\text{time}}

Compounding interest

To determine compounding interest, we use the following formula:

APY=[(1+interest rate)yeartime]1\text{APY} = \left[ \left(1 + \text{interest rate}\right)^\frac{\text{year}}{\text{time}} \right] - 1

Interest Rate Calculation

The interest rate at any given point in time is determined by:

interest rate=current share priceprevious share price1\text{interest rate} = \frac{\text{current share price}}{\text{previous share price}} - 1

Where the share price is:

share price=total shares valuetotal shares\text{share price} = \frac{\text{total shares value}}{\text{total shares}}

Rewards APY

To calculate the rewards APY for a desired time range (1 day, 7 days, 30 days), we:

  1. Estimate the number of reward tokens distributed per token deposited in the vault during the chosen period by taking a weighted average of emissions based on the TVL.

  2. Calculate the average price ratio between the reward token and the deposited token for that period.

  3. Use this ratio to convert the accumulated reward tokens' value to a single deposited token's value.

  4. Compare this converted value to the initial deposit to determine the APY.

The average of the reward token price (PIT - Price In Token) to deposited token price is calculated using the formula:

PITti,xday=j:titj=xdayirewardTokenPriceInUSDtj1underlyingTokenPriceInUSDtj1(tjtj1)titj\overline{PIT}_{t_{i},xday}=\frac{\sum_{j:t_{i}-t_{j}=xday}^{i}\frac{rewardTokenPriceInUSD_{t_{j-1}}}{underlyingTokenPriceInUSD_{t_{j-1}}} * (t_{j}-t_{j-1})}{t_{i}-t_{j}}

The APY at time range of xday is calculated using the formula:

APYti,xday=j:titj=xdayiemissionsPerSecondtj1×year×PITtj,xday×(tjtj1)j:titj=xdayiTVLtj×(tjtj1)\text{APY}_{t_{i},xday}=\frac{\sum_{j:t_{i}-t_{j}=xday}^{i}emissionsPerSecond_{t_{j-1}}\times year\times\overline{PIT}_{t_{j},xday}\times (t_{j}-t_{j-1}) }{\sum_{j:t_{i}-t_{j}=xday}^{i}TVL_{t_{j}}\times (t_{j}-t_{j-1}) }

Adjusting for changes in TVL

To offer a more representative APY in scenarios where the amount of funds held in the vault ("TVL") fluctuates significantly, we calculate APY using a weighted average over a specified period (x days).

Weighting Mechanism for Range APY

In calculating the weighted average interest rate for the range APY, each point in time within the range is assigned a weight. This weight is determined by taking the minimum of the TVL at that specific time (TVLti)(TVL_{t_{i}}) and the TVL at the preceding time (TVLti1)(TVL_{t_{i-1}}).

weightti=min(TVLti,TVLti1)\text{weight}_{t_{i}}=min(\text{TVL}_{t_{i}},\text{TVL}_{t_{i-1}})

Rationale

The TVL between two consecutive points in time (t_{i} and t_{i-1}) is inherently uncertain. To maintain a conservative approach and avoid overestimating the yield, we choose to underestimate the TVL during that interval by selecting the lower of the two TVL values. This ensures that the calculated APY reflects a more realistic, if not slightly lower, yield.

With this weighting method the average interest rate over a given period is determined by

interest rateti,xday=(j:titj=xdayishare pricetjshare pricetj1weighttjj:titj=xdayiweighttj)ij1\text{interest rate}_{t_{i},xday}=(\frac{\sum_{j:t_{i}-t_{j}=xday}^{i}\frac{\text{share price}_{t_{j}}}{\text{share price}_{t_{j-1}}}*weight_{t_{j}}}{\sum_{j:t_{i}-t_{j}=xday}^{i}weight_{t_{j}}})^{i-j} - 1

Obtaining the data we need

Last updated