mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-27 17:25:16 +00:00
add more grid extend tests
This commit is contained in:
parent
56e40eff67
commit
b2f8abd56c
|
@ -40,7 +40,7 @@ func (g *Grid) ExtendUpperPrice(upper fixedpoint.Value) (newPins []fixedpoint.Va
|
||||||
g.UpperPrice = upper
|
g.UpperPrice = upper
|
||||||
|
|
||||||
// since the grid is extended, the size should be updated as well
|
// since the grid is extended, the size should be updated as well
|
||||||
g.Size = (g.UpperPrice - g.LowerPrice).Div(g.Spread).Ceil()
|
g.Size = (g.UpperPrice - g.LowerPrice).Div(g.Spread).Floor()
|
||||||
|
|
||||||
lastPin := g.Pins[ len(g.Pins) - 1 ]
|
lastPin := g.Pins[ len(g.Pins) - 1 ]
|
||||||
for p := lastPin + g.Spread; p <= g.UpperPrice; p += g.Spread {
|
for p := lastPin + g.Spread; p <= g.UpperPrice; p += g.Spread {
|
||||||
|
@ -55,10 +55,13 @@ func (g *Grid) ExtendLowerPrice(lower fixedpoint.Value) (newPins []fixedpoint.Va
|
||||||
g.LowerPrice = lower
|
g.LowerPrice = lower
|
||||||
|
|
||||||
// since the grid is extended, the size should be updated as well
|
// since the grid is extended, the size should be updated as well
|
||||||
g.Size = (g.UpperPrice - g.LowerPrice).Div(g.Spread).Ceil()
|
g.Size = (g.UpperPrice - g.LowerPrice).Div(g.Spread).Floor()
|
||||||
|
|
||||||
firstPin := g.Pins[0]
|
firstPin := g.Pins[0]
|
||||||
numToAdd := (firstPin - g.LowerPrice).Div(g.Spread).Ceil()
|
numToAdd := (firstPin - g.LowerPrice).Div(g.Spread).Floor()
|
||||||
|
if numToAdd == 0 {
|
||||||
|
return newPins
|
||||||
|
}
|
||||||
|
|
||||||
for p := firstPin - g.Spread.Mul(numToAdd); p < firstPin; p += g.Spread {
|
for p := firstPin - g.Spread.Mul(numToAdd); p < firstPin; p += g.Spread {
|
||||||
newPins = append(newPins, p)
|
newPins = append(newPins, p)
|
||||||
|
|
|
@ -53,7 +53,7 @@ func TestGrid_ExtendLowerPrice(t *testing.T) {
|
||||||
|
|
||||||
// 100 = (2000-1000) / 10
|
// 100 = (2000-1000) / 10
|
||||||
if assert.Len(t, newPins, 100) {
|
if assert.Len(t, newPins, 100) {
|
||||||
assert.Equal(t, fixedpoint.NewFromFloat(2000.0) - expectedSpread, newPins[99])
|
assert.Equal(t, fixedpoint.NewFromFloat(2000.0)-expectedSpread, newPins[99])
|
||||||
}
|
}
|
||||||
|
|
||||||
assert.Equal(t, expectedSpread, grid.Spread)
|
assert.Equal(t, expectedSpread, grid.Spread)
|
||||||
|
@ -61,4 +61,8 @@ func TestGrid_ExtendLowerPrice(t *testing.T) {
|
||||||
assert.Equal(t, fixedpoint.NewFromFloat(1000.0), grid.Pins[0])
|
assert.Equal(t, fixedpoint.NewFromFloat(1000.0), grid.Pins[0])
|
||||||
assert.Equal(t, fixedpoint.NewFromFloat(3000.0), grid.Pins[200])
|
assert.Equal(t, fixedpoint.NewFromFloat(3000.0), grid.Pins[200])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
newPins2 := grid.ExtendLowerPrice(
|
||||||
|
fixedpoint.NewFromFloat(1000.0 - 1.0))
|
||||||
|
assert.Len(t, newPins2, 0) // should have no new pin generated
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user