---
# System prepended metadata

title: APY calculation

---

# APY calculation

The current formula to calculating APY in the backend is wrong, this docs will show the current + the fix for that


## UnderlyingInterestApy
### Current calculation on backend

$rate = \frac{scyIndex}{prevScyIndex}$

$apy = rate^{365} - 1$


## UnderlyingRewardApy (scy rewards)
### Current calculation on backend

$rateIndex = rewardIndex - prevRewardIndex$;

$rewardYield = rateIndex * rewardPrice / scyPrice$

$apy = (1 + rewardYield)^{365} - 1$


## impliedAPY

### Backend code
$rate = ptExchangeRate - 1$


$apy = (1 + rate)^\frac{{365}}{durationInDays} - 1$

### Fix
Already good

## swapFeeApy

### Backend code

$durationInDays = min(current - marketStartDate, 7)$

$rate = swapFees / poolValue$

$apy = (1 + rate)^\frac{{365}}{durationInDays} - 1$

### Fix

See Vu's comment

## SwapFee

$durationInDays = min(current - marketStartDate, 7)$

Define: 
- $explicitSwapFee$ is total explicit swap fee (in term of accounting asset) gotten from the last $durationInDays$
- $implicitSwapFee$ is total implicit swap fee (in term of accounting asset) gottern from the last $durationInDays$
- $lpTokenPrice$ is price of the lp token in term of accounting asset

- $poolValue = lpTokenPrice * totalSupply$
- $swapFeeRateForLpHolder = \frac{explicitSwapFee * (1 - reserveFeePercent) + implicitSwapFee}{poolValue}$

- $swapFeeRateForVoter = \frac{explicitSwapFee \ * \ reserveFeePercent \ * \ accountingUSD}{PendlePriceUSD \ * \  totalVotedLastEpoch}$


- $swapFeeApyForLpHolder = (1 + swapFeeRateForLpHolder)^\frac{{365}}{durationInDays} - 1$

- $swapFeeApyForVoter =  swapFeeRateForVoter * \frac{365}{durationInDays}$