Class WeightedTailMeasureCalc
- java.lang.Object
-
- com.activeviam.risk.ref.calc.impl.WeightedTailMeasureCalc
-
- All Implemented Interfaces:
IWeightedTailMeasureCalc
public class WeightedTailMeasureCalc extends Object implements IWeightedTailMeasureCalc
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface com.activeviam.risk.core.calc.IWeightedTailMeasureCalc
IWeightedTailMeasureCalc.CalcType
-
-
Constructor Summary
Constructors Constructor Description WeightedTailMeasureCalc()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description double[]
calculateWeights(int n, double lambda)
Generates an array of weightings of length equal to the number of scenarios n, based on a Lambda value.Integer[]
getIndices(com.quartetfs.biz.pivot.IActivePivot activePivot, com.qfs.store.IDatastoreVersion datastore, IWeightedTailMeasureCalc.CalcType type, com.qfs.vector.IVector pnl, double[] weights, double quantile, boolean isPnlOldestFirst)
Return an array of the indices in the vector that contribute to the weighted VaR/ES.Double
getLEstimator(com.quartetfs.biz.pivot.IActivePivot activePivot, com.qfs.store.IDatastoreVersion datastore, IWeightedTailMeasureCalc.CalcType type, com.qfs.vector.IVector referencePnl, com.qfs.vector.IVector pnl, double[] weights, double quantile, boolean isPnlOldestFirst)
Calculate the contribution to the VaR, ES, VaE or ETG of the PnL vector for the quantile.protected double[][]
getSortedWeightedPnLs(com.qfs.vector.IVector referencePnl, com.qfs.vector.IVector originalPnLs, double[] weights, boolean reverse)
Double
getWeightedESMetric(com.qfs.vector.IVector referencePnl, com.qfs.vector.IVector originalPnLs, double[] weights, double quantile, boolean reverse, boolean isPnlOldestFirst)
Calculate the weighted VaR of the PnL vector for the quantile.Integer[]
getWeightedESMetricIndices(com.qfs.vector.IVector originalPnLs, double[] weights, double quantile, boolean reverse, boolean isPnlOldestFirst)
Calculate indices of the scenarios that contribute to the weighted VaR of the PnL vector for the quantile.protected com.quartetfs.fwk.impl.Pair<Double,Integer[]>
getWeightedESMetricWithIndices(com.qfs.vector.IVector referencePnl, com.qfs.vector.IVector originalPnLs, double[] weights, double quantile, boolean reverse, boolean isPnlOldestFirst)
Calculate the weighted ES of the PnL vector for the quantile.Double
getWeightedTailMeasure(com.quartetfs.biz.pivot.IActivePivot activePivot, com.qfs.store.IDatastoreVersion datastore, IWeightedTailMeasureCalc.CalcType type, com.qfs.vector.IVector pnl, double[] weights, double quantile, boolean isPnlOldestFirst)
Calculate the ES or VaR of the PnL vector for the quantile.Double
getWeightedVaRMetric(com.qfs.vector.IVector referencePnl, com.qfs.vector.IVector originalPnLs, double[] weights, double quantile, boolean reverse, boolean isPnlOldestFirst)
Calculate the weighted VaR of the PnL vector for the quantile.Integer[]
getWeightedVaRMetricIndices(com.qfs.vector.IVector originalPnLs, double[] weights, double quantile, boolean reverse, boolean isPnlOldestFirst)
Calculate indices of the scenarios that contribute to the weighted VaR of the PnL vector for the quantile.com.quartetfs.fwk.impl.Pair<Double,Integer[]>
getWeightedVaRMetricWithIndices(com.qfs.vector.IVector referencePnl, com.qfs.vector.IVector originalPnLs, double[] weights, double quantile, boolean reverse, boolean isPnlOldestFirst)
Calculate the weighted VaR of the PnL vector for the quantile and also rfetrun the list of indicies that correspond to the weighted VaR.
-
-
-
Method Detail
-
getWeightedTailMeasure
public Double getWeightedTailMeasure(com.quartetfs.biz.pivot.IActivePivot activePivot, com.qfs.store.IDatastoreVersion datastore, IWeightedTailMeasureCalc.CalcType type, com.qfs.vector.IVector pnl, double[] weights, double quantile, boolean isPnlOldestFirst)
Calculate the ES or VaR of the PnL vector for the quantile.- Specified by:
getWeightedTailMeasure
in interfaceIWeightedTailMeasureCalc
- Parameters:
activePivot
- activePivotdatastore
- datastorepnl
- The PnL vector.weights
- weightsquantile
- The quantile for the ES or VaR, between 0 and 1 (equals 1 minus the confidence level).isPnlOldestFirst
- Whether the first entry in the PnL vector corresponds to the oldest scenario or the newest.type
- "ES", "VaR", "VaE" or "ETG"- Returns:
- The tail measure (i.e. VaR or ES value of the vector for the quantile).
-
calculateWeights
public double[] calculateWeights(int n, double lambda)
Generates an array of weightings of length equal to the number of scenarios n, based on a Lambda value.- Specified by:
calculateWeights
in interfaceIWeightedTailMeasureCalc
- Parameters:
n
- numberlambda
- lambda- Returns:
- array of weightings.
-
getWeightedVaRMetric
public Double getWeightedVaRMetric(com.qfs.vector.IVector referencePnl, com.qfs.vector.IVector originalPnLs, double[] weights, double quantile, boolean reverse, boolean isPnlOldestFirst)
Calculate the weighted VaR of the PnL vector for the quantile.- Parameters:
referencePnl
- The reference PnL vector used for the scenario sortingoriginalPnLs
- The PnL vector used for the VaRweights
- weightsquantile
- The quantile for the VaR, between 0 and 1 (equals 1 minus the confidence level).reverse
- false for negative tail measures, true for positive tail measuresisPnlOldestFirst
- flag to indicate if the PnL values in the PnL vector are present from with the oldest value at index 0 or the most recent value at index 0. The flag is set to 'true' if the oldest PnL value is present at index 0 and to 'false' if the most recent PnL value is present at index 0.- Returns:
- The weighted VaR measure
-
getWeightedVaRMetricIndices
public Integer[] getWeightedVaRMetricIndices(com.qfs.vector.IVector originalPnLs, double[] weights, double quantile, boolean reverse, boolean isPnlOldestFirst)
Calculate indices of the scenarios that contribute to the weighted VaR of the PnL vector for the quantile.- Parameters:
originalPnLs
- The PnL vector.weights
- weightsquantile
- The quantile for the VaR, between 0 and 1 (equals 1 minus the confidence level).reverse
- false for negative tail measures, true for positive tail measuresisPnlOldestFirst
- flag to indicate if the PnL values in the PnL vector are present from with the oldest value at index 0 or the most recent value at index 0. The flag is set to 'true' if the oldest PnL value is present at index 0 and to 'false' if the most recent PnL value is present at index 0.- Returns:
- The indices that contribute to the weighted VaR
-
getWeightedESMetric
public Double getWeightedESMetric(com.qfs.vector.IVector referencePnl, com.qfs.vector.IVector originalPnLs, double[] weights, double quantile, boolean reverse, boolean isPnlOldestFirst)
Calculate the weighted VaR of the PnL vector for the quantile.- Parameters:
referencePnl
- The PnL reference vector used for the scenario sortingoriginalPnLs
- The PnL vector for the metric computationweights
- weightsquantile
- The quantile for the VaR, between 0 and 1 (equals 1 minus the confidence level).reverse
- false for negative tail measures, true for positive tail measuresisPnlOldestFirst
- flag to indicate if the PnL values in the PnL vector are present from with the oldest value at index 0 or the most recent value at index 0. The flag is set to 'true' if the oldest PnL value is present at index 0 and to 'false' if the most recent PnL value is present at index 0.- Returns:
- The weighted VaR measure
-
getWeightedESMetricIndices
public Integer[] getWeightedESMetricIndices(com.qfs.vector.IVector originalPnLs, double[] weights, double quantile, boolean reverse, boolean isPnlOldestFirst)
Calculate indices of the scenarios that contribute to the weighted VaR of the PnL vector for the quantile.- Parameters:
originalPnLs
- The PnL vector.weights
- weightsquantile
- The quantile for the VaR, between 0 and 1 (equals 1 minus the confidence level).reverse
- false for negative tail measures, true for positive tail measuresisPnlOldestFirst
- flag to indicate if the PnL values in the PnL vector are present from with the oldest value at index 0 or the most recent value at index 0. The flag is set to 'true' if the oldest PnL value is present at index 0 and to 'false' if the most recent PnL value is present at index 0.- Returns:
- The indices that contribute to the weighted VaR
-
getWeightedESMetricWithIndices
protected com.quartetfs.fwk.impl.Pair<Double,Integer[]> getWeightedESMetricWithIndices(com.qfs.vector.IVector referencePnl, com.qfs.vector.IVector originalPnLs, double[] weights, double quantile, boolean reverse, boolean isPnlOldestFirst)
Calculate the weighted ES of the PnL vector for the quantile.- Parameters:
referencePnl
- The PnL reference vector used for the scenario sortingoriginalPnLs
- The PnL vector for the metric computationweights
- weightquantile
- The quantile for the ES, between 0 and 1 (equals 1 minus the confidence level)reverse
- false for negative tail measures, true for positive tail measuresisPnlOldestFirst
- flag to indicate if the PnL values in the PnL vector are present from with the oldest value at index 0 or the most recent value at index 0. The flag is set to 'true' if the oldest PnL value is present at index 0 and to 'false' if the most recent PnL value is present at index 0.- Returns:
- The weighted ES measure and the list of indices that correspond to the scenarios used for the computation of the weighted ES
-
getSortedWeightedPnLs
protected double[][] getSortedWeightedPnLs(com.qfs.vector.IVector referencePnl, com.qfs.vector.IVector originalPnLs, double[] weights, boolean reverse)
-
getWeightedVaRMetricWithIndices
public com.quartetfs.fwk.impl.Pair<Double,Integer[]> getWeightedVaRMetricWithIndices(com.qfs.vector.IVector referencePnl, com.qfs.vector.IVector originalPnLs, double[] weights, double quantile, boolean reverse, boolean isPnlOldestFirst)
Calculate the weighted VaR of the PnL vector for the quantile and also rfetrun the list of indicies that correspond to the weighted VaR.- Parameters:
referencePnl
- The PnL vector used for the scenario sortingoriginalPnLs
- The PnL vector used for the metric computationweights
- weightsquantile
- The quantile for the VaR, between 0 and 1 (equals 1 minus the confidence level).reverse
- false for negative tail measures, true for positive tail measuresisPnlOldestFirst
- flag to indicate if the PnL values in the PnL vector are present from with the oldest value at index 0 or the most recent value at index 0. The flag is set to 'true' if the oldest PnL value is present at index 0 and to 'false' if the most recent PnL value is present at index 0.- Returns:
- The weighted VaR measure and the list of indicies that correspond to the scenarios used for the computation of the weighted VaR
-
getIndices
public Integer[] getIndices(com.quartetfs.biz.pivot.IActivePivot activePivot, com.qfs.store.IDatastoreVersion datastore, IWeightedTailMeasureCalc.CalcType type, com.qfs.vector.IVector pnl, double[] weights, double quantile, boolean isPnlOldestFirst)
Description copied from interface:IWeightedTailMeasureCalc
Return an array of the indices in the vector that contribute to the weighted VaR/ES.- Specified by:
getIndices
in interfaceIWeightedTailMeasureCalc
- Parameters:
activePivot
- Active Pivot instance.datastore
- Datastore version.type
- "ES", "VaR", "VaE" or "ETG"pnl
- The PnL vector.weights
- the weightsquantile
- The quantile for the VaR, between 0 and 1 (equals 1 minus the confidence level).isPnlOldestFirst
- flag to indicate if the PnL values in the PnL vector are present from with the oldest value at index 0 or the most recent value at index 0. The flag is set to 'true' if the oldest PnL value is present at index 0 and to 'false' if the most recent PnL value is present at index 0.- Returns:
- The array of vector indices.
-
getLEstimator
public Double getLEstimator(com.quartetfs.biz.pivot.IActivePivot activePivot, com.qfs.store.IDatastoreVersion datastore, IWeightedTailMeasureCalc.CalcType type, com.qfs.vector.IVector referencePnl, com.qfs.vector.IVector pnl, double[] weights, double quantile, boolean isPnlOldestFirst)
Description copied from interface:IWeightedTailMeasureCalc
Calculate the contribution to the VaR, ES, VaE or ETG of the PnL vector for the quantile.- Specified by:
getLEstimator
in interfaceIWeightedTailMeasureCalc
- Parameters:
activePivot
- Active Pivot instance.datastore
- Datastore version.type
- "ES", "VaR", "VaE" or "ETG"referencePnl
- The aggregate PnL vector at the reference level.pnl
- The PnL vector for the current sub-portfolio.weights
- The weightsquantile
- The quantile for the ES, VaR or VaE between 0 and 1 (equals 1 minus the confidence level).isPnlOldestFirst
- flag to indicate if the PnL values in the PnL vector are present from with the oldest value at index 0 or the most recent value at index 0. The flag is set to 'true' if the oldest PnL value is present at index 0 and to 'false' if the most recent PnL value is present at index 0.- Returns:
- The tail measure (i.e. VaR, ES or VaE value of the vector for the quantile).
-
-