Skip to content

Instantly share code, notes, and snippets.

@gregorynicholas
Forked from ajb413/net_apy.md
Created November 8, 2020 18:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gregorynicholas/53d55753c6edc6f75b2df0aba7dd58bc to your computer and use it in GitHub Desktop.
Save gregorynicholas/53d55753c6edc6f75b2df0aba7dd58bc 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%
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment