You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
47 lines
1.2 KiB
47 lines
1.2 KiB
package sig |
|
|
|
import ( |
|
"sig-pub/pkg/indicator" |
|
"sig-pub/pkg/types/series" |
|
) |
|
|
|
// WindowIndicatorSeries 封装 |
|
type WindowIndicatorSeries struct { |
|
indicator.IIndicatorSeries |
|
window int16 |
|
indicator indicator.IWindowIndicator |
|
indicatorContext IOffsetIndicatorContext |
|
} |
|
|
|
func NewWindowIndicatorSeries(window int16, indicator indicator.IWindowIndicator, indicatorContext IOffsetIndicatorContext) *WindowIndicatorSeries { |
|
return &WindowIndicatorSeries{ |
|
window: window, |
|
indicator: indicator, |
|
indicatorContext: indicatorContext, |
|
} |
|
} |
|
|
|
func (s *WindowIndicatorSeries) Get(offset int16) (vector float64) { |
|
// 根据当前相对offset |
|
s.indicatorContext.AddOffset(offset) |
|
vector = s.indicator.Calculate(s.indicatorContext, s.window) |
|
// 计算结束后还原 |
|
s.indicatorContext.AddOffset(-offset) |
|
return |
|
} |
|
|
|
// Series 返回指标值序列降序 |
|
func (s *WindowIndicatorSeries) Series(offset, count int16) (matrix series.Floats) { |
|
// 设置当前相对offset |
|
s.indicatorContext.AddOffset(offset) |
|
for range count { |
|
vector := s.indicator.Calculate(s.indicatorContext, s.window) |
|
matrix.Push(vector) |
|
|
|
offset++ |
|
s.indicatorContext.AddOffset(1) |
|
} |
|
// 计算结束后还原 |
|
s.indicatorContext.AddOffset(-offset) |
|
return |
|
}
|
|
|