@Override public double quantileFromUnsorted(double level, DoubleArray sample) { return quantileResultFromUnsorted(level, sample).getValue(); }
@Override public double quantileWithExtrapolationFromUnsorted(double level, DoubleArray sample) { return quantileResultWithExtrapolationFromUnsorted(level, sample).getValue(); }
@Override public double expectedShortfallFromUnsorted(double level, DoubleArray sample) { return expectedShortfallResultFromUnsorted(level, sample).getValue(); }
/** * Compute the quantile estimation. * <p> * The quantile level is in decimal, i.e. 99% = 0.99 and 0 < level < 1 should be satisfied. * This is measured from the bottom, that is, Thus the quantile estimation with the level 99% corresponds to * the smallest 99% observations. * <p> * If index value computed from the level is outside of the sample data range, the nearest data point is used, i.e., * quantile is computed with flat extrapolation. * <p> * The sample observations are sorted from the smallest to the largest. * * @param level the quantile level * @param sortedSample the sample observations * @return the quantile estimation */ public double quantileWithExtrapolationFromSorted(double level, DoubleArray sortedSample) { return quantileResultWithExtrapolationFromUnsorted(level, sortedSample).getValue(); }
/** * Compute the quantile estimation. * <p> * The quantile level is in decimal, i.e. 99% = 0.99 and 0 < level < 1 should be satisfied. * This is measured from the bottom, that is, Thus the quantile estimation with the level 99% corresponds to * the smallest 99% observations. * <p> * If index value computed from the level is outside of the sample data range, * {@code IllegalArgumentException} is thrown. * <p> * The sample observations are sorted from the smallest to the largest. * * @param level the quantile level * @param sortedSample the sample observations * @return the quantile estimation */ public double quantileFromSorted(double level, DoubleArray sortedSample) { return quantileResultFromUnsorted(level, sortedSample).getValue(); }
/** * Compute the expected shortfall. * <p> * The quantile level is in decimal, i.e. 99% = 0.99 and 0 < level < 1 should be satisfied. * This is measured from the bottom, that is, Thus the expected shortfall with the level 99% corresponds to * the smallest 99% observations. * <p> * If index value computed from the level is outside of the sample data range, the nearest data point is used, i.e., * expected short fall is computed with flat extrapolation. * Thus this is coherent to {@link #quantileWithExtrapolationFromSorted(double, DoubleArray)}. * <p> * The sample observations are sorted from the smallest to the largest. * * @param level the quantile level * @param sortedSample the sample observations * @return the quantile estimation */ public double expectedShortfallFromSorted(double level, DoubleArray sortedSample) { return expectedShortfallResultFromUnsorted(level, sortedSample).getValue(); }
@Override protected Object propertyGet(Bean bean, String propertyName, boolean quiet) { switch (propertyName.hashCode()) { case 111972721: // value return ((QuantileResult) bean).getValue(); case 1943391143: // indices return ((QuantileResult) bean).getIndices(); case 1230441723: // weights return ((QuantileResult) bean).getWeights(); } return super.propertyGet(bean, propertyName, quiet); }
public void es_details() { double[] level = {0.98, 0.981, 0.9811, 0.97}; for (int i = 0; i < level.length; i++) { double es = METHOD.expectedShortfallFromUnsorted(level[i], DATA_123); QuantileResult r = METHOD.expectedShortfallDetailsFromUnsorted(level[i], DATA_123); assertEquals(r.getValue(), es, TOLERANCE_QUANTILE); assertEquals(r.getIndices().length, r.getWeights().size()); double qExpected = 0.0; for (int j = 0; j < r.getIndices().length; j++) { // Recompute ES from details qExpected += DATA_123.get(r.getIndices()[j]) * r.getWeights().get(j); } assertEquals(qExpected, es, TOLERANCE_QUANTILE); } }
public void quantile_details() { double[] level = {0.98, 0.981, 0.9811, 0.97}; for (int i = 0; i < level.length; i++) { double q = METHOD.quantileFromUnsorted(level[i], DATA_123); QuantileResult r = METHOD.quantileDetailsFromUnsorted(level[i], DATA_123); assertEquals(r.getValue(), q, TOLERANCE_QUANTILE); assertEquals(r.getIndices().length, r.getWeights().size()); double qExpected = 0.0; for (int j = 0; j < r.getIndices().length; j++) { // Recompute quantile from details qExpected += DATA_123.get(r.getIndices()[j]) * r.getWeights().get(j); } assertEquals(qExpected, q, TOLERANCE_QUANTILE); } }
assertEquals(quantileAbove.getValue(), expectedValueAbove, TOL); assertEquals(quantileNearest.getValue(), expectedValueNearest, TOL); assertEquals(quantileSample.getValue(), expectedValueSample, TOL); assertEquals(quantileSampleInterp.getValue(), expectedValueSampleInterp, TOL); assertEquals(quantileSample1Interp.getValue(), expectedValueSample1Interp, TOL); assertEquals(quantileMidInterp.getValue(), expectedValueMidInterp, TOL);
assertEquals(esAbove.getValue(), expectedValueAbove, TOL); assertEquals(esNearest.getValue(), expectedValueNearest, TOL); assertEquals(esSample.getValue(), expectedValueSample, TOL); assertEquals(esSampleInterp.getValue(), expectedValueSampleInterp, TOL); assertEquals(esSample1Interp.getValue(), expectedValueSample1Interp, TOL); assertEquals(esMidInterp.getValue(), expectedValueMidInterp, TOL);