calculate_return: Calculate returns at specified intervals

Description Usage Arguments Details

View source: R/calculate_return.R

Description

Calculate arithmetic or log returns at specified periods.

Usage

1
2
calculate_return(.tbl_time, ..., type = "arithmetic", period = "daily",
  start_date = NULL, suffix = "return")

Arguments

.tbl_time

A tbl_time object

...

The columns to calculate returns for. One or more unquoted column names separated by commas.

type

Either "arithmetic" or "log" returns.

period

A character specification used for time-based grouping. The general format to use is "frequency period" where frequency is a number like 1 or 2, and period is an interval like weekly or yearly. There must be a space between the two.

Note that you can pass the specification in a flexible way:

  • 1 Year: '1 year' / '1 Y' / '1 yearly' / 'yearly'

This shorthand is available for year, quarter, month, day, hour, minute, second, millisecond and microsecond periodicities.

Additionally, you have the option of passing in a vector of dates to use as custom and more flexible boundaries.

start_date

Optional argument used to specify the start date for the first group. The default is to start at the closest period boundary below the minimum date in the supplied index.

suffix

For each column specified in ..., this is the suffix that is appended onto the name of the new column that corresponds to the return.

Details

These functions make no attempt to ensure that you have a full period in your return calculations. This means that if you calculate monthly returns from daily returns but you do not have a complete month of returns for your first month, you may get a value that does not make much sense. It is up to the user to keep this in mind!


DavisVaughan/tidyfinance documentation built on May 24, 2019, 8:46 p.m.