pfhedge.nn.functional.value_at_risk

pfhedge.nn.functional.value_at_risk(input, p, dim=None)[source]

Returns the value at risk of the given input tensor.

Note

If \(p \leq 1 / N\) with \(N\) being the number of elements to sort, returns the smallest element in the tensor. If \(p > 1 - 1 / N\), returns the largest element in the tensor.

Parameters
  • input (torch.Tensor) – The input tensor.

  • p (float) – The quantile level.

  • dim (int, optional) – The dimension to sort along.

Returns

torch.Tensor

Examples

>>> from pfhedge.nn.functional import value_at_risk
>>>
>>> input = -torch.arange(10.0)
>>> input
tensor([-0., -1., -2., -3., -4., -5., -6., -7., -8., -9.])
>>> value_at_risk(input, 0.3)
tensor(-7.)