ema

package module
v0.0.0-...-5943d28 Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2019 License: Apache-2.0 Imports: 3 Imported by: 8

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

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 New

func New(defaultValue float64, defaultAlpha float64) *EMA

New creates an EMA with the given default value and alpha

func NewDuration

func NewDuration(defaultValue time.Duration, defaultAlpha float64) *EMA

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

func NewWithBeta(defaultValue float64, defaultAlpha float64, defaultBeta float64) *EMA

NewWithBeta is the same as New but supplies a seperate beta to control the decrease rate

func (*EMA) Clear

func (e *EMA) Clear()

Clear clears the EMA

func (*EMA) Get

func (e *EMA) Get() float64

Get gets the EMA

func (*EMA) GetDuration

func (e *EMA) GetDuration() time.Duration

GetDuration is like Get but using time.Duration

func (*EMA) Set

func (e *EMA) Set(v float64)

Set sets the EMA directly.

func (*EMA) SetDuration

func (e *EMA) SetDuration(v time.Duration)

SetDuration is like Set but using time.Duration

func (*EMA) Update

func (e *EMA) Update(v float64) float64

Update is like UpdateAlphaBeta but using the default alpha and beta

func (*EMA) UpdateAlpha

func (e *EMA) UpdateAlpha(v float64, α float64) float64

UpdateAlpha calculates and stores new EMA based on the duration and α value passed in.

func (*EMA) UpdateDuration

func (e *EMA) UpdateDuration(v time.Duration) time.Duration

UpdateDuration is like Update but using time.Duration

Jump to

Keyboard shortcuts

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