runStats: Running (a.k.a. Moving Window) Statistics

Description Usage Arguments Details Value Author(s) References See Also Examples

Description

Compute a number of statistics like mean, minimum or maximum of a vector (typically a time series) on a shifting window. The function emphasises efficiency; potential problems (like NA values) should be checked before.

Usage

1
  runStats(what, y, N = 5L, pad = NULL, q = NULL, h = NULL)

Arguments

what

a character vector: "mean", "min" or "max" (‘sum’, ‘abssum’ and others will be added)

y

a numeric vector

N

an integer

pad

replace elements 1 to N - 1 in returned vector. Defaults to NULL (no padding).

q

a quantile (not implemented)

h

the order statistic for a quantile (not implemented)

Details

All algorithms are written in C. There is no error handling, and no handling of NA, Inf or similar values (if such values are in y, runStats will stop with an error).

For quantiles either h or q must be specified, not both.

Value

A numeric vector of length length(y).

Author(s)

Enrico Schumann

References

Gilli, M., Maringer, D. and Schumann, E. (2011) Numerical Methods and Optimization in Finance. Elsevier. http://www.elsevierdirect.com/product.jsp?isbn=9780123756626

See Also

A number of packages already include such computations. See, for examples, packages caTools, zoo or TTR.

Examples

1
2
3
4
5
6
y <- rnorm(100)
N <- 10L
runStats("min", y, N)

N <- length(y)
runStats("min", y, N)[N] == min(y)

enricoschumann/runStats documentation built on May 16, 2019, 7:48 a.m.