forked from cinar/indicator
-
Notifications
You must be signed in to change notification settings - Fork 1
/
volatility_strategies.go
56 lines (46 loc) · 1.23 KB
/
volatility_strategies.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
52
53
54
55
56
// Copyright (c) 2021 Onur Cinar. All Rights Reserved.
// The source code is provided under MIT License.
//
// https://github.com/cinar/indicator
package indicator
// Bollinger bands strategy function.
func BollingerBandsStrategy(asset *Asset) []Action {
actions := make([]Action, len(asset.Date))
_, upperBand, lowerBand := BollingerBands(asset.Closing)
for i := 0; i < len(actions); i++ {
if asset.Closing[i] > upperBand[i] {
actions[i] = SELL
} else if asset.Closing[i] < lowerBand[i] {
actions[i] = BUY
} else {
actions[i] = HOLD
}
}
return actions
}
// Projection oscillator strategy function.
func ProjectionOscillatorStrategy(period, smooth int, asset *Asset) []Action {
actions := make([]Action, len(asset.Date))
po, spo := ProjectionOscillator(
period,
smooth,
asset.High,
asset.Low,
asset.Closing)
for i := 0; i < len(actions); i++ {
if po[i] > spo[i] {
actions[i] = BUY
} else if po[i] < spo[i] {
actions[i] = SELL
} else {
actions[i] = HOLD
}
}
return actions
}
// Make projection oscillator strategy.
func MakeProjectionOscillatorStrategy(period, smooth int) StrategyFunction {
return func(asset *Asset) []Action {
return ProjectionOscillatorStrategy(period, smooth, asset)
}
}