Learn R Programming

RTL (version 1.3.7)

returns: Compute absolute, relative or log returns.

Description

Computes periodic returns from a dataframe ordered by date

Usage

returns(df = dflong, retType = "abs", period.return = 1, spread = FALSE)

Value

A dataframe object of returns. tibble

Arguments

df

Long dataframe with colnames = c("date","value","series"). character

retType

"abs" for absolute, "rel" for relative, or "log" for log returns. character

period.return

Number of rows over which to compute returns. numeric

spread

TRUE if you want to spread into a long dataframe. logical

Author

Philippe Cote

Examples

Run this code
x <- dflong %>% dplyr::filter(grepl("CL01", series))
returns(df = x, retType = "abs", period.return = 1, spread = TRUE)

Run the code above in your browser using DataLab