pub fn tvar_sorted(sorted: &[f64], p: f64) -> Result<f64>Expand description
Tail value at risk: the mean of the worst 1 - p of the distribution,
(1 / (1 - p)) * integral from p to 1 of VaR(u) du.
When p * n is not a whole number the draw at the VaR is counted with
the fractional weight that falls above p, so the result is coherent
and moves continuously with p. p = 0 gives the mean and p = 1 the
largest draw. sorted must be non-empty and sorted ascending; this is
checked only in debug builds.
use prospicio_prob::risk::tvar_sorted;
let x = [1.0, 2.0, 3.0, 4.0];
assert_eq!(tvar_sorted(&x, 0.5), Ok(3.5));
// Half of the draw 2 lies above p = 0.375: (0.5 * 2 + 3 + 4) / 2.5.
assert_eq!(tvar_sorted(&x, 0.375), Ok(3.2));