Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

fin-returns

Financial Returns


Description

Compute financial returns from prices or indexes.

Usage

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

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

getReturns(...)
returnSeries(...)

Arguments

x

an object of class timeSeries.

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.

...

arguments to be passed.

Value

all functions return an object of class timeSeries.

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

Note

The functions returnSeries, getReturns, are synonymes for the function returns. We do not recommend to use these functions.

Examples

## 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)

timeSeries

Financial Time Series Objects (Rmetrics)

v3062.100
GPL (>= 2)
Authors
Diethelm Wuertz [aut] (original code), Tobias Setz [cre], Yohan Chalabi [ctb], Martin Maechler [ctb] (<https://orcid.org/0000-0002-8685-9910>)
Initial release
2020-01-24

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.