fin_CAGR: Calculate Compound Annual Growth Rate (CAGR)

View source: R/financial_functions.R

fin_CAGRR Documentation

Calculate Compound Annual Growth Rate (CAGR)

Description

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).

Usage

fin_CAGR(beginningValue, endingValue, numYears, digits = 3)

Arguments

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)

Value

A numeric value representing the Compound Annual Growth Rate as a decimal (e.g., 0.096 for 9.6

Note

This function includes input validation and will 'stop()' with an error if any inputs are non-numeric or non-positive.

Examples

# --- 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)

umx documentation built on Nov. 21, 2025, 1:07 a.m.