This commit is contained in:
Will Charczuk 2019-02-13 16:09:26 -08:00
parent 3cb33d48d3
commit 26eaa1d898
76 changed files with 1076 additions and 1717 deletions

View file

@ -2,8 +2,6 @@ package chart
import (
"fmt"
"github.com/wcharczuk/go-chart/seq"
)
// Interface Assertions.
@ -22,7 +20,7 @@ type BollingerBandsSeries struct {
K float64
InnerSeries ValuesProvider
valueBuffer *seq.Buffer
valueBuffer *ValueBuffer
}
// GetName returns the name of the time series.
@ -72,7 +70,7 @@ func (bbs *BollingerBandsSeries) GetBoundedValues(index int) (x, y1, y2 float64)
return
}
if bbs.valueBuffer == nil || index == 0 {
bbs.valueBuffer = seq.NewBufferWithCapacity(bbs.GetPeriod())
bbs.valueBuffer = NewValueBufferWithCapacity(bbs.GetPeriod())
}
if bbs.valueBuffer.Len() >= bbs.GetPeriod() {
bbs.valueBuffer.Dequeue()
@ -81,8 +79,8 @@ func (bbs *BollingerBandsSeries) GetBoundedValues(index int) (x, y1, y2 float64)
bbs.valueBuffer.Enqueue(py)
x = px
ay := seq.New(bbs.valueBuffer).Average()
std := seq.New(bbs.valueBuffer).StdDev()
ay := NewSeq(bbs.valueBuffer).Average()
std := NewSeq(bbs.valueBuffer).StdDev()
y1 = ay + (bbs.GetK() * std)
y2 = ay - (bbs.GetK() * std)
@ -101,15 +99,15 @@ func (bbs *BollingerBandsSeries) GetBoundedLastValues() (x, y1, y2 float64) {
startAt = 0
}
vb := seq.NewBufferWithCapacity(period)
vb := NewValueBufferWithCapacity(period)
for index := startAt; index < seriesLength; index++ {
xn, yn := bbs.InnerSeries.GetValues(index)
vb.Enqueue(yn)
x = xn
}
ay := seq.Seq{Provider: vb}.Average()
std := seq.Seq{Provider: vb}.StdDev()
ay := Seq{vb}.Average()
std := Seq{vb}.StdDev()
y1 = ay + (bbs.GetK() * std)
y2 = ay - (bbs.GetK() * std)