gains_rate {stocks} | R Documentation |
Calculate Growth Rate From a Vector of Gains
Description
The formula is simply: prod(gains + 1) - 1
. If units.rate
is
specified, then it converts to x-unit growth rate.
Usage
gains_rate(gains, units.rate = NULL)
Arguments
gains |
Numeric matrix with 1 column of gains for each investment (can be a vector if there is only one). |
units.rate |
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 |
Value
Numeric value if gains
is a vector, numeric matrix if
gains
is a matrix.
Examples
# 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)
[Package stocks version 1.1.4 Index]