mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-25 00:05:15 +00:00
risk: rename func
This commit is contained in:
parent
c7424479bb
commit
5bbccacc89
|
@ -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)
|
||||||
}
|
}
|
||||||
|
|
|
@ -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)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user