Skip to content

Commit

Permalink
fix: correct vault apr calculation (#693)
Browse files Browse the repository at this point in the history
  • Loading branch information
tyleroooo authored Oct 1, 2024
1 parent e13a869 commit 82e1128
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ allprojects {
}

group = "exchange.dydx.abacus"
version = "1.12.10"
version = "1.12.11"

repositories {
google()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,11 @@ object VaultCalculator {
val thirtyDaysAgoTotalPnl = thirtyDaysAgoEntry.totalPnl ?: 0.0

val pnlDifference = latestTotalPnl - thirtyDaysAgoTotalPnl
val timeDifferenceMs = if (latestEntry.date != null && thirtyDaysAgoEntry.date != null) {
latestEntry.date - thirtyDaysAgoEntry.date
} else {
0.0
}
val thirtyDaysAgoEquity = thirtyDaysAgoEntry.equity ?: 0.0
val thirtyDayReturnPercent = if (thirtyDaysAgoEquity != 0.0) {
(pnlDifference / thirtyDaysAgoEquity)
Expand All @@ -135,7 +140,7 @@ object VaultCalculator {

return VaultDetails(
totalValue = totalValue,
thirtyDayReturnPercent = thirtyDayReturnPercent,
thirtyDayReturnPercent = if (timeDifferenceMs > 0) thirtyDayReturnPercent * 365.days.inWholeMilliseconds / timeDifferenceMs else 0.0,
history = history.toIList(),
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class VaultTests {

val expectedVaultDetails = VaultDetails(
totalValue = 10000.0,
thirtyDayReturnPercent = 0.1,
thirtyDayReturnPercent = 0.1 * 365,
history = iListOf(
VaultHistoryEntry(
date = 1659465600000.0,
Expand Down Expand Up @@ -119,7 +119,7 @@ class VaultTests {
val vaultDetails = calculateVaultSummary(historicalPnl)

assertNotNull(vaultDetails)
assertEquals(0.05263157894736842, vaultDetails.thirtyDayReturnPercent)
assertEquals(0.6403508771929824, vaultDetails.thirtyDayReturnPercent)
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class V4VaultTests : V4BaseTests() {

val vaultDetails = vault?.details
assertEquals(10000.0, vaultDetails?.totalValue)
assertEquals(0.1, vaultDetails?.thirtyDayReturnPercent)
assertEquals(0.1 * 365, vaultDetails?.thirtyDayReturnPercent)
assertEquals(2, vaultDetails?.history?.size)
assertEquals(1000.0, vaultDetails?.history?.get(0)?.totalPnl)
assertEquals(500.0, vaultDetails?.history?.get(1)?.totalPnl)
Expand All @@ -50,7 +50,7 @@ class V4VaultTests : V4BaseTests() {

val vault = perp.internalState.vault
assertEquals(10000.0, vault?.details?.totalValue)
assertEquals(0.1, vault?.details?.thirtyDayReturnPercent)
assertEquals(0.1 * 365, vault?.details?.thirtyDayReturnPercent)
assertEquals(2, vault?.details?.history?.size)
assertEquals(1000.0, vault?.details?.history?.get(0)?.totalPnl)
assertEquals(500.0, vault?.details?.history?.get(1)?.totalPnl)
Expand Down
2 changes: 1 addition & 1 deletion v4_abacus.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |spec|
spec.name = 'v4_abacus'
spec.version = '1.12.10'
spec.version = '1.12.11'
spec.homepage = 'https://github.com/dydxprotocol/v4-abacus'
spec.source = { :http=> ''}
spec.authors = ''
Expand Down

0 comments on commit 82e1128

Please sign in to comment.