risk: rename func

This commit is contained in:
c9s 2022-07-14 00:07:49 +08:00
parent c7424479bb
commit 5bbccacc89
No known key found for this signature in database
GPG Key ID: 7385E7E464CB0A54
2 changed files with 6 additions and 5 deletions

View File

@ -24,6 +24,7 @@ func CalculateOpenLoss(numContract, markPrice, orderPrice fixedpoint.Value, side
return openLoss return openLoss
} }
// CalculateMarginCost calculate the margin cost of the given notional position by price * quantity
func CalculateMarginCost(price, quantity, leverage fixedpoint.Value) fixedpoint.Value { func CalculateMarginCost(price, quantity, leverage fixedpoint.Value) fixedpoint.Value {
var notionalValue = price.Mul(quantity) var notionalValue = price.Mul(quantity)
var cost = notionalValue.Div(leverage) var cost = notionalValue.Div(leverage)
@ -43,8 +44,8 @@ func CalculateMaxPosition(price, availableMargin, leverage fixedpoint.Value) fix
return maxQuantity return maxQuantity
} }
// CalculateLeverage calculates the leverage of the given position (price and quantity) // CalculateMinRequiredLeverage calculates the leverage of the given position (price and quantity)
func CalculateLeverage(price, quantity, availableMargin fixedpoint.Value) fixedpoint.Value { func CalculateMinRequiredLeverage(price, quantity, availableMargin fixedpoint.Value) fixedpoint.Value {
var notional = price.Mul(quantity) var notional = price.Mul(quantity)
return notional.Div(availableMargin) return notional.Div(availableMargin)
} }

View File

@ -114,7 +114,7 @@ func TestCalculateMaxPosition(t *testing.T) {
} }
} }
func TestCalculateLeverage(t *testing.T) { func TestCalculateMinRequiredLeverage(t *testing.T) {
type args struct { type args struct {
price fixedpoint.Value price fixedpoint.Value
quantity fixedpoint.Value quantity fixedpoint.Value
@ -137,8 +137,8 @@ func TestCalculateLeverage(t *testing.T) {
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
if got := CalculateLeverage(tt.args.price, tt.args.quantity, tt.args.availableMargin); got.String() != tt.want.String() { if got := CalculateMinRequiredLeverage(tt.args.price, tt.args.quantity, tt.args.availableMargin); got.String() != tt.want.String() {
t.Errorf("CalculateLeverage() = %v, want %v", got, tt.want) t.Errorf("CalculateMinRequiredLeverage() = %v, want %v", got, tt.want)
} }
}) })
} }