diff --git a/pkg/bbgo/scale.go b/pkg/bbgo/scale.go index e4d36133d..da5a5bc52 100644 --- a/pkg/bbgo/scale.go +++ b/pkg/bbgo/scale.go @@ -151,7 +151,7 @@ func (s *LinearScale) Call(x float64) (y float64) { if x <= s.Domain[0] { return s.Range[0] } else if x >= s.Domain[1] { - return s.Range[0] + return s.Range[1] } y = s.Range[0] + (x-s.Domain[0])*s.a diff --git a/pkg/bbgo/scale_test.go b/pkg/bbgo/scale_test.go index 3b46c2c7a..1ad86a0c4 100644 --- a/pkg/bbgo/scale_test.go +++ b/pkg/bbgo/scale_test.go @@ -75,6 +75,7 @@ func TestLinearScale(t *testing.T) { assert.NoError(t, err) assert.Equal(t, "f(x) = 3.000000 + (x - 1000.000000) * 0.007000", scale.String()) assert.InDelta(t, 3, scale.Call(1000), delta) + assert.InDelta(t, 6.5, scale.Call(1500), delta) assert.InDelta(t, 10, scale.Call(2000), delta) for x := 1000; x <= 2000; x += 100 { y := scale.Call(float64(x)) @@ -92,6 +93,7 @@ func TestLinearScale2(t *testing.T) { assert.NoError(t, err) assert.Equal(t, "f(x) = 0.100000 + (x - 1.000000) * 0.150000", scale.String()) assert.InDelta(t, 0.1, scale.Call(1), delta) + assert.InDelta(t, 0.25, scale.Call(2), delta) assert.InDelta(t, 0.4, scale.Call(3), delta) } @@ -105,6 +107,7 @@ func TestLinearScaleNegative(t *testing.T) { assert.NoError(t, err) assert.Equal(t, "f(x) = 0.100000 + (x - -1.000000) * 0.075000", scale.String()) assert.InDelta(t, 0.1, scale.Call(-1), delta) + assert.InDelta(t, 0.25, scale.Call(1), delta) assert.InDelta(t, 0.4, scale.Call(3), delta) }