Skip to contents

Functions to compute cumulative column statistics.

Usage

# S4 method for timeSeries
colCumsums(x, na.rm = FALSE, ...)

# S4 method for timeSeries
colCummaxs(x, na.rm = FALSE, ...)

# S4 method for timeSeries
colCummins(x, na.rm = FALSE, ...)

# S4 method for timeSeries
colCumprods(x, na.rm = FALSE, ...)

# S4 method for timeSeries
colCumreturns(x, method = c("geometric", "simple"),
                                     na.rm = FALSE, ...)

Arguments

x

a time series, may be an object of class "matrix", or "timeSeries".

na.rm

a logical. Should missing values be removed?

method

a character string to indicate if geometric (TRUE) or simple (FALSE) returns should be computed.

...

arguments to be passed.

Details

These functions compute the requested cumulative quantities columnwise to obtain a matrix of the same dimension as the data. The "timeSeries" methods replace the data part of the original object with the resulting matrix.

The "timeSeries" methods for the Math group functions cummin, cummax, cumsum, and cumprod, work similarly but don't have the na.rm argument.

Value

"matrix" for the default methods of all functions,

"timeSeries" for the "timeSeries" methods

Examples

## simulate return data
x <- matrix(rnorm(24), ncol = 2)
X <- as.timeSeries(x)
     
## cumulative sums  by column  -
class(colCumsums(x))  # "matrix"
#> [1] "matrix" "array" 
class(colCumsums(X))  # "timeSeries"
#> [1] "timeSeries"
#> attr(,"package")
#> [1] "timeSeries"

colCumsums(X)
#>  
#>             SS.1       SS.2
#>  [1,] 0.03533135 -1.3702965
#>  [2,] 0.45848023 -1.1740516
#>  [3,] 0.66070907 -2.3864073
#>  [4,] 2.23691652 -2.5452630
#>  [5,] 1.76787366 -3.2135665
#>  [6,] 2.14745357 -2.3309633
#>  [7,] 1.61282804 -2.1126688
#>  [8,] 2.64454534 -0.3471208
#>  [9,] 3.35411196  0.7952983
#> [10,] 3.43256097  0.2041010
#> [11,] 4.40864141 -0.4137295
#> [12,] 4.14655437 -1.1747465