periodize_return: Calculate constant growth rates

Description Usage Arguments Details Implementation Examples

View source: R/periodize_return.R

Description

annualize_return() computes the constant annual return of a return stream that is typically longer than one year. This is often called the Compound Annual Growth Rate (CAGR). periodize_return() takes that concept and generalizes it to any valid period.

Usage

1
2
3
4
periodize_return(.r, from_period = "daily", to_period = "yearly",
  type = "arithmetic")

annualize_return(.r, from_period = "daily", type = "arithmetic")

Arguments

.r

A vector of returns.

from_period

The period the returns are currently in.

to_period

The period that you want to calculate a constant growth rate for.

type

Either "arithmetic" or "log" returns.

Details

annualize_return() is a common special case of periodize_return() in which the to_period argument is set to "yearly".

Implementation

The general equation for periodize_return() solves for r_period in either:

(1 + r_period) ^ multiplier = (1 + r_1)(1 + r_2) ... (1 + r_n)

r_period * multiplier = r_1 + r_2 + ... + r_n

where r_period is the constant compound growth ratio for the specified to_period. The multiplier is the same for the arithmetic and log formulas and is calculated as:

multiplier = length(.r) * annualization_multiplier(to_period) / annualization_multiplier(from_period)

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
data(FANG)

FANG_time <- FANG %>%
  as_tbl_time(date) %>%
  dplyr::group_by(symbol)

# Compound Annual Growth Rate (CAGR)
FANG_time %>%
  calculate_return(adjusted) %>%
  dplyr::summarise(CAGR = annualize_return(adjusted_return))

# Compound Monthly Growth Rate (CMGR)
FANG_time %>%
  calculate_return(adjusted, period = "daily") %>%
  dplyr::summarise(
    CMGR = periodize_return(
      adjusted_return,
      from_period = "daily",
      to_period = "monthly"
    )
  )

# Equivalent 6 month growth rate
FANG_time %>%
  calculate_return(adjusted, period = "monthly") %>%
  dplyr::summarise(
    CMGR = periodize_return(
      adjusted_return,
      from_period = "monthly",
      to_period = "6 month"
    )
  )

# One other useful feature is to take a daily return series and
# find the single daily return value that would give equivalent
# results if compounded over the same number of days
FANG_time %>%
  calculate_return(adjusted, period = "daily") %>%
  dplyr::summarise(
    equivalent_constant_daily_return = periodize_return(
      adjusted_return,
      from_period = "daily",
      to_period = "daily"
    )
  )

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