The formula is simply: overall.rate = prod(gains + 1) - 1. If xday is specified, then it converts to x-day growth rate. For example, if balances is a vector of stock gains over a five-day period, say c(-0.02, -0.01, 0.01, 0.02, 0.01), then the total growth rate is approximately 0.0095 over five trading days. If xday.rate is set to 1, this rate is converted to an average daily rate of approximately 0.0019.

1 | ```
gains.rate(gains, xday.rate = NULL, nas = FALSE)
``` |

`gains` |
Numeric vector of stock or investment gains. Has to be daily gains if you want to calculate x-day rather than overall growth. |

`xday.rate` |
Number of days for growth rate calculation. If unspecified, function returns total growth. If set to 251, function would return annual growth rate. |

`nas` |
If TRUE, function finds and removes any missing values (NA's) in prices vector. The default is FALSE to maximize speed for the usual case where there are no missing values. |

Numeric value indicating the growth rate.

Dane R. Van Domelen

Acknowledgment: This material is based upon work supported by the National Science Foundation Graduate Research Fellowship under Grant No. DGE-0940903.

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 60.7% annual growth
gains.rate(daily.gains, 251)
``` |

Questions? Problems? Suggestions? Tweet to @rdrrHQ or email at ian@mutexlabs.com.

Please suggest features or report bugs with the GitHub issue tracker.

All documentation is copyright its authors; we didn't write any of that.