cumsum_na: Compute cumulative sums or products and ignores NAs.

Description Usage Arguments Details Value Functions Examples

Description

Functions cumsum_na() and cumprod_na() are similar to cumsum() and cumprod(), except that they ignore any NAs present within the argument matrix.

Usage

1
2
3

Arguments

x

Value of the series from which to compute the cumulative sum or product.

Details

NAs are ignored by assuming they equal zeroes for cumsum_na() and equal ones for cumprod_na(). These functions work on vectors and xts matrices. With an xts matrix, it applies cumprod or cumsum on every column.

Value

A numeric vector of the cumulative sum or product.

Functions

Examples

1
2
3
4
5
6
7
8
cumsum_na(c(NA, 1, 2, 1, NA, 0, 0))
cumprod_na(c(NA, 1, 2, 1.3, NA, 1, 2.5, NA))

# compute returns on xts_data, first row contains NAs
rets <- ROC(xts_data, type="discrete")
ecurves <- cumprod_na(1 + rets)
xtsplot(ecurves, main = 'Equity curves')
xtsplot(xts_data, main = 'Prices')   # identical since normalized.

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