View source: R/financial_functions.R
| fin_CAGR | R Documentation |
Calculates the constant, period-over-period growth rate required for an investment to grow from a beginning value to an ending value over a specified number of periods.
The Compound Annual Growth Rate (CAGR) is computed as: CAGR = (End value/Start value)^(1/t) - 1
Where t is the number of years (periods).
fin_CAGR(beginningValue, endingValue, numYears, digits = 3)
beginningValue |
Starting value of investment |
endingValue |
Ending value of investment |
numYears |
Number of periods (e.g., years) elapsing from begin to end |
digits |
rounding the returned value (default = 3) |
A numeric value representing the Compound Annual Growth Rate as a decimal (e.g., 0.096 for 9.6
This function includes input validation and will 'stop()' with an error if any inputs are non-numeric or non-positive.
# --- Basic Usage ---
rate = fin_CAGR(beginningValue = 100, endingValue = 190, numYears = 7)
print(rate)
# --- Formatting as Percentage ---
percent = paste0(round(rate * 100, 2), "%")
print(percent)
# --- Example with a Loss ---
fin_CAGR(100, 50, 5)
## Not run:
# --- Examples of what will fail ---
fin_CAGR(0, 100, 5) # Error: Inputs must be positive
fin_CAGR(100, 150, -1) # Error: Inputs must be positive
fin_CAGR("100", 150, 5) # Error: All inputs must be numeric
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.