## Class QuantileCalculationMethod

• java.lang.Object
• com.opengamma.strata.math.impl.statistics.descriptive.QuantileCalculationMethod
• Direct Known Subclasses:
DiscreteQuantileMethod, ExponentiallyWeightedInterpolationQuantileMethod, InterpolationQuantileMethod

public abstract class QuantileCalculationMethod
extends Object
Abstract method to estimate quantiles and expected shortfalls from sample observations.
• ### Constructor Summary

Constructors
Constructor Description
QuantileCalculationMethod()
• ### Method Summary

All Methods
Modifier and Type Method Description
protected double checkIndex​(double index, int size, boolean isExtrapolated)
Check the index is within the sample data range.
protected abstract QuantileResult expectedShortfall​(double level, DoubleArray sample)
Computed the expected shortfall.
double expectedShortfallFromSorted​(double level, DoubleArray sortedSample)
Compute the expected shortfall.
double expectedShortfallFromUnsorted​(double level, DoubleArray sample)
Compute the expected shortfall.
QuantileResult expectedShortfallResultFromUnsorted​(double level, DoubleArray sample)
Compute the expected shortfall.
protected abstract QuantileResult quantile​(double level, DoubleArray sample, boolean isExtrapolated)
Computed the quantile.
double quantileFromSorted​(double level, DoubleArray sortedSample)
Compute the quantile estimation.
double quantileFromUnsorted​(double level, DoubleArray sample)
Compute the quantile estimation.
QuantileResult quantileResultFromUnsorted​(double level, DoubleArray sample)
Compute the quantile estimation.
QuantileResult quantileResultWithExtrapolationFromUnsorted​(double level, DoubleArray sample)
Compute the quantile estimation.
double quantileWithExtrapolationFromSorted​(double level, DoubleArray sortedSample)
Compute the quantile estimation.
double quantileWithExtrapolationFromUnsorted​(double level, DoubleArray sample)
Compute the quantile estimation.
• ### Methods inherited from class java.lang.Object

clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
• ### Constructor Detail

• #### QuantileCalculationMethod

public QuantileCalculationMethod()
• ### Method Detail

• #### quantileResultFromUnsorted

public QuantileResult quantileResultFromUnsorted​(double level,
DoubleArray sample)
Compute the quantile estimation.

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, the quantile estimation with the level 99% corresponds to the smallest 99% observations and 1% of the observation are above that level.

If index value computed from the level is outside of the sample data range, IllegalArgumentException is thrown.

The sample observations are supposed to be unsorted.

The quantile result produced contains the quantile value, the indices of the data points used to compute it as well as the weights assigned to each point in the computation. The indices are based on the original, unsorted array. Additionally, the indices start from 0 and so do not need to be shifted to account for java indexing, when using them to reference the data points in the quantile calculation.

Parameters:
level - the quantile level
sample - the sample observations
Returns:
the quantile estimation
• #### quantileResultWithExtrapolationFromUnsorted

public QuantileResult quantileResultWithExtrapolationFromUnsorted​(double level,
DoubleArray sample)
Compute the quantile estimation.

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, the quantile estimation with the level 99% corresponds to the smallest 99% observations and 1% of the observation are above that level.

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.

The sample observations are supposed to be unsorted.

The quantile result produced contains the quantile value, the indices of the data points used to compute it as well as the weights assigned to each point in the computation. The indices are based on the original, unsorted array. Additionally, the indices start from 0 and so do not need to be shifted to account for java indexing, when using them to reference the data points in the quantile calculation.

Parameters:
level - the quantile level
sample - the sample observations
Returns:
the quantile estimation
• #### quantileFromSorted

public double quantileFromSorted​(double level,
DoubleArray sortedSample)
Compute the quantile estimation.

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.

If index value computed from the level is outside of the sample data range, IllegalArgumentException is thrown.

The sample observations are sorted from the smallest to the largest.

Parameters:
level - the quantile level
sortedSample - the sample observations
Returns:
the quantile estimation
• #### quantileFromUnsorted

public double quantileFromUnsorted​(double level,
DoubleArray sample)
Compute the quantile estimation.

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.

If index value computed from the level is outside of the sample data range, IllegalArgumentException is thrown.

The sample observations are supposed to be unsorted, the first step is to sort the data.

Parameters:
level - the quantile level
sample - the sample observations
Returns:
The quantile estimation
• #### quantileWithExtrapolationFromSorted

public double quantileWithExtrapolationFromSorted​(double level,
DoubleArray sortedSample)
Compute the quantile estimation.

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.

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.

The sample observations are sorted from the smallest to the largest.

Parameters:
level - the quantile level
sortedSample - the sample observations
Returns:
the quantile estimation
• #### quantileWithExtrapolationFromUnsorted

public double quantileWithExtrapolationFromUnsorted​(double level,
DoubleArray sample)
Compute the quantile estimation.

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.

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.

The sample observations are supposed to be unsorted, the first step is to sort the data.

Parameters:
level - the quantile level
sample - the sample observations
Returns:
The quantile estimation
• #### expectedShortfallResultFromUnsorted

public QuantileResult expectedShortfallResultFromUnsorted​(double level,
DoubleArray sample)
Compute the expected shortfall.

The shortfall level is in decimal, i.e. 99% = 0.99 and 0 < level < 1 should be satisfied. This is measured from the bottom, that is, the expected shortfall with the level 99% corresponds to the average of the smallest 99% of the observations.

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 quantileWithExtrapolationFromUnsorted(double, DoubleArray).

The sample observations are supposed to be unsorted.

The quantile result produced contains the expected shortfall value, the indices of the data points used to compute it as well as the weights assigned to each point in the computation. The indices are based on the original, unsorted array. Additionally, the indices start from 0 and so do not need to be shifted to account for java indexing, when using them to reference the data points in the quantile calculation.

Parameters:
level - the quantile level
sample - the sample observations
Returns:
the quantile estimation
• #### expectedShortfallFromSorted

public double expectedShortfallFromSorted​(double level,
DoubleArray sortedSample)
Compute the expected shortfall.

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.

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 quantileWithExtrapolationFromSorted(double, DoubleArray).

The sample observations are sorted from the smallest to the largest.

Parameters:
level - the quantile level
sortedSample - the sample observations
Returns:
the quantile estimation
• #### expectedShortfallFromUnsorted

public double expectedShortfallFromUnsorted​(double level,
DoubleArray sample)
Compute the expected shortfall.

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.

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 quantileWithExtrapolationFromUnsorted(double, DoubleArray).

The sample observations are supposed to be unsorted, the first step is to sort the data.

Parameters:
level - the quantile level
sample - the sample observations
Returns:
The expected shortfall estimation
• #### quantile

protected abstract QuantileResult quantile​(double level,
DoubleArray sample,
boolean isExtrapolated)
Computed the quantile.

This protected method should be implemented in subclasses.

Parameters:
level - the quantile level
sample - the sample observations
isExtrapolated - extrapolated if true, not extrapolated otherwise.
Returns:
the quantile
• #### expectedShortfall

protected abstract QuantileResult expectedShortfall​(double level,
DoubleArray sample)
Computed the expected shortfall.

This protected method should be implemented in subclasses and coherent to quantile(double, DoubleArray, boolean).

Parameters:
level - the quantile level
sample - the sample observations
Returns:
the expected shortfall
• #### checkIndex

protected double checkIndex​(double index,
int size,
boolean isExtrapolated)
Check the index is within the sample data range.

If the index is outside the data range, the nearest data point is used in case of isExtrapolated == true or an exception is thrown in case of isExtrapolated == false.

Parameters:
index - the index
size - the sample size
isExtrapolated - extrapolated if true, not extrapolated otherwise
Returns:
the index