mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-10 09:11:55 +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
|
||||
}
|
||||
|
||||
// CalculateMarginCost calculate the margin cost of the given notional position by price * quantity
|
||||
func CalculateMarginCost(price, quantity, leverage fixedpoint.Value) fixedpoint.Value {
|
||||
var notionalValue = price.Mul(quantity)
|
||||
var cost = notionalValue.Div(leverage)
|
||||
|
@ -43,8 +44,8 @@ func CalculateMaxPosition(price, availableMargin, leverage fixedpoint.Value) fix
|
|||
return maxQuantity
|
||||
}
|
||||
|
||||
// CalculateLeverage calculates the leverage of the given position (price and quantity)
|
||||
func CalculateLeverage(price, quantity, availableMargin fixedpoint.Value) fixedpoint.Value {
|
||||
// CalculateMinRequiredLeverage calculates the leverage of the given position (price and quantity)
|
||||
func CalculateMinRequiredLeverage(price, quantity, availableMargin fixedpoint.Value) fixedpoint.Value {
|
||||
var notional = price.Mul(quantity)
|
||||
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 {
|
||||
price fixedpoint.Value
|
||||
quantity fixedpoint.Value
|
||||
|
@ -137,8 +137,8 @@ func TestCalculateLeverage(t *testing.T) {
|
|||
}
|
||||
for _, tt := range tests {
|
||||
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() {
|
||||
t.Errorf("CalculateLeverage() = %v, want %v", got, tt.want)
|
||||
if got := CalculateMinRequiredLeverage(tt.args.price, tt.args.quantity, tt.args.availableMargin); got.String() != tt.want.String() {
|
||||
t.Errorf("CalculateMinRequiredLeverage() = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user