Documentation ¶
Overview ¶
Package ema provides an exponential moving average. It can hold floating point values up to 3 decimal points in precision and provides a convenience interface for keeping EMAs of time.Durations.
Index ¶
- type EMA
- func New(defaultValue float64, defaultAlpha float64) *EMA
- func NewDuration(defaultValue time.Duration, defaultAlpha float64) *EMA
- func NewDurationWithBeta(defaultValue time.Duration, defaultAlpha float64, defaultBeta float64) *EMA
- func NewWithBeta(defaultValue float64, defaultAlpha float64, defaultBeta float64) *EMA
- func (e *EMA) Clear()
- func (e *EMA) Get() float64
- func (e *EMA) GetDuration() time.Duration
- func (e *EMA) Set(v float64)
- func (e *EMA) SetDuration(v time.Duration)
- func (e *EMA) Update(v float64) float64
- func (e *EMA) UpdateAlpha(v float64, α float64) float64
- func (e *EMA) UpdateDuration(v time.Duration) time.Duration
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type EMA ¶
type EMA struct {
// contains filtered or unexported fields
}
EMA holds the Exponential Moving Average of a float64 with a the given default α value and a fixed scale of 3 digits. Safe to access concurrently. https://en.wikipedia.org/wiki/Moving_average#Exponential_moving_average. It can also optionally have β which controls decrease rate seperately.
func NewDuration ¶
NewDuration is like New but using time.Duration
func NewDurationWithBeta ¶
func NewDurationWithBeta(defaultValue time.Duration, defaultAlpha float64, defaultBeta float64) *EMA
NewDurationWithBeta is the same as NewDuration but supplies a seperate beta to control the decrease rate
func NewWithBeta ¶
NewWithBeta is the same as New but supplies a seperate beta to control the decrease rate
func (*EMA) GetDuration ¶
GetDuration is like Get but using time.Duration
func (*EMA) SetDuration ¶
SetDuration is like Set but using time.Duration
func (*EMA) UpdateAlpha ¶
UpdateAlpha calculates and stores new EMA based on the duration and α value passed in.