forked from cinar/indicator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
strategy.go
44 lines (35 loc) · 791 Bytes
/
strategy.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
// Copyright (c) 2021 Onur Cinar. All Rights Reserved.
// The source code is provided under MIT License.
//
// https://github.com/cinar/indicator
package indicator
import (
"time"
)
// Strategy action.
type Action int
const (
SELL Action = -1
HOLD Action = 0
BUY Action = 1
)
// Asset values.
type Asset struct {
Date []time.Time
Opening []float64
Closing []float64
High []float64
Low []float64
Volume []int64
}
// Strategy function. It takes an Asset and returns
// actions for each row.
type StrategyFunction func(Asset) []Action
// Buy and hold strategy. Buys at the beginning and holds.
func BuyAndHoldStrategy(asset Asset) []Action {
actions := make([]Action, len(asset.Date))
for i := 0; i < len(actions); i++ {
actions[i] = BUY
}
return actions
}