-
Notifications
You must be signed in to change notification settings - Fork 142
/
rule_stop_test.go
51 lines (36 loc) · 1.06 KB
/
rule_stop_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package techan
import (
"testing"
"github.com/sdcoffey/big"
"github.com/stretchr/testify/assert"
)
func TestStopLossRule(t *testing.T) {
t.Run("Returns false when position is new or closed", func(t *testing.T) {
record := NewTradingRecord()
series := mockTimeSeriesFl(1, 2, 3, 4)
slr := NewStopLossRule(series, -0.1)
assert.False(t, slr.IsSatisfied(3, record))
})
t.Run("Returns true when losses exceed tolerance", func(t *testing.T) {
record := NewTradingRecord()
record.Operate(Order{
Side: BUY,
Amount: big.NewFromString("10"),
Price: big.ONE,
})
series := mockTimeSeriesFl(10, 9) // Lose 10%
slr := NewStopLossRule(series, -0.05)
assert.True(t, slr.IsSatisfied(1, record))
})
t.Run("Returns false when losses do not exceed tolerance", func(t *testing.T) {
record := NewTradingRecord()
record.Operate(Order{
Side: BUY,
Amount: big.NewFromString("10"),
Price: big.ONE,
})
series := mockTimeSeriesFl(10, 10.1) // Gain 1%
slr := NewStopLossRule(series, -0.05)
assert.False(t, slr.IsSatisfied(1, record))
})
}