Skip to content

Commit

Permalink
Switch to linear trailing APRs
Browse files Browse the repository at this point in the history
  • Loading branch information
kexleyBeefy committed Jun 20, 2024
1 parent a33364e commit 83315e6
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/utils/apr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,17 @@ export function calculateLastApr(
}

let durationSum = ZERO_BD;
let timeWeight = ZERO_BD;
let weighedAPRSum = ZERO_BD;

// linearly weight the APRs, most recent APRs have full impact
for (let i = 0; i < APRs.length; i++) {
durationSum = durationSum.plus(durations[i]);
weighedAPRSum = weighedAPRSum.plus(APRs[i].times(durations[i]));
durationSum = durationSum.plus(durations[i].dividedBy(periodMs));
timeWeight = timeWeight.plus(durations[i].times(durationSum));
weighedAPRSum = weighedAPRSum.plus(APRs[i].times(timeWeight));
}

const apr = weighedAPRSum.div(durationSum);
const apr = weighedAPRSum.div(timeWeight);
// we compound the APR to get the APY
const annualPeriods = ONE_YEAR / periodMs;
const annualCompounds = annualPeriods * compoundCount;
Expand Down

0 comments on commit 83315e6

Please sign in to comment.