EMA creates a streaming algorithm that can be used to calculate the exponential moving average of incoming values

Format

An R6Class generator object

Methods


Method new()

Creates a new EMA streamer object.

Usage

EMA$new(x = NULL, alpha = 0.5)

Arguments

x

values to be used during initialization (optional)

alpha

value of the smoothing factor (0.5 by default)

Returns

The new EMA (invisibly)

Examples

exp_mean <- EMA$new()


Method update()

Updates the EMA with a stream of new values

Usage

EMA$update(x)

Arguments

x

a vector of values to update the EMA

Returns

The updated EMA (invisibly)

Examples

exp_mean <- EMA$new(c(1,2))
exp_mean$update(c(3,4))


Method clone()

The objects of this class are cloneable with this method.

Usage

EMA$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.

Examples

exp_mean <- EMA$new(c(1, 2))
exp_mean$update(c(3, 4))
exp_mean$value
#> [1] 3.266667
#> [1] 3.266667


## ------------------------------------------------
## Method `EMA$new`
## ------------------------------------------------

exp_mean <- EMA$new()


## ------------------------------------------------
## Method `EMA$update`
## ------------------------------------------------

exp_mean <- EMA$new(c(1,2))
exp_mean$update(c(3,4))