fix: dup naming, remove Leverage from drift field

This commit is contained in:
zenix 2022-09-22 13:48:01 +09:00
parent 15308fbe3b
commit ac2f7decdf
2 changed files with 24 additions and 25 deletions

View File

@ -6,7 +6,7 @@ import (
"github.com/stretchr/testify/assert"
)
const Delta = 1e-9
const delta = 1e-9
func TestExponentialScale(t *testing.T) {
// graph see: https://www.desmos.com/calculator/ip0ijbcbbf
@ -19,8 +19,8 @@ func TestExponentialScale(t *testing.T) {
assert.NoError(t, err)
assert.Equal(t, "f(x) = 0.001000 * 1.002305 ^ (x - 1000.000000)", scale.String())
assert.InDelta(t, 0.001, scale.Call(1000.0), Delta)
assert.InDelta(t, 0.01, scale.Call(2000.0), Delta)
assert.InDelta(t, 0.001, scale.Call(1000.0), delta)
assert.InDelta(t, 0.01, scale.Call(2000.0), delta)
for x := 1000; x <= 2000; x += 100 {
y := scale.Call(float64(x))
@ -38,8 +38,8 @@ func TestExponentialScale_Reverse(t *testing.T) {
assert.NoError(t, err)
assert.Equal(t, "f(x) = 0.100000 * 0.995405 ^ (x - 1000.000000)", scale.String())
assert.InDelta(t, 0.1, scale.Call(1000.0), Delta)
assert.InDelta(t, 0.001, scale.Call(2000.0), Delta)
assert.InDelta(t, 0.1, scale.Call(1000.0), delta)
assert.InDelta(t, 0.001, scale.Call(2000.0), delta)
for x := 1000; x <= 2000; x += 100 {
y := scale.Call(float64(x))
@ -57,8 +57,8 @@ func TestLogScale(t *testing.T) {
err := scale.Solve()
assert.NoError(t, err)
assert.Equal(t, "f(x) = 0.001303 * log(x - 999.000000) + 0.001000", scale.String())
assert.InDelta(t, 0.001, scale.Call(1000.0), Delta)
assert.InDelta(t, 0.01, scale.Call(2000.0), Delta)
assert.InDelta(t, 0.001, scale.Call(1000.0), delta)
assert.InDelta(t, 0.01, scale.Call(2000.0), delta)
for x := 1000; x <= 2000; x += 100 {
y := scale.Call(float64(x))
t.Logf("%s = %f", scale.FormulaOf(float64(x)), y)
@ -74,8 +74,8 @@ func TestLinearScale(t *testing.T) {
err := scale.Solve()
assert.NoError(t, err)
assert.Equal(t, "f(x) = 0.007000 * x + -4.000000", scale.String())
assert.InDelta(t, 3, scale.Call(1000), Delta)
assert.InDelta(t, 10, scale.Call(2000), Delta)
assert.InDelta(t, 3, scale.Call(1000), delta)
assert.InDelta(t, 10, scale.Call(2000), delta)
for x := 1000; x <= 2000; x += 100 {
y := scale.Call(float64(x))
t.Logf("%s = %f", scale.FormulaOf(float64(x)), y)
@ -91,8 +91,8 @@ func TestLinearScale2(t *testing.T) {
err := scale.Solve()
assert.NoError(t, err)
assert.Equal(t, "f(x) = 0.150000 * x + -0.050000", scale.String())
assert.InDelta(t, 0.1, scale.Call(1), Delta)
assert.InDelta(t, 0.4, scale.Call(3), Delta)
assert.InDelta(t, 0.1, scale.Call(1), delta)
assert.InDelta(t, 0.4, scale.Call(3), delta)
}
func TestQuadraticScale(t *testing.T) {
@ -105,9 +105,9 @@ func TestQuadraticScale(t *testing.T) {
err := scale.Solve()
assert.NoError(t, err)
assert.Equal(t, "f(x) = 0.000550 * x ^ 2 + 0.135000 * x + 1.000000", scale.String())
assert.InDelta(t, 1, scale.Call(0), Delta)
assert.InDelta(t, 20, scale.Call(100.0), Delta)
assert.InDelta(t, 50.0, scale.Call(200.0), Delta)
assert.InDelta(t, 1, scale.Call(0), delta)
assert.InDelta(t, 20, scale.Call(100.0), delta)
assert.InDelta(t, 50.0, scale.Call(200.0), delta)
for x := 0; x <= 200; x += 1 {
y := scale.Call(float64(x))
t.Logf("%s = %f", scale.FormulaOf(float64(x)), y)
@ -127,11 +127,11 @@ func TestPercentageScale(t *testing.T) {
v, err := s.Scale(0.0)
assert.NoError(t, err)
assert.InDelta(t, 1.0, v, Delta)
assert.InDelta(t, 1.0, v, delta)
v, err = s.Scale(1.0)
assert.NoError(t, err)
assert.InDelta(t, 100.0, v, Delta)
assert.InDelta(t, 100.0, v, delta)
})
t.Run("from -1.0 to 1.0", func(t *testing.T) {
@ -146,11 +146,11 @@ func TestPercentageScale(t *testing.T) {
v, err := s.Scale(-1.0)
assert.NoError(t, err)
assert.InDelta(t, 10.0, v, Delta)
assert.InDelta(t, 10.0, v, delta)
v, err = s.Scale(1.0)
assert.NoError(t, err)
assert.InDelta(t, 100.0, v, Delta)
assert.InDelta(t, 100.0, v, delta)
})
t.Run("reverse -1.0 to 1.0", func(t *testing.T) {
@ -165,19 +165,19 @@ func TestPercentageScale(t *testing.T) {
v, err := s.Scale(-1.0)
assert.NoError(t, err)
assert.InDelta(t, 100.0, v, Delta)
assert.InDelta(t, 100.0, v, delta)
v, err = s.Scale(1.0)
assert.NoError(t, err)
assert.InDelta(t, 10.0, v, Delta)
assert.InDelta(t, 10.0, v, delta)
v, err = s.Scale(2.0)
assert.NoError(t, err)
assert.InDelta(t, 10.0, v, Delta)
assert.InDelta(t, 10.0, v, delta)
v, err = s.Scale(-2.0)
assert.NoError(t, err)
assert.InDelta(t, 100.0, v, Delta)
assert.InDelta(t, 100.0, v, delta)
})
t.Run("negative range", func(t *testing.T) {
@ -192,10 +192,10 @@ func TestPercentageScale(t *testing.T) {
v, err := s.Scale(0.0)
assert.NoError(t, err)
assert.InDelta(t, -100.0, v, Delta)
assert.InDelta(t, -100.0, v, delta)
v, err = s.Scale(1.0)
assert.NoError(t, err)
assert.InDelta(t, 100.0, v, Delta)
assert.InDelta(t, 100.0, v, delta)
})
}

View File

@ -71,7 +71,6 @@ type Strategy struct {
beta float64
Leverage fixedpoint.Value `json:"leverage" modifiable:"true"`
StopLoss fixedpoint.Value `json:"stoploss" modifiable:"true"`
CanvasPath string `json:"canvasPath"`
PredictOffset int `json:"predictOffset"`