function annreturn
annreturn(
x: array,
t?: number,
mode?: string,
dim?: 0 | 1,
): number

Computes the annualized return.

Calculates the annualized return of an asset or portfolio over a period. It supports both geometric (compounded) and simple (arithmetic) return modes.

Examples

Annualized return for a single asset (geometric)

import { assertEquals } from "jsr:@std/assert";

const x = [0.003, 0.026, 0.015, -0.009, 0.014, 0.024, 0.015, 0.066, -0.014, 0.039];
assertEquals(annreturn(x, 12), 0.2338146820656939);

Annualized return with simple (arithmetic) mode

import { assertEquals } from "jsr:@std/assert";

const x = [0.003, 0.026, 0.015, -0.009, 0.014, 0.024, 0.015, 0.066, -0.014, 0.039];

assertEquals(annreturn(x, 12, 'simple'), 0.2148);

Annualized return for multiple assets (matrix)

import { assertEquals } from "jsr:@std/assert";

const x1 = [0.003, 0.026, 0.015, -0.009, 0.014];
const x2 = [0.024, 0.015, 0.066, -0.014, 0.039];
assertEquals(annreturn([x1, x2], 12), [0.12321338265292425, 0.3553067415252329]);

Parameters

Asset/portfolio returns

optional
t: number

Frequency of data points in a year (1: yearly, 4: quarterly, 12: monthly, 52: weekly, 252: daily)

optional
mode: string

Return mode: 'geometric' (default) or 'simple'

optional
dim: 0 | 1

Dimension to operate on (0: row-wise, 1: column-wise)

Return Type

number

The computed annualized return

Throws

If the input is invalid or an unknown mode is specified

annreturn(
x: matrix,
t?: number,
mode?: string,
dim?: 0 | 1,
): array

Computes the annualized return.

Calculates the annualized return of an asset or portfolio over a period. It supports both geometric (compounded) and simple (arithmetic) return modes.

Examples

Annualized return for a single asset (geometric)

import { assertEquals } from "jsr:@std/assert";

const x = [0.003, 0.026, 0.015, -0.009, 0.014, 0.024, 0.015, 0.066, -0.014, 0.039];
assertEquals(annreturn(x, 12), 0.2338146820656939);

Annualized return with simple (arithmetic) mode

import { assertEquals } from "jsr:@std/assert";

const x = [0.003, 0.026, 0.015, -0.009, 0.014, 0.024, 0.015, 0.066, -0.014, 0.039];

assertEquals(annreturn(x, 12, 'simple'), 0.2148);

Annualized return for multiple assets (matrix)

import { assertEquals } from "jsr:@std/assert";

const x1 = [0.003, 0.026, 0.015, -0.009, 0.014];
const x2 = [0.024, 0.015, 0.066, -0.014, 0.039];
assertEquals(annreturn([x1, x2], 12), [0.12321338265292425, 0.3553067415252329]);

Parameters

Asset/portfolio returns

optional
t: number

Frequency of data points in a year (1: yearly, 4: quarterly, 12: monthly, 52: weekly, 252: daily)

optional
mode: string

Return mode: 'geometric' (default) or 'simple'

optional
dim: 0 | 1

Dimension to operate on (0: row-wise, 1: column-wise)

Return Type

The computed annualized return

Throws

If the input is invalid or an unknown mode is specified