[][src]Function cf_dist_utils::get_expected_shortfall_and_value_at_risk

pub fn get_expected_shortfall_and_value_at_risk<T>(
    alpha: f64,
    num_u: usize,
    x_min: f64,
    x_max: f64,
    max_iterations: usize,
    tolerance: f64,
    fn_inv: T
) -> Result<RiskMetric, ValueAtRiskError> where
    T: Fn(&Complex<f64>) -> Complex<f64> + Sync + Send

Returns expected shortfall (partial expectation) and value at risk (quantile) given a characteristic function.

Remarks

Technically there is no guarantee of convergence for value at risk. The cosine expansion oscillates and the value at risk may be under or over stated. However, in tests it appears to converge for a wide range of distributions

Examples

extern crate num_complex;
use num_complex::Complex;
#[macro_use]
extern crate approx;
extern crate cf_dist_utils;
let mu=2.0;
let sigma=5.0;
let num_u=128;
let x_min=-20.0;
let x_max=25.0;
let max_iterations=1000;
let tolerance=0.0000001;
let alpha=0.05;
let norm_cf=|u:&Complex<f64>| (u*mu+0.5*sigma*sigma*u*u).exp();
let reference_var=6.224268;
let reference_es=8.313564;
let cf_dist_utils::RiskMetric{
    expected_shortfall,
    value_at_risk
}=cf_dist_utils::get_expected_shortfall_and_value_at_risk(
    alpha, num_u, x_min, x_max, max_iterations, tolerance, norm_cf
).unwrap();
assert_abs_diff_eq!(reference_var, value_at_risk, epsilon=0.0001);
assert_abs_diff_eq!(reference_es, expected_shortfall, epsilon=0.001);