function ulcerindex
ulcerindex(
x: array,
mode?: "return" | "geometric",
dim?: 0 | 1,
): number

Ulcer Index.

Ulcer Index of Peter G. Martin (1987). The impact of long, deep drawdowns will have significant impact because the underperformance since the last peak is squared. The formula is: sqrt(sum(dd^2) / n), where dd is the drawdown and n is the number of observations.

Examples

Single array of returns

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(ulcerindex(x), 0.005263078946776312);

Matrix of returns with column dimension

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

const xt = [[0.003, 0.026], [0.015, -0.009], [0.014, 0.024], [0.015, 0.066], [-0.014, 0.039]];
assertEquals(ulcerindex(xt, 'return', 1), [0.006260990336999415, 0.004024922359499606]);

Ulcer index with geometric 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(ulcerindex(x, 'geometric'), 0.005296364154061427);

Parameters

Asset/portfolio returns

optional
mode: "return" | "geometric"

Drawdown calculation mode: 'return' or 'geometric' (defaults to 'return')

optional
dim: 0 | 1

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

Return Type

number

Ulcer Index

Throws

If input is a number (not supported)

ulcerindex(
x: matrix,
mode?: "return" | "geometric",
dim?: 0 | 1,
): array | matrix

Ulcer Index.

Ulcer Index of Peter G. Martin (1987). The impact of long, deep drawdowns will have significant impact because the underperformance since the last peak is squared. The formula is: sqrt(sum(dd^2) / n), where dd is the drawdown and n is the number of observations.

Examples

Single array of returns

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(ulcerindex(x), 0.005263078946776312);

Matrix of returns with column dimension

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

const xt = [[0.003, 0.026], [0.015, -0.009], [0.014, 0.024], [0.015, 0.066], [-0.014, 0.039]];
assertEquals(ulcerindex(xt, 'return', 1), [0.006260990336999415, 0.004024922359499606]);

Ulcer index with geometric 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(ulcerindex(x, 'geometric'), 0.005296364154061427);

Parameters

Asset/portfolio returns

optional
mode: "return" | "geometric"

Drawdown calculation mode: 'return' or 'geometric' (defaults to 'return')

optional
dim: 0 | 1

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

Return Type

Ulcer Index

Throws

If input is a number (not supported)