Learn R Programming

timeSeries (version 3010.97)

returns: Financial Returns

Description

Compute financial returns from prices or indexes.

Usage

returns(x, ...)

## S3 method for class 'ANY': returns(x, method = c("continuous", "discrete", "compound", "simple"), percentage = FALSE, ...) ## S3 method for class 'timeSeries': returns(x, method = c("continuous", "discrete", "compound", "simple"), percentage = FALSE, na.rm = TRUE, trim = TRUE, ...) getReturns(...) returnSeries(...)

Arguments

percentage
a logical value. By default FALSE, if TRUE the series will be expressed in percentage changes.
method
a character string. Which method should be used to compute the returns, "continuous", "discrete", or "compound", "simple". The second pair of methods is a synonyme for the first two methods.
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.
x
an object of class timeSeries.
...
arguments to be passed.

Value

  • all functions return an object of class timeSeries.

Examples

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

## Continuous Returns - 
   returns(X)
  
## Discrete Returns:
   returns(X, type = "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