movingaverage

package
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 9, 2022 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

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.

func (*AvgOverTime) Clear

func (aot *AvgOverTime) Clear()

Clear clears the AvgOverTime.

func (*AvgOverTime) Get

func (aot *AvgOverTime) Get() float64

Get returns change rate in the last 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 NewEMA

func NewEMA(decays ...float64) *EMA

NewEMA returns an EMA.

func (*EMA) Add

func (e *EMA) Add(num float64)

Add adds a data point.

func (*EMA) Get

func (e *EMA) Get() float64

Get returns the result of the data set.If return 0.0, it means the filter can not be wake up.

func (*EMA) Reset

func (e *EMA) Reset()

Reset cleans the data set.

func (*EMA) Set

func (e *EMA) Set(n float64)

Set = Reset + Add.

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 NewHMA

func NewHMA(sizes ...float64) *HMA

NewHMA returns a WMA.

func (*HMA) Add

func (h *HMA) Add(n float64)

Add adds a data point.

func (*HMA) Get

func (h *HMA) Get() float64

Get returns the weight average of the data set.

func (*HMA) Reset

func (h *HMA) Reset()

Reset cleans the data set.

func (*HMA) Set

func (h *HMA) Set(n float64)

Set = Reset + Add.

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 NewMaxFilter

func NewMaxFilter(size int) *MaxFilter

NewMaxFilter returns a MaxFilter.

func (*MaxFilter) Add

func (r *MaxFilter) Add(n float64)

Add adds a data point.

func (*MaxFilter) Get

func (r *MaxFilter) Get() float64

Get returns the maximum of the data set.

func (*MaxFilter) Reset

func (r *MaxFilter) Reset()

Reset cleans the data set.

func (*MaxFilter) Set

func (r *MaxFilter) Set(n float64)

Set = Reset + Add.

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) Add

func (r *MedianFilter) Add(n float64)

Add adds a data point.

func (*MedianFilter) Get

func (r *MedianFilter) Get() float64

Get returns the median of the data set.

func (*MedianFilter) Reset

func (r *MedianFilter) Reset()

Reset cleans the data set.

func (*MedianFilter) Set

func (r *MedianFilter) Set(n float64)

Set = Reset + Add.

type MovingAvg

type MovingAvg interface {
	// Add adds a data point to the data set.
	Add(data float64)
	// Get returns the moving average.
	Get() 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 SafeQueue

type SafeQueue struct {
	// contains filtered or unexported fields
}

SafeQueue is a concurrency safe queue

func NewSafeQueue

func NewSafeQueue() *SafeQueue

NewSafeQueue return a SafeQueue

func (*SafeQueue) Init

func (sq *SafeQueue) Init()

Init implement init

func (*SafeQueue) PopFront

func (sq *SafeQueue) PopFront() interface{}

PopFront implement PopFront

func (*SafeQueue) PushBack

func (sq *SafeQueue) PushBack(v interface{})

PushBack implement PushBack

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) Get

func (t *TimeMedian) Get() float64

Get returns change rate in the median of the several intervals.

func (*TimeMedian) GetFilledPeriod

func (t *TimeMedian) GetFilledPeriod() int

GetFilledPeriod returns filled period.

func (*TimeMedian) GetInstantaneous

func (t *TimeMedian) GetInstantaneous() float64

GetInstantaneous returns instantaneous speed

func (*TimeMedian) Set

func (t *TimeMedian) Set(avg float64)

Set sets the given average.

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 NewWMA

func NewWMA(sizes ...int) *WMA

NewWMA returns a WMA.

func (*WMA) Add

func (w *WMA) Add(n float64)

Add adds a data point.

func (*WMA) Get

func (w *WMA) Get() float64

Get returns the weight average of the data set.

func (*WMA) Reset

func (w *WMA) Reset()

Reset cleans the data set.

func (*WMA) Set

func (w *WMA) Set(n float64)

Set = Reset + Add.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL