Functions and methods for mathematical operations on "timeSeries".

## Usage

# S4 method for timeSeries,timeSeries
Ops(e1, e2)
# S4 method for timeSeries
Math(x)
# S4 method for timeSeries
Math2(x, digits)

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

## Arguments

x

an object of class timeSeries.

digits

number of digits to be used in 'round' or 'signif'.

e1, e2

at least one of the two objects is from class "timeSeries" (for the methods described on this page).

na.rm

a logical value: should missing values be removed?

...

arguments to be passed.

## Details

The methods for the Math and Math2 groups of mathematical functions return 'timeSeries' objects. Most of them work element-wise on the data part of the time series with the exception of cummin, cummax, cumsum, and cumprod which work columnwise.

The Ops group includes mathematical operators. For the binary operators methods are defined for pairs of at least one 'timeSeries' object. These work as expected on the data parts of the arguments. If the operation gives a value of the same dimension as the data part of the 'timeSeries' object, it replaces the original data in the object.

There are also methods for quantile and median.

## Value

the value from a mathematical or logical operation operating on objects of class "timeSeries" or the value computed by a mathematical function.

colCumXXX

## Examples

## Create an Artificial 'timeSeries' Object -
setRmetricsOptions(myFinCenter = "GMT")
charvec = timeCalendar()
set.seed(4711)
data = matrix(exp(cumsum(rnorm(12, sd = 0.1))))
TS = timeSeries(data, charvec, units = "TS")
TS
#> GMT
#>                   TS
#> 2023-01-01 1.1995824
#> 2023-02-01 1.3757753
#> 2023-03-01 1.5506114
#> 2023-04-01 1.4887865
#> 2023-05-01 1.4005479
#> 2023-06-01 1.2043889
#> 2023-07-01 1.3069906
#> 2023-08-01 1.1867998
#> 2023-09-01 1.1815277
#> 2023-10-01 1.2389245
#> 2023-11-01 1.1230263
#> 2023-12-01 0.9596526

## Mathematical Operations: | +/- * ^ ... -
TS^2
#> GMT
#>                  TS
#> 2023-01-01 1.438998
#> 2023-02-01 1.892758
#> 2023-03-01 2.404396
#> 2023-04-01 2.216485
#> 2023-05-01 1.961534
#> 2023-06-01 1.450553
#> 2023-07-01 1.708224
#> 2023-08-01 1.408494
#> 2023-09-01 1.396008
#> 2023-10-01 1.534934
#> 2023-11-01 1.261188
#> 2023-12-01 0.920933
TS[2:4]
#> [1] 1.375775 1.550611 1.488787
OR = returns(TS)
OR
#> GMT
#>                      TS
#> 2023-02-01  0.137043950
#> 2023-03-01  0.119631824
#> 2023-04-01 -0.040687920
#> 2023-05-01 -0.061097880
#> 2023-06-01 -0.150891205
#> 2023-07-01  0.081754941
#> 2023-08-01 -0.096466789
#> 2023-09-01 -0.004452208
#> 2023-10-01  0.047435474
#> 2023-11-01 -0.098216632
#> 2023-12-01 -0.157211053
OR > 0
#> GMT
#>               TS
#> 2023-02-01  TRUE
#> 2023-03-01  TRUE
#> 2023-04-01 FALSE
#> 2023-05-01 FALSE
#> 2023-06-01 FALSE
#> 2023-07-01  TRUE
#> 2023-08-01 FALSE
#> 2023-09-01 FALSE
#> 2023-10-01  TRUE
#> 2023-11-01 FALSE
#> 2023-12-01 FALSE