This commit is contained in:
Will Charczuk 2016-07-27 12:34:15 -07:00
parent 4f381fa4dc
commit 6533e951e7
8 changed files with 309 additions and 16 deletions

View file

@ -35,6 +35,17 @@ func (sma SMASeries) Len() int {
return sma.InnerSeries.Len()
}
// GetPeriod returns the window size.
func (sma SMASeries) GetPeriod(defaults ...int) int {
if sma.Period == 0 {
if len(defaults) > 0 {
return defaults[0]
}
return DefaultSimpleMovingAveragePeriod
}
return sma.Period
}
// GetValue gets a value at a given index.
func (sma SMASeries) GetValue(index int) (x, y float64) {
if sma.InnerSeries == nil {
@ -59,17 +70,6 @@ func (sma SMASeries) GetLastValue() (x, y float64) {
return
}
// GetPeriod returns the window size.
func (sma SMASeries) GetPeriod(defaults ...int) int {
if sma.Period == 0 {
if len(defaults) > 0 {
return defaults[0]
}
return DefaultSimpleMovingAveragePeriod
}
return sma.Period
}
func (sma SMASeries) getAverage(index int) float64 {
period := sma.GetPeriod()
floor := MaxInt(0, index-period)