EMA: Create a streamer for calculating the exponential moving...

Description Format Methods Examples

Description

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

Format

An R6Class generator object

Methods

Public 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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
exp_mean <- EMA$new(c(1, 2))
exp_mean$update(c(3, 4))
exp_mean$value
#> [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))

THargreaves/online-oceanarium documentation built on Jan. 13, 2022, 10:39 p.m.