public void interpolation_samplePlusOne_9999_100_expected_shortfall() { Function<Double, Double> func = new Function<Double, Double>() { @Override public Double apply(Double level) { return QUANTILE_SAMPLE1_INTERPOLATION.quantileWithExtrapolationFromUnsorted(level, UNSORTED_100); } }; double expectedShortfallExpected = INTEG.integrate(func, TOL_INTEGRAL, LEVEL5) / LEVEL5; double expectedShortfallComputed = QUANTILE_SAMPLE1_INTERPOLATION.expectedShortfallFromUnsorted(LEVEL5, UNSORTED_100); assertEquals(expectedShortfallComputed, expectedShortfallExpected, TOL_INTEGRAL); }
public void index_nearest_one_9999_100_expected_shortfall() { Function<Double, Double> func = new Function<Double, Double>() { @Override public Double apply(Double level) { return QUANTILE_SAMPLE1_NEAREST_INDEX.quantileWithExtrapolationFromUnsorted(level, UNSORTED_100); } }; double expectedShortfallExpected = INTEG.integrate(func, TOL_INTEGRAL, LEVEL5) / LEVEL5; double expectedShortfallComputed = QUANTILE_SAMPLE1_NEAREST_INDEX.expectedShortfallFromUnsorted(LEVEL5, UNSORTED_100); assertEquals(expectedShortfallComputed, expectedShortfallExpected, TOL_INTEGRAL); }
public void interpolation_sample_9999_100_expected_shortfall() { Function<Double, Double> func = new Function<Double, Double>() { @Override public Double apply(Double level) { return QUANTILE_SAMPLE_INTERPOLATION.quantileWithExtrapolationFromUnsorted(level, UNSORTED_100); } }; double expectedShortfallExpected = INTEG.integrate(func, TOL_INTEGRAL, LEVEL5) / LEVEL5; double expectedShortfallComputed = QUANTILE_SAMPLE_INTERPOLATION.expectedShortfallFromUnsorted(LEVEL5, UNSORTED_100); assertEquals(expectedShortfallComputed, expectedShortfallExpected, TOL_INTEGRAL); }
public void interpolation_midway_9999_100_expected_shortfall() { Function<Double, Double> func = new Function<Double, Double>() { @Override public Double apply(Double level) { return QUANTILE_MIDWAY_INTERPOLATION.quantileWithExtrapolationFromUnsorted(level, UNSORTED_100); } }; double expectedShortfallExpected = INTEG.integrate(func, TOL_INTEGRAL, LEVEL5) / LEVEL5; double expectedShortfallComputed = QUANTILE_MIDWAY_INTERPOLATION.expectedShortfallFromUnsorted(LEVEL5, UNSORTED_100); assertEquals(expectedShortfallComputed, expectedShortfallExpected, TOL_INTEGRAL); }
public void interpolation_sample_095_123_expected_shortfall() { Function<Double, Double> func = new Function<Double, Double>() { @Override public Double apply(Double level) { return QUANTILE_SAMPLE_INTERPOLATION.quantileWithExtrapolationFromUnsorted(level, UNSORTED_123); } }; double expectedShortfallExpected = INTEG.integrate(func, TOL_INTEGRAL, LEVEL3) / LEVEL3; double expectedShortfallComputed = QUANTILE_SAMPLE_INTERPOLATION.expectedShortfallFromUnsorted( LEVEL3, UNSORTED_123); assertEquals(expectedShortfallComputed, expectedShortfallExpected, TOL_INTEGRAL); }
public void interpolation_midway_095_100_expected_shortfall() { Function<Double, Double> func = new Function<Double, Double>() { @Override public Double apply(Double level) { return QUANTILE_MIDWAY_INTERPOLATION.quantileWithExtrapolationFromUnsorted(level, UNSORTED_100); } }; double expectedShortfallExpected = INTEG.integrate(func, TOL_INTEGRAL, LEVEL3) / LEVEL3; double expectedShortfallComputed = QUANTILE_MIDWAY_INTERPOLATION.expectedShortfallFromUnsorted( LEVEL3, UNSORTED_100); assertEquals(expectedShortfallComputed, expectedShortfallExpected, TOL_INTEGRAL); }
public void index_above_9999_100_expected_shortfall() { Function<Double, Double> func = new Function<Double, Double>() { @Override public Double apply(Double level) { return QUANTILE_INDEX_ABOVE.quantileWithExtrapolationFromUnsorted(level, UNSORTED_100); } }; double expectedShortfallExpected = INTEG.integrate(func, TOL_INTEGRAL, LEVEL5) / LEVEL5; double expectedShortfallComputed = QUANTILE_INDEX_ABOVE.expectedShortfallFromUnsorted( LEVEL5, UNSORTED_100); assertEquals(expectedShortfallComputed, expectedShortfallExpected, TOL_INTEGRAL); }
public void interpolation_samplePlusOne_095_123_expected_shortfall() { Function<Double, Double> func = new Function<Double, Double>() { @Override public Double apply(Double level) { return QUANTILE_SAMPLE1_INTERPOLATION.quantileWithExtrapolationFromUnsorted(level, UNSORTED_123); } }; double expectedShortfallExpected = INTEG.integrate(func, TOL_INTEGRAL, LEVEL3) / LEVEL3; double expectedShortfallComputed = QUANTILE_SAMPLE1_INTERPOLATION.expectedShortfallFromUnsorted( LEVEL3, UNSORTED_123); assertEquals(expectedShortfallComputed, expectedShortfallExpected, TOL_INTEGRAL); }
public void index_nearest_095_100_expected_shortfall() { Function<Double, Double> func = new Function<Double, Double>() { @Override public Double apply(Double level) { return QUANTILE_NEAREST_INDEX.quantileWithExtrapolationFromUnsorted(level, UNSORTED_100); } }; double expectedShortfallExpected = INTEG.integrate(func, TOL_INTEGRAL, LEVEL3) / LEVEL3; double expectedShortfallComputed = QUANTILE_NEAREST_INDEX.expectedShortfallFromUnsorted( LEVEL3, UNSORTED_100); assertEquals(expectedShortfallComputed, expectedShortfallExpected, TOL_INTEGRAL); }
public void index_nearest_9999_100_expected_shortfall() { Function<Double, Double> func = new Function<Double, Double>() { @Override public Double apply(Double level) { return QUANTILE_NEAREST_INDEX.quantileWithExtrapolationFromUnsorted(level, UNSORTED_100); } }; double expectedShortfallExpected = INTEG.integrate(func, TOL_INTEGRAL, LEVEL5) / LEVEL5; double expectedShortfallComputed = QUANTILE_NEAREST_INDEX.expectedShortfallFromUnsorted( LEVEL5, UNSORTED_100); assertEquals(expectedShortfallComputed, expectedShortfallExpected, TOL_INTEGRAL); }
public void interpolation_midway_095_123_expected_shortfall() { Function<Double, Double> func = new Function<Double, Double>() { @Override public Double apply(Double level) { return QUANTILE_MIDWAY_INTERPOLATION.quantileWithExtrapolationFromUnsorted(level, UNSORTED_123); } }; double expectedShortfallExpected = INTEG.integrate(func, TOL_INTEGRAL, LEVEL3) / LEVEL3; double expectedShortfallComputed = QUANTILE_MIDWAY_INTERPOLATION.expectedShortfallFromUnsorted( LEVEL3, UNSORTED_123); assertEquals(expectedShortfallComputed, expectedShortfallExpected, TOL_INTEGRAL); }
public void index_above_095_100_expected_shortfall() { Function<Double, Double> func = new Function<Double, Double>() { @Override public Double apply(Double level) { return QUANTILE_INDEX_ABOVE.quantileWithExtrapolationFromUnsorted(level, UNSORTED_100); } }; double expectedShortfallExpected = INTEG.integrate(func, TOL_INTEGRAL, LEVEL3) / LEVEL3; double expectedShortfallComputed = QUANTILE_INDEX_ABOVE.expectedShortfallFromUnsorted( LEVEL3, UNSORTED_100); assertEquals(expectedShortfallComputed, expectedShortfallExpected, TOL_INTEGRAL); }
public void index_above_095_123_expected_shortfall() { Function<Double, Double> func = new Function<Double, Double>() { @Override public Double apply(Double level) { return QUANTILE_INDEX_ABOVE.quantileWithExtrapolationFromUnsorted(level, UNSORTED_123); } }; double expectedShortfallExpected = INTEG.integrate(func, TOL_INTEGRAL, LEVEL3) / LEVEL3; double expectedShortfallComputed = QUANTILE_INDEX_ABOVE.expectedShortfallFromUnsorted( LEVEL3, UNSORTED_123); assertEquals(expectedShortfallComputed, expectedShortfallExpected, TOL_INTEGRAL); }
public void index_nearest_095_123_expected_shortfall() { Function<Double, Double> func = new Function<Double, Double>() { @Override public Double apply(Double level) { return QUANTILE_NEAREST_INDEX.quantileWithExtrapolationFromUnsorted(level, UNSORTED_123); } }; double expectedShortfallExpected = INTEG.integrate(func, TOL_INTEGRAL, LEVEL3) / LEVEL3; double expectedShortfallComputed = QUANTILE_NEAREST_INDEX.expectedShortfallFromUnsorted( LEVEL3, UNSORTED_123); assertEquals(expectedShortfallComputed, expectedShortfallExpected, TOL_INTEGRAL); }
public void index_nearest_one_095_100_expected_shortfall() { Function<Double, Double> func = new Function<Double, Double>() { @Override public Double apply(Double level) { return QUANTILE_SAMPLE1_NEAREST_INDEX.quantileWithExtrapolationFromUnsorted(level, UNSORTED_100); } }; double expectedShortfallExpected = INTEG.integrate(func, TOL_INTEGRAL, LEVEL3) / LEVEL3; double expectedShortfallComputed = QUANTILE_SAMPLE1_NEAREST_INDEX.expectedShortfallFromUnsorted( LEVEL3, UNSORTED_100); assertEquals(expectedShortfallComputed, expectedShortfallExpected, TOL_INTEGRAL); }
public void interpolation_sample_095_100_expected_shortfall() { Function<Double, Double> func = new Function<Double, Double>() { @Override public Double apply(Double level) { return QUANTILE_SAMPLE_INTERPOLATION.quantileWithExtrapolationFromUnsorted(level, UNSORTED_100); } }; double expectedShortfallExpected = INTEG.integrate(func, TOL_INTEGRAL, LEVEL3) / LEVEL3; double expectedShortfallComputed = QUANTILE_SAMPLE_INTERPOLATION.expectedShortfallFromUnsorted( LEVEL3, UNSORTED_100); assertEquals(expectedShortfallComputed, expectedShortfallExpected, TOL_INTEGRAL); }
@Test public void testRungeKutta() { final RungeKuttaIntegrator1D integrator = new RungeKuttaIntegrator1D(); final double lower = -1; final double upper = 2; assertEquals(F1.apply(upper) - F1.apply(lower), integrator.integrate(DF1, lower, upper), EPS); }
public void excel_expected_shortfall_9999() { DoubleArray data = DoubleArray.of(1.0, 3.0, 2.0, 4.0); Function<Double, Double> func = new Function<Double, Double>() { @Override public Double apply(Double level) { return ExcelInterpolationQuantileMethod.DEFAULT.quantileWithExtrapolationFromUnsorted(level, data); } }; double expectedShortfallExpected = INTEG.integrate(func, TOL_INTEGRAL / 1000d, LEVEL5) / LEVEL5; double expectedShortfallComputed = ExcelInterpolationQuantileMethod.DEFAULT.expectedShortfallFromUnsorted(LEVEL5, data); assertEquals(expectedShortfallComputed, expectedShortfallExpected, TOL_INTEGRAL); }
public void excel_expected_shortfall() { DoubleArray data = DoubleArray.of(1.0, 3.0, 2.0, 4.0); double level = 0.3; Function<Double, Double> func = new Function<Double, Double>() { @Override public Double apply(Double level) { return ExcelInterpolationQuantileMethod.DEFAULT.quantileWithExtrapolationFromUnsorted(level, data); } }; double expectedShortfallExpected = INTEG.integrate(func, TOL_INTEGRAL / 1000d, level) / level; double expectedShortfallComputed = ExcelInterpolationQuantileMethod.DEFAULT.expectedShortfallFromUnsorted(level, data); assertEquals(expectedShortfallComputed, expectedShortfallExpected, TOL_INTEGRAL); }
@Test public void testGaussHermite2() { final RungeKuttaIntegrator1D rk = new RungeKuttaIntegrator1D(1e-15); final Double expected = 2 * rk.integrate(COS_EXP, 0., 10.); final GaussHermiteQuadratureIntegrator1D gh = new GaussHermiteQuadratureIntegrator1D(11); final double res1 = gh.integrateFromPolyFunc(COS); assertEquals(expected, res1, 1e-15); //11 points gets you machine precision final double res2 = gh.integrate(COS_EXP, Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY); assertEquals(expected, res2, 1e-15); }