WMA creates a streaming algorithm that can be used to keep track of the weighted mean of incoming values.

In an n-day WMA the latest day has weight n, the second latest n-1, etc., down to one.

Format

An R6Class generator object

Methods


Method new()

Creates a new WMA streamer object.

Usage

WMA$new(x = NULL)

Arguments

x

values to be used during initialisation (optional)

Returns

The new WMA (invisibly)

Examples

weighted_mean <- WMA$new()


Method update()

Resets the WMA streamer object.

Usage

WMA$update(x)

Arguments

x

values to be added to the stream

Returns

The updated WMA (invisibly)

Examples

weighted_mean <- WMA$new()
weighted_mean$update(c(1, 2))


Method clone()

The objects of this class are cloneable with this method.

Usage

WMA$clone(deep = FALSE)

Arguments

deep

Whether to make a deep clone.

Examples

mean <- WMA$new(c(1, 2))
mean$update(c(3, 4))
mean$value
#> [1] 7.5
#> [1] 7.5


## ------------------------------------------------
## Method `WMA$new`
## ------------------------------------------------

weighted_mean <- WMA$new()


## ------------------------------------------------
## Method `WMA$update`
## ------------------------------------------------

weighted_mean <- WMA$new()
weighted_mean$update(c(1, 2))