Description Usage Arguments Details Methods (by class) References See Also Examples
Calculate an exponential moving average (EMA) of a time series by applying an exponential kernel to the time series sample path.
1 2 3 4 |
x |
a numeric time series object. |
... |
further arguments passed to or from methods. |
tau |
a finite |
interpolation |
the sample path interpolation method. Either |
Three different time series sample path interpolation schemes are supported for "uts"
objects. Each method implicitly puts different weights on past observation values:
last
: Use last-point interpolation for the time series sample path.. Equivalently, each observation value is weighted proportionally by how long it remained unchanged.
next
: Use next-point interpolation for the time series sample path. Equivalently, each observation value is weighted proportionally by how long it remained the next (i.e. upcoming) observation. For equally spaced time series this method coincides with the usual definition used for such time series, see Proposition 8.8 in Eckner, A. (2014).
linear
: Use linear interpolation of the time series sample path. The behavior is approximately halfway in-between last-point and next-point interpolation.
See the first reference below for precise mathematical definitions.
Depending on the application, one sample path interpolation method will often be preferable. See the corresponding discussion for simple moving averages
.
uts
: exponential moving average for "uts"
objects with finite, non-NA observation values.
Eckner, A. (2017) Algorithms for Unevenly Spaced Time Series: Moving Averages and Other Rolling Operators.
Eckner, A. (2017) Some Properties of Operators for Unevenly Spaced Time Series.
sma
for simple moving averages.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | ema(ex_uts(), ddays(1))
ema(ex_uts(), ddays(1), interpolation="linear")
ema(ex_uts(), ddays(1), interpolation="next")
# Plot a monotonically increasing time series 'x', together with
# a backward-looking and forward-looking EMA.
# Note how the forward-looking SMA is leading the increase in 'x', which
# in turn is leading the increase in the backward-looking SMA.
## Not run:
x <- uts(0:10, Sys.time() + dhours(0:10))
par(mfrow=c(1, 3))
plot(x, ylim=c(0, 10), main="Original time series")
plot(ema(x, dhours(3)), ylim=c(0, 10), main="Backward-looking EMA")
plot(ema(x, dhours(-3)), ylim=c(0, 10), main="Forward-looking EMA")
## End(Not run)
# Plot three different EMAs of a monotonically increasing time series
# Note that EMA_last(x)_t <= EMA_linear(x)_t <= EMA_next(x)_t for all observation times t
## Not run:
x <- uts(0:8, Sys.time() + dhours(0:8))
par(mfrow=c(1, 3))
plot(ema(x, dhours(10), interpolation="last"), ylim=c(0, 3), main="Last-point interpolation")
plot(ema(x, dhours(10), interpolation="linear"), ylim=c(0, 3), main="Linear interpolation")
plot(ema(x, dhours(10), interpolation="next"), ylim=c(0, 3), main="Next-point interpolation")
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.