Description Format Methods Examples
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.
An R6Class
generator object
new()
Creates a new WMA
streamer object.
WMA$new(x = NULL)
x
values to be used during initialisation (optional)
The new WMA
(invisibly)
weighted_mean <- WMA$new()
update()
Resets the WMA
streamer object.
WMA$update(x)
x
values to be added to the stream
The updated WMA
(invisibly)
weighted_mean <- WMA$new() weighted_mean$update(c(1, 2))
clone()
The objects of this class are cloneable with this method.
WMA$clone(deep = FALSE)
deep
Whether to make a deep clone.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | mean <- WMA$new(c(1, 2))
mean$update(c(3, 4))
mean$value
#> [1] 7.5
## ------------------------------------------------
## Method `WMA$new`
## ------------------------------------------------
weighted_mean <- WMA$new()
## ------------------------------------------------
## Method `WMA$update`
## ------------------------------------------------
weighted_mean <- WMA$new()
weighted_mean$update(c(1, 2))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.