-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.go
46 lines (39 loc) · 947 Bytes
/
utils.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
package baregone
import (
"time"
)
type TradeType string
const (
BUY TradeType = "BUY"
SELL = "SELL"
)
type BarData struct {
date time.Time
close int
volume int
}
type BacktestContext struct {
trades []Position `json:"trades,omitempty"`
capital int `json:"capital,omitempty"`
profit int `json:"profit,omitempty"`
totalTrades int `json:"total_trades,omitempty"`
}
/**
* Get Profit percentage gained
* https://www.investopedia.com/ask/answers/how-do-you-calculate-percentage-gain-or-loss-investment/
* @param startPrice
* @param endPrice
*/
func GetPercentageGain(startPrice int, endPrice int) int {
return (endPrice - startPrice) / startPrice * 100
}
/**
* GetTotalProfitAmount, from start and end
* @param start
* @param end
* @param capital
*/
func GetTotalProfitAmount(start int, end int, capital int) int {
profit := end - start
return (profit / start) * capital
}