Learn R Programming

TTR (version 0.2)

runFun: Analysis of Running/Rolling/Moving Windows

Description

Various functions to analyze data over a moving window of periods.

Usage

runSum(x, n=10, cumulative=FALSE)
  runMin(x, n=10, cumulative=FALSE)
  runMax(x, n=10, cumulative=FALSE)
  runMean(x, n=10, cumulative=FALSE)
  runMedian(x, n=10, non.unique="mean", cumulative=FALSE)
  runCov(x, y, n=10, use="all.obs", sample=TRUE, cumulative=FALSE)
  runCor(x, y, n=10, use="all.obs", sample=TRUE, cumulative=FALSE)
  runVar(x, y=NULL, n=10, sample=TRUE, cumulative=FALSE)
  runSD(x, n=10, sample=TRUE, cumulative=FALSE)
  runMAD(x, n=10, center=NULL, stat="median",
         constant=1.4826, non.unique="mean", cumulative=FALSE)

Arguments

x
Object coercible to xts or matrix.
y
Object coercible to xts or matrix.
n
Number of periods to use in the window or, if cumulative=TRUE, the number of obversations to use before the first result is returned.
cumulative
Logical, use from-inception calculation?
sample
Logical, sample covariance if TRUE (denominator of n-1)
use
Only "all.obs" currently implemented.
non.unique
One of 'mean', 'max', or 'min'; which compute their respective statistics for the two middle values of even-sized samples.
center
The values to use as the measure of central tendency, around which to calculate deviations. The default (NULL) uses the median.
stat
Statistic to calculate, one of 'median' or 'mean' (e.g. median absolute deviation or mean absolute deviation, respectively.)
constant
Scale factor applied to approximate the standard deviation.

Value

  • A object of the same class as x and y or a vector (if try.xts fails).
  • runSumreturns sums over a n-period moving window.
  • runMinreturns minimums over a n-period moving window.
  • runMaxreturns maximums over a n-period moving window.
  • runMeanreturns means over a n-period moving window.
  • runMedianreturns medians over a n-period moving window.
  • runCovreturns covariances over a n-period moving window.
  • runCorreturns correlations over a n-period moving window.
  • runVarreturns variances over a n-period moving window.
  • runSDreturns standard deviations over a n-period moving window.
  • runMADreturns median/mean absolute deviations over a n-period moving window.