Please enter valid positive numbers. Beginning value cannot be zero.
Compound Annual Growth Rate
0.00%
Total Growth: 0.00%
Absolute Gain: $0.00
function calculateCAGR() {
// 1. Get input elements by exact ID
var startInput = document.getElementById("cagrStartValue");
var endInput = document.getElementById("cagrEndValue");
var yearsInput = document.getElementById("cagrYears");
var resultBox = document.getElementById("cagrResult");
var valueDisplay = document.getElementById("cagrValueDisplay");
var totalGrowthDisplay = document.getElementById("totalGrowthDisplay");
var absoluteDiffDisplay = document.getElementById("absoluteDiffDisplay");
var errorMsg = document.getElementById("cagrError");
// 2. Parse values
var startVal = parseFloat(startInput.value);
var endVal = parseFloat(endInput.value);
var years = parseFloat(yearsInput.value);
// 3. Reset display states
errorMsg.style.display = "none";
resultBox.style.display = "none";
// 4. Validation logic
if (isNaN(startVal) || isNaN(endVal) || isNaN(years)) {
errorMsg.innerText = "Please fill in all fields with valid numbers.";
errorMsg.style.display = "block";
return;
}
if (startVal <= 0) {
errorMsg.innerText = "Beginning Value must be greater than zero for CAGR calculation.";
errorMsg.style.display = "block";
return;
}
if (years <= 0) {
errorMsg.innerText = "Number of periods (years) must be greater than zero.";
errorMsg.style.display = "block";
return;
}
// 5. The CAGR Formula Calculation
// Formula: ( (Ending Value / Beginning Value) ^ (1 / n) ) – 1
var ratio = endVal / startVal;
var exponent = 1 / years;
var cagrDecimal = Math.pow(ratio, exponent) – 1;
var cagrPercent = cagrDecimal * 100;
// Calculate auxiliary metrics
var totalGrowthPercent = ((endVal – startVal) / startVal) * 100;
var absoluteGain = endVal – startVal;
// 6. Display Results
valueDisplay.innerHTML = cagrPercent.toFixed(2) + "%";
// Handle negative growth styling
if (cagrPercent < 0) {
valueDisplay.style.color = "#dc3545";
} else {
valueDisplay.style.color = "#28a745";
}
totalGrowthDisplay.innerHTML = "Total Growth: " + totalGrowthPercent.toFixed(2) + "%";
// Format currency for absolute gain
var currencyFormatter = new Intl.NumberFormat('en-US', {
style: 'currency',
currency: 'USD',
});
absoluteDiffDisplay.innerHTML = "Absolute Gain/Loss: " + currencyFormatter.format(absoluteGain);
// Reveal the result box
resultBox.style.display = "block";
}
Understanding the Compound Annual Growth Rate (CAGR) Formula
The Compound Annual Growth Rate (CAGR) is one of the most accurate ways to calculate and determine returns for anything that can rise or fall in value over time. Unlike a simple average growth rate, CAGR takes into account the effect of compounding, providing a geometric mean that smooths out the volatility of periodic returns.
Investors typically use CAGR to compare the historical return performance of different investments (like stocks, mutual funds, or portfolios) or to project the expected growth of a business metric over several years.
The CAGR Formula
The mathematical formula used in the calculator above is:
CAGR = ( EV / BV ) 1 / n – 1
Where:
EV = Ending Value (The value of the investment at the end of the period)
BV = Beginning Value (The initial investment amount)
n = Number of periods (Usually years)
Why Use CAGR Instead of Average Return?
Arithmetic average returns can be misleading. For example, if an investment of $100 drops by 50% in Year 1 (to $50) and rises by 50% in Year 2 (to $75), the arithmetic average return is 0% ((-50% + 50%) / 2). However, you actually lost money ($100 became $75).
The CAGR formula corrects this. It would calculate the rate at which $100 must grow (or shrink) steadily each year to reach $75 in two years. In this case, the CAGR would be approximately -13.4%, accurately reflecting the loss of value.
Example Calculation
Let's assume you invested $10,000 in a portfolio. After 3 years, your portfolio is worth $15,000.
Divide Ending Value by Beginning Value: 15,000 / 10,000 = 1.5
Raise the result to the power of 1 divided by years: 1.5 (1/3) ≈ 1.1447
Subtract 1: 1.1447 – 1 = 0.1447
Convert to Percentage: 0.1447 * 100 = 14.47%
This means your investment grew at an effective smoothed annual rate of 14.47% per year.
Limitations of CAGR
While CAGR is a powerful tool, it does have limitations. It ignores volatility along the way, assuming the growth was steady. It also does not account for investors adding or withdrawing funds during the time period (for that, Internal Rate of Return or IRR is more appropriate). Always use CAGR alongside other metrics like standard deviation to understand the risk involved.