mazey
    Preparing search index...

    Function calculateCAGR

    • Calculate an investment's Compound Annual Growth Rate (CAGR).

      Numeric total returns use decimal ratios. For example, 0.202 represents 20.2%. String total returns use percentage values, so "20.2%" and "20.2" both represent 20.2%. A trailing percent sign is optional, and the complete trimmed string must be a finite JavaScript number. Scientific notation such as "2.02e1%" is accepted.

      The returned CAGR is a decimal ratio and is not rounded. The calculation uses:

      CAGR = (1 + totalReturn)^(365 / durationInDays) - 1

      Usage:

      import {
      calculateCAGR,
      floatToPercent,
      } from "mazey";

      const cagr = calculateCAGR(
      "2022-04-01",
      "2025-10-01",
      "20.2%"
      );
      const equivalentCagr = calculateCAGR(
      "2022-04-01",
      "2025-10-01",
      0.202
      );
      const negativeCagr = calculateCAGR(
      "2022-04-01",
      "2025-10-01",
      "-15.5%"
      );

      console.log({
      cagr,
      equivalentCagr,
      negativeCagr,
      percentage: floatToPercent(cagr, 2),
      });

      Possible output:

      {
        cagr: 0.053908...,
        equivalentCagr: 0.053908...,
        negativeCagr: -0.046926...,
        percentage: "5.39%"
      }
      

      Parameters

      • startDate: MazeyDate

        Start date as a supported structured string, millisecond timestamp, or Date.

      • endDate: MazeyDate

        End date in the same accepted forms. It must be strictly later than startDate.

      • totalReturnRate: InvestmentReturnRate

        Total period return. Numbers are decimal ratios; strings are percentage values.

      Returns number

      The unrounded CAGR as a decimal ratio.

      If either date or the total return is invalid.

      If the dates are not increasing, the total return is at most -1, or the result is not finite.

      Duration uses the exact elapsed milliseconds, including time of day, converted to fractional days. A financial year is always fixed at 365 days. Input Date objects are copied and never mutated.