prices.rate {stocks} | R Documentation |
The formula is simply:
overall.rate = prices[length(prices)] / prices[1] - 1
. If
units.rate
is specified, then it converts to x-unit growth rate.
prices.rate(prices, units.rate = NULL, nas = FALSE)
prices |
Numeric vector of stock prices or investment balances. |
units.rate |
Number of units for growth rate calculation. If unspecified, function returns
total growth. To get annualized growth rate, set to 252 if |
nas |
If |
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.
# Create vector of daily closing prices for a hypothetical stock prices <- c(100.4, 98.7, 101.3, 101.0, 100.9) # Overall growth is 0.50% prices.rate(prices) # Average daily growth is 0.12% prices.rate(prices, 1) # Corresponds to 36.6% annualized growth prices.rate(prices, 252)