Description Usage Arguments Details Value Functions Examples
Functions cumsum_na() and cumprod_na() are similar to cumsum() and cumprod(), except that they ignore any NAs present within the argument matrix.
1 2 3 | cumsum_na(x)
cumprod_na(x)
|
x |
Value of the series from which to compute the cumulative sum or product. |
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.
A numeric vector of the cumulative sum or product.
cumprod_na
: Compute the cumulative sum while ignoring NAs
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.
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.