APR computations
This page describe the various methods used to compute Lagoon Vaults APR.
In order to compute those metrics, we will rely on the Period Summaries given by the Lagoon subgraphs.
As a reminder, here is what we can find inside a Period Summary:
type PeriodSummary @entity(immutable: false) {
id: Bytes!
vault: Bytes! # address
totalAssetsAtStart: BigInt!
totalSupplyAtStart: BigInt!
totalAssetsAtEnd: BigInt!
totalSupplyAtEnd: BigInt! # Before fee taking
netTotalSupplyAtEnd: BigInt! # After fee taking
blockNumber: BigInt!
blockTimestamp: BigInt! # Timestamp of the start of the period
duration: BigInt! # Duration of the period
}Single Period APR
How to compute the linear Net APR of a single period ?
Using totalAssetsAtStart and totalSupplyAtStart we can get the pricePerShareAtStart:
Then using totalAssetsAtEnd and netTotalSupplyAtEnd we can get the netPricePerShareAtEnd:
Using those 2 values, we can compute the evolution and annualize it using the period duration.
How to compute the linear Gross APR of a single period ?
The method is exactly the same as the one used previously. The difference will reside in the totalSupply used at the end of the period. This time we use summary.totalSupplyAtEnd.
Multiple periods APR
How to select a subset of periods summaries for a given duration, eg. 30 days?
1) Find the most recent period summary within the timeframe, here 30 days. If none is found, APR is 0.
2) Determine the start of the period by removing the duration to the end of the most recent period summary. We will call this value the targetTimestamp.
3) Find the price per share at targetTimestamp:
if
targetTimestampis older than the first periodSummary, we will use the first periodSummary timestamp and ppsif the
targetTimestampis within a periodSummaryp, we will do an linear interpolation of the price per share using thep.startPricePerShare,andp.endNetPricePerShare.
Here are a code snippet and a visual representation of the computation process:

How to compute a linear 30day Gross APR ?
It is not possible to do this, as it would only remove the fees for the last period used, which is not an accurate indicator of what the yield would have been without fees over multiple periods.
How to compute a Time-Weighted Rate Return (TWRR) 30day ?
The summaries subset selection will be the same as previously described.
In this computation we will do the average of the linear APR of the various periods, weighted by their duration.
Here is an example:
1
400
10%
2
600
20%
TotalDuration = 400 + 600 = 1000.
Period 1 Time Weighted APR (P1TW) : 400 / 1000 * 10% = 0.4 * 10% = 4%.
Period 2 Time Weighted APR (P2TW) : 600 / 1000 * 20% = 0.6 * 20% = 12%.
TWRR : P1TW + P2TW = 16%.
Here is a typescript example to compute the gross TWRR over a subset of Period Summaries.
Last updated