Rename functions

This commit is contained in:
なるみ 2022-03-29 02:23:42 +08:00
parent 2a6f1f410d
commit 42d6bf03b5
2 changed files with 4 additions and 4 deletions

View File

@ -37,8 +37,8 @@ func (inc *RSI) Update(kline types.KLine, priceF KLinePriceMapper) {
if len(inc.Prices) == inc.Window+1 { if len(inc.Prices) == inc.Window+1 {
diffValues := inc.Prices.Diff() diffValues := inc.Prices.Diff()
avgGain = diffValues.PositiveValues().AbsoluteValues().Sum() / float64(inc.Window) avgGain = diffValues.PositiveValuesOrZero().AbsoluteValues().Sum() / float64(inc.Window)
avgLoss = diffValues.NegativeValues().AbsoluteValues().Sum() / float64(inc.Window) avgLoss = diffValues.NegativeValuesOrZero().AbsoluteValues().Sum() / float64(inc.Window)
} else { } else {
diff := price - inc.Prices[len(inc.Prices)-2] diff := price - inc.Prices[len(inc.Prices)-2]
currentGain := math.Max(diff, 0) currentGain := math.Max(diff, 0)

View File

@ -66,7 +66,7 @@ func (s Float64Slice) Diff() Float64Slice {
return values return values
} }
func (s Float64Slice) PositiveValues() Float64Slice { func (s Float64Slice) PositiveValuesOrZero() Float64Slice {
var values Float64Slice var values Float64Slice
for _, v := range s { for _, v := range s {
values.Push(math.Max(v, 0)) values.Push(math.Max(v, 0))
@ -74,7 +74,7 @@ func (s Float64Slice) PositiveValues() Float64Slice {
return values return values
} }
func (s Float64Slice) NegativeValues() Float64Slice { func (s Float64Slice) NegativeValuesOrZero() Float64Slice {
var values Float64Slice var values Float64Slice
for _, v := range s { for _, v := range s {
values.Push(math.Min(v, 0)) values.Push(math.Min(v, 0))