Skip to content

Instantly share code, notes, and snippets.

@ajb413
Last active October 7, 2024 02:10
Show Gist options
  • Save ajb413/a6f89486ec5485746cd5eac1e10e4fc2 to your computer and use it in GitHub Desktop.
Save ajb413/a6f89486ec5485746cd5eac1e10e4fc2 to your computer and use it in GitHub Desktop.
How to calculate the Net APY that is displayed for users on https://app.compound.finance/

Net APY Calculation

  1. Convert all supplied and borrowed asset amounts to a single asset (like USD or ETH).
  2. Calculate the sum of (suppliedAmount * supplyApyAsDecimal - borrowedAmount * borrowApyAsDecimal) for all underlying assets.
  3. If the calculated sum from the previous step is >0 then Net APY = 100 * (sum / totalSuppliedValue). If the calculation from the previous step is <0 then Net APY = 100 * (sum / totalBorrowedValue). If the calculation from the previous step is 0 then Net APY = 0.

Example

Net APY:

  • -7.29%

Supplied Assets:

  • 0.6 ETH ($260.20) @ 1.11% APY

Borrowed Assets:

  • 75 BAT ($26.56) @ 5.57% APY
  • 100.02 USDT ($100.02) @ 10.64 APY%

Calculation:

(260.20 * 0.0111 - 0 * 0) + (0 * 0 - 26.56 * 0.0557) + (0 * 0 - 100.02 * 0.1064) = -9.2333

100 * (-9.2333 / (26.56 + 100.02)) = -7.294438299889398

-7.29%
@CherryDT
Copy link

Hm, something is not adding up. I did an example calculation and got a very different value than shown on the website, perhaps it's because the website somehow includes COMP while you don't? Not sure how, though.

@user2745
Copy link

user2745 commented Oct 7, 2024

I get a very different value in my testing application

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment