updates + tests

This commit is contained in:
Will Charczuk 2018-09-07 12:52:30 -07:00
parent 1144b80a46
commit 1555902fc4
13 changed files with 207 additions and 2 deletions

View file

@ -11,6 +11,13 @@ const (
DefaultSimpleMovingAveragePeriod = 16
)
// Interface Assertions.
var (
_ Series = (*SMASeries)(nil)
_ FirstValuesProvider = (*SMASeries)(nil)
_ LastValuesProvider = (*SMASeries)(nil)
)
// SMASeries is a computed series.
type SMASeries struct {
Name string
@ -63,6 +70,17 @@ func (sma SMASeries) GetValues(index int) (x, y float64) {
return
}
// GetFirstValues computes the first moving average value.
func (sma SMASeries) GetFirstValues() (x, y float64) {
if sma.InnerSeries == nil || sma.InnerSeries.Len() == 0 {
return
}
px, _ := sma.InnerSeries.GetValues(0)
x = px
y = sma.getAverage(0)
return
}
// GetLastValues computes the last moving average value but walking back window size samples,
// and recomputing the last moving average chunk.
func (sma SMASeries) GetLastValues() (x, y float64) {