Learn R Programming

timeSeries (version 4041.111)

returns: Financial returns

Description

Compute financial returns from prices or indexes.

Usage

returns(x, ...)
returns0(x, ...)

# S4 method for ANY returns(x, method = c("continuous", "discrete", "compound", "simple"), percentage = FALSE, ...) # S4 method for timeSeries returns(x, method = c("continuous", "discrete", "compound", "simple"), percentage = FALSE, na.rm = TRUE, trim = TRUE, ...)

Value

an object of class timeSeries.

returns0 returns an untrimmed series with the first row of returns set to zero(s).

Arguments

x

an object of class timeSeries.

method

a character string. Which method should be used to compute the returns, one of "continuous", "discrete", or "compound", "simple". The second pair of methods is a synonym for the first two methods.

percentage

a logical value. By default FALSE, if TRUE the series will be expressed in percentage changes.

na.rm

a logical value. Should NAs be removed? By default TRUE.

trim

a logical value. Should the time series be trimmed? By Default TRUE.

...

arguments to be passed.

See Also

cumulated, drawdowns, splits, spreads, midquotes, index2wealth

Examples

Run this code
## Load Microsoft Data - 
   setRmetricsOptions(myFinCenter = "GMT")
   data(MSFT)
   X = MSFT[1:10, 1:4]
   X

## Continuous Returns - 
   returns(X)
   returns0(X)
  
## Discrete Returns:
   returns(X, method = "discrete")
   
## Don't trim:
   returns(X, trim = FALSE)
   
## Use Percentage Values:
   returns(X, percentage = TRUE, trim = FALSE)

Run the code above in your browser using DataLab