Documentation ¶
Index ¶
- type AvgOverTime
- func (aot *AvgOverTime) Add(delta float64, interval time.Duration)
- func (aot *AvgOverTime) Clear()
- func (aot *AvgOverTime) Clone() *AvgOverTime
- func (aot *AvgOverTime) Get() float64
- func (aot *AvgOverTime) GetInstantaneous() float64
- func (aot *AvgOverTime) GetIntervalSum() time.Duration
- func (aot *AvgOverTime) IsFull() bool
- func (aot *AvgOverTime) Set(avg float64)
- type EMA
- type HMA
- type MaxFilter
- type MedianFilter
- type MovingAvg
- type TimeMedian
- type WMA
- type WeightAllocator
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AvgOverTime ¶
type AvgOverTime struct {
// contains filtered or unexported fields
}
AvgOverTime maintains change rate in the last avgInterval.
AvgOverTime takes changes with their own intervals, stores recent changes that happened in the last avgInterval, then calculates the change rate by (sum of changes) / (sum of intervals).
func NewAvgOverTime ¶
func NewAvgOverTime(interval time.Duration) *AvgOverTime
NewAvgOverTime returns an AvgOverTime with given interval.
func (*AvgOverTime) Add ¶
func (aot *AvgOverTime) Add(delta float64, interval time.Duration)
Add adds recent change to AvgOverTime. It will pop item until the retain item's sum is greater than avgInterval. such as: que [1,1,1,6], avgInterval is 5. It will pop 6 if adding 2, the retaining item's sum is 5(2,1,1,1) >= avgInterval. It can't pop 6 if adding 1, the retaining item's sum is 4(1,1,1,1) < avgInterval.
func (*AvgOverTime) Clone ¶
func (aot *AvgOverTime) Clone() *AvgOverTime
Clone returns a copy of AvgOverTime
func (*AvgOverTime) Get ¶
func (aot *AvgOverTime) Get() float64
Get returns change rate in the last interval.
func (*AvgOverTime) GetInstantaneous ¶
func (aot *AvgOverTime) GetInstantaneous() float64
GetInstantaneous returns the value just added.
func (*AvgOverTime) GetIntervalSum ¶
func (aot *AvgOverTime) GetIntervalSum() time.Duration
GetIntervalSum returns the sum of interval
func (*AvgOverTime) IsFull ¶
func (aot *AvgOverTime) IsFull() bool
IsFull returns whether AvgOverTime is full
func (*AvgOverTime) Set ¶
func (aot *AvgOverTime) Set(avg float64)
Set sets AvgOverTime to the given average.
type EMA ¶
type EMA struct {
// contains filtered or unexported fields
}
EMA works as an exponential moving average filter. References: https://en.wikipedia.org/wiki/Moving_average#Exponential_moving_average.
func (*EMA) Get ¶
Get returns the result of the data set.If return 0.0, it means the filter can not be wake up.
func (*EMA) GetInstantaneous ¶
GetInstantaneous returns the value just added.
type HMA ¶
type HMA struct {
// contains filtered or unexported fields
}
HMA works as hull moving average There are at most `size` data points for calculating. References: https://www.fidelity.com/learning-center/trading-investing/technical-analysis/technical-indicator-guide/hull-moving-average
func (*HMA) GetInstantaneous ¶
GetInstantaneous returns the value just added.
type MaxFilter ¶
type MaxFilter struct {
// contains filtered or unexported fields
}
MaxFilter works as a maximum filter with specified window size. There are at most `size` data points for calculating.
func (*MaxFilter) GetInstantaneous ¶
GetInstantaneous returns the value just added.
type MedianFilter ¶
type MedianFilter struct {
// contains filtered or unexported fields
}
MedianFilter works as a median filter with specified window size. There are at most `size` data points for calculating. References: https://en.wikipedia.org/wiki/Median_filter.
func NewMedianFilter ¶
func NewMedianFilter(size int) *MedianFilter
NewMedianFilter returns a MedianFilter.
func (*MedianFilter) Clone ¶
func (r *MedianFilter) Clone() *MedianFilter
Clone returns a copy of MedianFilter
func (*MedianFilter) Get ¶
func (r *MedianFilter) Get() float64
Get returns the median of the data set.
func (*MedianFilter) GetInstantaneous ¶
func (r *MedianFilter) GetInstantaneous() float64
GetInstantaneous returns the value just added.
type MovingAvg ¶
type MovingAvg interface { // Add adds a data point to the data set. Add(data float64) // Get returns the moving average. Get() float64 // GetInstantaneous returns the value just added. GetInstantaneous() float64 // Reset cleans the data set. Reset() // Set = Reset + Add Set(data float64) }
MovingAvg provides moving average. Ref: https://en.wikipedia.org/wiki/Moving_average
type TimeMedian ¶
type TimeMedian struct {
// contains filtered or unexported fields
}
TimeMedian is AvgOverTime + MedianFilter Size of MedianFilter should be larger than double size of AvgOverTime to denoisy. Delay is aotSize * mfSize * reportInterval/4 and the min filled period is aotSize * reportInterval, which is not related with mfSize
func NewTimeMedian ¶
func NewTimeMedian(aotSize, mfSize int, reportInterval time.Duration) *TimeMedian
NewTimeMedian returns a TimeMedian with given size.
func (*TimeMedian) Add ¶
func (t *TimeMedian) Add(delta float64, interval time.Duration)
Add adds recent change to TimeMedian.
func (*TimeMedian) Clone ¶
func (t *TimeMedian) Clone() *TimeMedian
Clone returns a copy of TimeMedian
func (*TimeMedian) Get ¶
func (t *TimeMedian) Get() float64
Get returns change rate in the median of the several intervals.
func (*TimeMedian) GetInstantaneous ¶
func (t *TimeMedian) GetInstantaneous() float64
GetInstantaneous returns instantaneous speed
type WMA ¶
type WMA struct {
// contains filtered or unexported fields
}
WMA works as a weight with specified window size. There are at most `size` data points for calculating. References:https://en.wikipedia.org/wiki/Moving_average#Weighted_moving_average
func (*WMA) GetInstantaneous ¶
GetInstantaneous returns the value just added.
type WeightAllocator ¶
type WeightAllocator struct {
// contains filtered or unexported fields
}
WeightAllocator is used to alloc weight for cache. When we need to use multiple items from the cache, we may need to assign different weights to these items. WeightAllocator will divide these items into some segments whose number named as segNum which should great than 0. And the items at first segment will be assigned more weight that is `segNum` times that of item at last segment. If you want assign same weights, just input segNum as 1. If length is 10 and segNum is 3, it will make the weight arrry as [3,3,3,3,2,2,2,1,1,1], and then uniform it : [3,3,3,3,2,2,2,1,1,1]/sum(arr)=arr/21, And the final weight is [0.143,0.143,0.143,0.143,0.095,0.095,0.095,0.047,0.047,0.047]; If length is 10 and segNum is 1, the weight is [0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1,0.1]; If length is 3 and segNum is 3, the weight is [0.5,0.33,0.17].
func NewWeightAllocator ¶
func NewWeightAllocator(length, segNum int) *WeightAllocator
NewWeightAllocator returns a new WeightAllocator.
func (*WeightAllocator) Get ¶
func (a *WeightAllocator) Get(i int) float64
Get returns weight at pos i