Class ExponentiallyWeightedInterpolationQuantileMethod

• public final class ExponentiallyWeightedInterpolationQuantileMethod
extends QuantileCalculationMethod
Implementation of a quantile and expected shortfall estimator for series with exponentially weighted probabilities.

Reference: "Value-at-risk", OpenGamma Documentation 31, Version 0.2, January 2016. Section A.4.

• Constructor Summary

Constructors
Constructor Description
ExponentiallyWeightedInterpolationQuantileMethod​(double lambda)
Constructor.
• Method Summary

All Methods
Modifier and Type Method Description
protected QuantileResult expectedShortfall​(double level, DoubleArray sortedSample)
Computed the expected shortfall.
QuantileResult expectedShortfallDetailsFromUnsorted​(double level, DoubleArray sample)
Compute the expected shortfall and the details used in the result.
double expectedShortfallFromUnsorted​(double level, DoubleArray sample)
Compute the expected shortfall.
QuantileResult expectedShortfallResultFromUnsorted​(double level, DoubleArray sample)
Compute the expected shortfall.
protected QuantileResult quantile​(double level, DoubleArray sortedSample, boolean isExtrapolated)
Computed the quantile.
QuantileResult quantileDetailsFromUnsorted​(double level, DoubleArray sample)
Compute the quantile estimation and the details used in the result.
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 quantileWithExtrapolationFromUnsorted​(double level, DoubleArray sample)
Compute the quantile estimation.
double[] weights​(int size)
Returns the weights for a given sample size.
• Methods inherited from class com.opengamma.strata.math.impl.statistics.descriptive.QuantileCalculationMethod

checkIndex, expectedShortfallFromSorted, quantileFromSorted, quantileWithExtrapolationFromSorted
• Methods inherited from class java.lang.Object

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

• ExponentiallyWeightedInterpolationQuantileMethod

public ExponentiallyWeightedInterpolationQuantileMethod​(double lambda)
Constructor.

The exponential weight lambda must be > 0 and < 1.0.

Parameters:
lambda - the exponential weight
• Method Detail

• quantileResultFromUnsorted

public QuantileResult quantileResultFromUnsorted​(double level,
DoubleArray sample)
Description copied from class: QuantileCalculationMethod
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.

Overrides:
quantileResultFromUnsorted in class QuantileCalculationMethod
Parameters:
level - the quantile level
sample - the sample observations
Returns:
the quantile estimation
• quantileResultWithExtrapolationFromUnsorted

public QuantileResult quantileResultWithExtrapolationFromUnsorted​(double level,
DoubleArray sample)
Description copied from class: QuantileCalculationMethod
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.

Overrides:
quantileResultWithExtrapolationFromUnsorted in class QuantileCalculationMethod
Parameters:
level - the quantile level
sample - the sample observations
Returns:
the quantile estimation
• quantileFromUnsorted

public double quantileFromUnsorted​(double level,
DoubleArray sample)
Description copied from class: QuantileCalculationMethod
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.

Overrides:
quantileFromUnsorted in class QuantileCalculationMethod
Parameters:
level - the quantile level
sample - the sample observations
Returns:
The quantile estimation
• quantileWithExtrapolationFromUnsorted

public double quantileWithExtrapolationFromUnsorted​(double level,
DoubleArray sample)
Description copied from class: QuantileCalculationMethod
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.

Overrides:
quantileWithExtrapolationFromUnsorted in class QuantileCalculationMethod
Parameters:
level - the quantile level
sample - the sample observations
Returns:
The quantile estimation
• expectedShortfallResultFromUnsorted

public QuantileResult expectedShortfallResultFromUnsorted​(double level,
DoubleArray sample)
Description copied from class: QuantileCalculationMethod
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 QuantileCalculationMethod.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.

Overrides:
expectedShortfallResultFromUnsorted in class QuantileCalculationMethod
Parameters:
level - the quantile level
sample - the sample observations
Returns:
the quantile estimation
• expectedShortfallFromUnsorted

public double expectedShortfallFromUnsorted​(double level,
DoubleArray sample)
Description copied from class: QuantileCalculationMethod
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 QuantileCalculationMethod.quantileWithExtrapolationFromUnsorted(double, DoubleArray).

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

Overrides:
expectedShortfallFromUnsorted in class QuantileCalculationMethod
Parameters:
level - the quantile level
sample - the sample observations
Returns:
The expected shortfall estimation
• quantileDetailsFromUnsorted

public QuantileResult quantileDetailsFromUnsorted​(double level,
DoubleArray sample)
Compute the quantile estimation and the details used in the result.

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.

The details consists on the indices of the samples actually used in the quantile computation - indices in the input sample - and the weights for each of those samples. The details are sufficient to recompute the quantile directly from the input sample.

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 and its details
• expectedShortfallDetailsFromUnsorted

public QuantileResult expectedShortfallDetailsFromUnsorted​(double level,
DoubleArray sample)
Compute the expected shortfall and the details used in the result.

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 details consists on the indices of the samples actually used in the expected shortfall computation - indices in the input sample - and the weights for each of those samples. The details are sufficient to recompute the expected shortfall directly from the input sample.

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 and its detail
• quantile

protected QuantileResult quantile​(double level,
DoubleArray sortedSample,
boolean isExtrapolated)
Description copied from class: QuantileCalculationMethod
Computed the quantile.

This protected method should be implemented in subclasses.

Specified by:
quantile in class QuantileCalculationMethod
Parameters:
level - the quantile level
sortedSample - the sample observations
isExtrapolated - extrapolated if true, not extrapolated otherwise.
Returns:
the quantile
• expectedShortfall

protected QuantileResult expectedShortfall​(double level,
DoubleArray sortedSample)
Description copied from class: QuantileCalculationMethod
Computed the expected shortfall.

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

Specified by:
expectedShortfall in class QuantileCalculationMethod
Parameters:
level - the quantile level
sortedSample - the sample observations
Returns:
the expected shortfall
• weights

public double[] weights​(int size)
Returns the weights for a given sample size.
Parameters:
size - the sample size
Returns:
the weights