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

Pain Index.

Mean value of the drawdowns, similar to Ulcer Index. It measures the depth, duration, and frequency of losses.

Examples

Single array of returns

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

var x = [0.003,0.026,0.015,-0.009,0.014,0.024,0.015,0.066,-0.014,0.039];
assertEquals(painindex(x), 0.0023000000000000034);

Multiple arrays

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

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

var y = [-0.005,0.081,0.04,-0.037,-0.061,0.058,-0.049,-0.021,0.062,0.058];
assertEquals(painindex(x), 0.0023000000000000034);
assertEquals(painindex(y), 0.042955093457969766);

Parameters

asset/portfolio returns

optional
mode: string

drawdown calculation. 'return','geometric' (def: 'return')

optional
dim: 0 | 1

dimension 0: row, 1: column (def: 0)

Return Type

number

Pain Index

painindex(
x: matrix,
mode?: string,
dim?: 0 | 1,
): array | matrix

Pain Index.

Mean value of the drawdowns, similar to Ulcer Index. It measures the depth, duration, and frequency of losses.

Examples

Single array of returns

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

var x = [0.003,0.026,0.015,-0.009,0.014,0.024,0.015,0.066,-0.014,0.039];
assertEquals(painindex(x), 0.0023000000000000034);

Multiple arrays

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

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

var y = [-0.005,0.081,0.04,-0.037,-0.061,0.058,-0.049,-0.021,0.062,0.058];
assertEquals(painindex(x), 0.0023000000000000034);
assertEquals(painindex(y), 0.042955093457969766);

Parameters

asset/portfolio returns

optional
mode: string

drawdown calculation. 'return','geometric' (def: 'return')

optional
dim: 0 | 1

dimension 0: row, 1: column (def: 0)

Return Type

Pain Index