Skip to content

Commit

Permalink
fix: use current price in datanode lower curve estimate
Browse files Browse the repository at this point in the history
  • Loading branch information
wwestgarth committed Sep 24, 2024
1 parent 7887a8a commit 2c65a87
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 1 deletion.
2 changes: 1 addition & 1 deletion core/execution/amm/estimator.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func EstimateBounds(
l: l,
high: basePrice,
low: lowerPrice,
sqrtHigh: sqrter.sqrt(upperPrice),
sqrtHigh: sqrter.sqrt(basePrice),
isLower: true,
pv: r.PositionSizeAtLower,
}
Expand Down
58 changes: 58 additions & 0 deletions core/execution/amm/estimator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,3 +238,61 @@ func TestEstimatePositionFactor(t *testing.T) {
assert.False(t, metrics.TooWideLower) // is valid as there are less than 10 empty price levels
assert.True(t, metrics.TooWideUpper) // isn't valid as there are more than 10 empty price levels
}

func TestEstimateBoundsOneSided(t *testing.T) {
initialMargin := num.DecimalFromFloat(1)
riskFactorShort := num.DecimalFromFloat(0.01)
riskFactorLong := num.DecimalFromFloat(0.01)
linearSlippageFactor := num.DecimalFromFloat(0)
sqrter := NewSqrter()

lowerPrice := num.NewUint(900)
basePrice := num.NewUint(1000)
upperPrice := num.NewUint(1100)
leverageUpper := num.DecimalFromFloat(2.00)
leverageLower := num.DecimalFromFloat(2.00)
balance := num.NewUint(100)

// no upper bound supplied
metrics := EstimateBounds(
sqrter,
lowerPrice,
basePrice,
nil,
leverageLower,
leverageUpper,
balance,
linearSlippageFactor,
initialMargin,
riskFactorShort,
riskFactorLong,
num.DecimalOne(),
num.DecimalOne(),
0,
)
assert.True(t, metrics.LiquidationPriceAtUpper.IsZero())
assert.True(t, metrics.PositionSizeAtUpper.IsZero())
assert.True(t, metrics.LossOnCommitmentAtUpper.IsZero())

// no lower bound supplied
metrics = EstimateBounds(
sqrter,
nil,
basePrice,
upperPrice,
leverageLower,
leverageUpper,
balance,
linearSlippageFactor,
initialMargin,
riskFactorShort,
riskFactorLong,
num.DecimalOne(),
num.DecimalOne(),
0,
)
assert.True(t, metrics.LiquidationPriceAtLower.IsZero())
assert.True(t, metrics.PositionSizeAtLower.IsZero())
assert.True(t, metrics.LossOnCommitmentAtLower.IsZero())

}

0 comments on commit 2c65a87

Please sign in to comment.