function histcondvar
histcondvar(
x: array,
p?: number,
amount?: number,
dim?: 0 | 1,
): number

Historical Conditional Value-At-Risk (CVaR).

Univariate historical simulation for Conditional Value-At-Risk. Also known as Expected Shortfall (ES) or Expected Tail Loss (ETL). The CVaR is the expected loss exceeding the VaR.

Examples

Historical conditional VaR for single asset

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(histcondvar(x, 0.95), 0.014);

Historical conditional VaR with custom amount

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(histcondvar(x, 0.99, 100000), 1400);

Historical conditional VaR for matrix (row-wise)

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];

const y = [-0.005, 0.081, 0.04, -0.037, -0.061, 0.058, -0.049, -0.021, 0.062, 0.058];
const matrix = [x, y];
assertEquals(histcondvar(matrix, 0.95, 1, 0), [0.014, 0.061]);

Parameters

array or matrix of values

optional
p: number

confidence level in the range [0,1] (def: 0.95)

optional
amount: number

amount (def: 1)

optional
dim: 0 | 1

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

Return Type

number

Historical Conditional Value-At-Risk

histcondvar(
x: matrix,
p?: number,
amount?: number,
dim?: 0 | 1,
): array | matrix

Historical Conditional Value-At-Risk (CVaR).

Univariate historical simulation for Conditional Value-At-Risk. Also known as Expected Shortfall (ES) or Expected Tail Loss (ETL). The CVaR is the expected loss exceeding the VaR.

Examples

Historical conditional VaR for single asset

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(histcondvar(x, 0.95), 0.014);

Historical conditional VaR with custom amount

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(histcondvar(x, 0.99, 100000), 1400);

Historical conditional VaR for matrix (row-wise)

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];

const y = [-0.005, 0.081, 0.04, -0.037, -0.061, 0.058, -0.049, -0.021, 0.062, 0.058];
const matrix = [x, y];
assertEquals(histcondvar(matrix, 0.95, 1, 0), [0.014, 0.061]);

Parameters

array or matrix of values

optional
p: number

confidence level in the range [0,1] (def: 0.95)

optional
amount: number

amount (def: 1)

optional
dim: 0 | 1

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

Return Type

Historical Conditional Value-At-Risk