gains_rate: Calculate Growth Rate from Sequence of Gains

Description Usage Arguments Value Examples

View source: R/gains_rate.R

Description

The formula is simply: prod(gains + 1) - 1. If units.out is specified, then it converts to x-unit growth rate.

Usage

1
gains_rate(gains, units.out = NULL)

Arguments

gains

Data frame with one column of gains for each investment (can be a numeric vector if there is only one).

units.out

Numeric value specifying the number of units for growth rate calculation, if you want something other than total growth. For annualized growth rate, set to 252 if gains has daily gains, 12 if gains has monthly gains, etc.

Value

Numeric vector.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
# Create vector of daily gains for a hypothetical stock
daily.gains <- c(-0.02, -0.01, 0.01, 0.02, 0.01)

# Overall growth is 0.95%
gains_rate(daily.gains)

# Average daily growth is 0.19%
gains_rate(daily.gains, 1)

# Corresponds to 61.0% annual growth
gains_rate(daily.gains, 252)

vandomed/stocks documentation built on July 22, 2020, 3:25 a.m.