methods-mathOps: Mathematical operations on 'timeSeries'

mathR Documentation

Mathematical operations on 'timeSeries'

Description

Functions and methods for mathematical operations on "timeSeries".

Usage

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

## S3 method for class 'timeSeries'
quantile(x, ...)
## S3 method for class '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.

See Also

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

## mathematical operations: | +/- * ^ ...
TS^2
TS[2:4]
OR = returns(TS)
OR
OR > 0

## median, quantile
median(TS)
quantile(TS)

TS[3] <- NA # to demonstrate 'na.rm'
median(TS)   # NA
#quantile(TS) # error

median(TS, na.rm = TRUE)   
quantile(TS, na.rm = TRUE)

timeSeries documentation built on Jan. 13, 2024, 8:16 p.m.