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

Historical Value-At-Risk.

Univariate historical simulation. Single asset

Examples

Daily VaR at 95% confidence level

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(histvar(x, 0.95), 0.013999999999999999);

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

VaR with different confidence level

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

assertEquals(histvar([0.1, -0.2, 0.05, -0.1], 0.75), 0.15);

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
period: number

time horizon (def: 1)

optional
dim: 0 | 1

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

Return Type

number

The calculated Historical Value-At-Risk

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

Historical Value-At-Risk.

Univariate historical simulation. Single asset

Examples

Daily VaR at 95% confidence level

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(histvar(x, 0.95), 0.013999999999999999);

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

VaR with different confidence level

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

assertEquals(histvar([0.1, -0.2, 0.05, -0.1], 0.75), 0.15);

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
period: number

time horizon (def: 1)

optional
dim: 0 | 1

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

Return Type

The calculated Historical Value-At-Risk