calculate_return: Calculate returns at specified intervals

Description Usage Arguments Details

View source: R/calculate_return.R


Calculate arithmetic or log returns at specified periods.


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



A tbl_time object


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


Either "arithmetic" or "log" returns.


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.


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.


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


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.