Skip to content

Commit

Permalink
Update account level default IMF to 0.02 (#772)
Browse files Browse the repository at this point in the history
  • Loading branch information
ruixhuang authored Jan 18, 2025
1 parent 863c948 commit ad045e5
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ internal class SubaccountCalculatorV2(
val equity = calculated?.equity
val initialRiskTotal = calculated?.initialRiskTotal
if (quoteBalance != null && equity != null && initialRiskTotal != null) {
val imf = configs?.initialMarginFraction ?: 0.05
val imf = configs?.initialMarginFraction ?: 0.02

calculated.buyingPower = calculateBuyingPower(
equity = equity,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -730,7 +730,7 @@ open class TradingStateMachine(
marketsSummary = internalState.marketsSummary,
periods = periods,
price = null, // priceOverwrite(markets),
configs = null, // This is used to get the IMF.. with "null" the default value 0.05 will be used
configs = null, // This is used to get the IMF.. with "null" the default value 0.02 will be used
)
} else {
this.marketsSummary?.let { marketsSummary ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ class TransferInputTests : V4BaseTests() {
assertEquals(0.27310138690337965, calculatedPostOrder.leverage)
assertEquals(0.013655195644485585, calculatedCurrent.marginUsage)
assertEquals(0.013655069345169024, calculatedPostOrder.marginUsage)
assertEquals(2132807.5345397857, calculatedCurrent.buyingPower)
assertEquals(2132827.5345397857, calculatedPostOrder.buyingPower)
assertEquals(5332018.836349465, calculatedCurrent.buyingPower)
assertEquals(5332068.836349465, calculatedPostOrder.buyingPower)
} else {
test(
{
Expand Down Expand Up @@ -170,8 +170,8 @@ class TransferInputTests : V4BaseTests() {
assertEquals(0.2610321394033229, calculatedPostOrder.leverage)
assertEquals(0.013655195644485585, calculatedCurrent.marginUsage)
assertEquals(0.013051606970166163, calculatedPostOrder.marginUsage)
assertEquals(2132807.5345397857, calculatedCurrent.buyingPower)
assertEquals(2232807.5345397857, calculatedPostOrder.buyingPower)
assertEquals(5332018.836349465, calculatedCurrent.buyingPower)
assertEquals(5582018.836349465, calculatedPostOrder.buyingPower)
} else {
test(
{
Expand Down Expand Up @@ -255,8 +255,8 @@ class TransferInputTests : V4BaseTests() {
assertEquals(0.2706010528035248, calculatedPostOrder.leverage)
assertEquals(0.013655195644485585, calculatedCurrent.marginUsage)
assertEquals(0.01353005264017626, calculatedPostOrder.marginUsage)
assertEquals(2132807.5345397857, calculatedCurrent.buyingPower)
assertEquals(2152807.5345397857, calculatedPostOrder.buyingPower)
assertEquals(5332018.836349465, calculatedCurrent.buyingPower)
assertEquals(5382018.836349465, calculatedPostOrder.buyingPower)
} else {
test(
{
Expand Down Expand Up @@ -339,8 +339,8 @@ class TransferInputTests : V4BaseTests() {
assertEquals(0.27062585430277314, calculatedPostOrder.leverage)
assertEquals(0.013655195644485585, calculatedCurrent.marginUsage)
assertEquals(0.013531292715138643, calculatedPostOrder.marginUsage)
assertEquals(2132807.5345397857, calculatedCurrent.buyingPower)
assertEquals(2152607.5345397857, calculatedPostOrder.buyingPower)
assertEquals(5332018.836349465, calculatedCurrent.buyingPower)
assertEquals(5381518.836349465, calculatedPostOrder.buyingPower)
} else {
test(
{
Expand Down Expand Up @@ -446,8 +446,8 @@ class TransferInputTests : V4BaseTests() {
assertEquals(0.2756535044256519, calculatedPostOrder.leverage)
assertEquals(0.013655195644485585, calculatedCurrent.marginUsage)
assertEquals(0.013782675221282625, calculatedPostOrder.marginUsage)
assertEquals(2132807.5345397857, calculatedCurrent.buyingPower)
assertEquals(2112807.5345397857, calculatedPostOrder.buyingPower)
assertEquals(5332018.836349465, calculatedCurrent.buyingPower)
assertEquals(5282018.836349465, calculatedPostOrder.buyingPower)
} else {
test(
{
Expand Down Expand Up @@ -530,8 +530,8 @@ class TransferInputTests : V4BaseTests() {
assertEquals(0.2756792407635699, calculatedPostOrder.leverage)
assertEquals(0.013655195644485585, calculatedCurrent.marginUsage)
assertEquals(0.013783962038178554, calculatedPostOrder.marginUsage)
assertEquals(2132807.5345397857, calculatedCurrent.buyingPower)
assertEquals(2112607.5345397857, calculatedPostOrder.buyingPower)
assertEquals(5332018.836349465, calculatedCurrent.buyingPower)
assertEquals(5281518.836349465, calculatedPostOrder.buyingPower)
} else {
test(
{
Expand Down Expand Up @@ -635,8 +635,8 @@ class TransferInputTests : V4BaseTests() {
assertEquals(0.2756535044256519, calculatedPostOrder.leverage)
assertEquals(0.013655195644485585, calculatedCurrent.marginUsage)
assertEquals(0.013782675221282625, calculatedPostOrder.marginUsage)
assertEquals(2132807.5345397857, calculatedCurrent.buyingPower)
assertEquals(2112807.5345397857, calculatedPostOrder.buyingPower)
assertEquals(5332018.836349465, calculatedCurrent.buyingPower)
assertEquals(5282018.836349465, calculatedPostOrder.buyingPower)

assertTrue { perp.state?.input?.transfer?.transferOutOptions?.assets?.count() == 2 }
assertTrue { perp.state?.input?.transfer?.transferOutOptions?.chains?.count() == 1 }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class V4CalculationTests : V4BaseTests() {
assertEquals(50.0, calculated?.initialRiskTotal)
assertEquals(10.0, calculated?.leverage)
assertEquals(0.5, calculated?.marginUsage)
assertEquals(1000.0, calculated?.buyingPower)
assertEquals(2500.0, calculated?.buyingPower)

val ethPosition = subaccount?.openPositions?.get("ETH-USD")
val positionCalculated = ethPosition?.calculated?.get(CalculationPeriod.current)
Expand Down Expand Up @@ -208,7 +208,7 @@ class V4CalculationTests : V4BaseTests() {
assertEquals(50.0, calculated.initialRiskTotal)
assertEquals(10.0, calculated.leverage)
assertEquals(0.5, calculated.marginUsage)
assertEquals(1000.0, calculated.buyingPower)
assertEquals(2500.0, calculated.buyingPower)

val ethPosition = subaccount.openPositions?.get("ETH-USD")!!
val positionCalculated = ethPosition.calculated[CalculationPeriod.current]!!
Expand Down

0 comments on commit ad045e5

Please sign in to comment.