funapply: Apply a function to an xts using multiple rolling windows.

Description Usage Arguments Details Value

Description

Runs rollapplyr multiple times on an xts matrix to apply a function using a set of different rolling window sizes.

Usage

1

Arguments

data

A single column xts matrix containing prices or returns.

FUN

The name of the function that will be applied.

windows

A vector of window sizes from which to loop over and pass to the rollapplyr function at each iteration.

...

additional arguments passed to FUN (this is fixed for all iterations).

Details

The data argument is assumed to be an xts matrix. The function is any function that can be used with rollapplyr. The windows argument is a vector corresponding to the rolling window size passed to FUN and rollapplyr during each iteration.

For example, if windows == c(20, 40, 100), then there will be three iterations as follows: the window size will be 20 periods for the first iteration, 40 for the second iteration, and 100 periods for the third iteration.

Since rollapplyr is used, the leading rows will contain NAs up to the window size + 1. Use the zoo:na.locf function to remove the leading NAs.

Value

An xts matrix with the same number of columns as the length of the windows parameter, where each column corresponds to one of the window sizes i.e. a column is associated with an iteration.


jeanmarcgp/xtsanalytics documentation built on May 19, 2019, 12:38 a.m.