cagr(): number
Compound Annual Growth Rate.
Calculates the Compound Annual Growth Rate (CAGR) which represents the mean annual growth rate of an investment over a specified time period longer than one year.
CAGR for a single asset over time
CAGR for a single asset over time
import { assertEquals } from "jsr:@std/assert"; const sp500 = [676.53, 902.40, 1378.43, 1769.30, 2206.45, 2643.85, 2679.63]; const dates = [1998, 2000, 2005, 2010, 2015, 2020, 2022]; assertEquals(cagr(sp500, dates), 0.05902892931364878);
CAGR for multiple assets with the same time series
CAGR for multiple assets with the same time series
import { assertEquals } from "jsr:@std/assert"; const dates = [1998, 2000, 2005, 2010, 2015, 2020, 2022]; const sp500 = [676.53, 902.40, 1378.43, 1769.30, 2206.45, 2643.85, 2679.63]; assertEquals(cagr([sp500, sp500], dates), [0.05902892931364878, 0.05902892931364878]);
cagr(): array | matrix
Compound Annual Growth Rate.
Calculates the Compound Annual Growth Rate (CAGR) which represents the mean annual growth rate of an investment over a specified time period longer than one year.
CAGR for a single asset over time
CAGR for a single asset over time
import { assertEquals } from "jsr:@std/assert"; const sp500 = [676.53, 902.40, 1378.43, 1769.30, 2206.45, 2643.85, 2679.63]; const dates = [1998, 2000, 2005, 2010, 2015, 2020, 2022]; assertEquals(cagr(sp500, dates), 0.05902892931364878);
CAGR for multiple assets with the same time series
CAGR for multiple assets with the same time series
import { assertEquals } from "jsr:@std/assert"; const dates = [1998, 2000, 2005, 2010, 2015, 2020, 2022]; const sp500 = [676.53, 902.40, 1378.43, 1769.30, 2206.45, 2643.85, 2679.63]; assertEquals(cagr([sp500, sp500], dates), [0.05902892931364878, 0.05902892931364878]);