Package com.activeviam.risk.core.utils
Class PnLExplainFormulaProvider
- java.lang.Object
-
- com.activeviam.risk.core.utils.PnLExplainFormulaProvider
-
- All Implemented Interfaces:
IPnLExplainFormulaProvider
- Direct Known Subclasses:
ExtendedPnLExplainFormulaProvider
public class PnLExplainFormulaProvider extends Object implements IPnLExplainFormulaProvider
-
-
Field Summary
Fields Modifier and Type Field Description static String
ABSOLUTE
static String
DHS
static String
FORMULA_RULE
static String
INTERPOLATION_FLAG
static String
RELATIVE
-
Constructor Summary
Constructors Constructor Description PnLExplainFormulaProvider(org.springframework.core.env.Environment environment)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description com.qfs.func.ITriFunction<Double,Double,Double,Double>
absoluteFunctionPnL(double priceFactor, Integer derivativeOrder)
BiFunction<Double,Double,Double>
absoluteFunctionVaR(double priceFactor, Integer derivativeOrder)
com.quartetfs.fwk.impl.Pair<Double,String>
computeInterpolatedMarketDataForBiDimensionalVectorisedSensitivities(com.qfs.vector.IVector finalQuote, Map.Entry<Double,Integer> tenor, TreeMap<Double,Integer> inputTenors, Map.Entry<Double,Integer> maturity, TreeMap<Double,Integer> inputMaturities, BiFunction<Double,Double,Double> preInterpolationCalcTenors, BiFunction<Double,Double,Double> postInterpolationCalcTenors, BiFunction<Double,Double,Double> preInterpolationCalcMaturities, BiFunction<Double,Double,Double> postInterpolationCalcMaturities, boolean enableDebugString)
Computes the interpolation of market daa in the case of a vectorised 2D-sensitivitycom.quartetfs.fwk.impl.Pair<Double,String>
computeInterpolatedMarketDataForSingleDimensionalVectorisedSensitivities(com.qfs.vector.IVector finalQuote, Map.Entry<Double,Integer> tenor, TreeMap<Double,Integer> inputTenors, BiFunction<Double,Double,Double> preInterpolationCalcTenors, BiFunction<Double,Double,Double> postInterpolationCalcTenors, boolean enableDebugString)
Computes the interpolation of market daa in the case of a vectorised 1D-sensitivitycom.quartetfs.fwk.impl.Pair<Double,String>
computeInterpolatedMarketDataForTriDimensionalVectorisedSensitivities(com.qfs.vector.IVector finalQuote, Map.Entry<Double,Integer> tenor, TreeMap<Double,Integer> inputTenors, Map.Entry<Double,Integer> maturity, TreeMap<Double,Integer> inputMaturities, Map.Entry<Double,Integer> moneyness, TreeMap<Double,Integer> inputMoneyness, BiFunction<Double,Double,Double> preInterpolationCalcTenors, BiFunction<Double,Double,Double> postInterpolationCalcTenors, BiFunction<Double,Double,Double> preInterpolationCalcMaturities, BiFunction<Double,Double,Double> postInterpolationCalcMaturities, BiFunction<Double,Double,Double> preInterpolationCalcMoneyness, BiFunction<Double,Double,Double> postInterpolationCalcMoneyness, boolean enableDebugString)
Computes the interpolation of market daa in the case of a vectorised 3D-sensitivitycom.qfs.func.ITriFunction<Double,Double,Double,Double>
dhsFunction(double priceFactor, Integer derivativeOrder, double shift)
protected Object[]
getCalculationMethod(String sensitivityName, String riskClass)
org.springframework.core.env.Environment
getEnvironment()
Optional<Boolean>
getMarketDataInterpolationFlag(com.quartetfs.biz.pivot.query.IQueryCache cache, String sensitivityName, String riskClass)
Retrieves the flag that specifies whether interpolation of the market data is used for the computation of PnL explainboolean
getMarketDataInterpolationFlag(String sensitivityName, String riskClass)
com.quartetfs.fwk.impl.Pair<Double,String>
getMarketDataValueForScalarInterpolation(MarketPrice marketDataRecord, List<String> pos, int[] interpolationOrder)
Retrieves the market data from aMarketPrice
recordcom.qfs.func.ITriFunction<Double,Double,Double,Double>
getPnlExplainFormula(com.quartetfs.biz.pivot.query.IQueryCache cache, String sensitivityName, String riskClass)
Retrieves a function that computes pnl from a market change from T-1 to Tcom.qfs.func.ITriFunction<Double,Double,Double,Double>
getPnlExplainFormula(String sensitivityName, String riskClass)
BiFunction<Double,Double,Double>
getPostMarketDataInterpolationFunction(com.quartetfs.biz.pivot.query.IQueryCache cache, int axisIndex, String sensitivityName, String riskClass)
Retrieves a function that performs a calculation on the market data for a given axis after interpolation of market data is doneBiFunction<Double,Double,Double>
getPreMarketDataInterpolationFunction(com.quartetfs.biz.pivot.query.IQueryCache cache, int axisIndex, String sensitivityName, String riskClass)
Retrieves a function that performs a calculation on the market data for a given axis before interpolation of market data is doneBiFunction<Double,Double,Double>
getVaRExplainFormula(com.quartetfs.biz.pivot.query.IQueryCache cache, String sensitivityName, String riskClass)
Retrieves a function that computes pnl from a market change expressed as a shift that may be * Absolute : shift = MtM(T)-MtM(T-1) * Relative : shift = MtM(T)/MtM(T-1) - 1 * DHS : shift = (MtM(T) + c)/(MtM(T-1) + c) - 1BiFunction<Double,Double,Double>
getVaRExplainFormula(String sensitivityName, String riskClass)
com.qfs.func.ITriFunction<Double,Double,Double,Double>
relativeFunctionPnL(double priceFactor, Integer derivativeOrder)
BiFunction<Double,Double,Double>
relativeFunctionVaR(double priceFactor, Integer derivativeOrder)
-
-
-
Field Detail
-
FORMULA_RULE
public static final String FORMULA_RULE
- See Also:
- Constant Field Values
-
ABSOLUTE
public static final String ABSOLUTE
- See Also:
- Constant Field Values
-
RELATIVE
public static final String RELATIVE
- See Also:
- Constant Field Values
-
DHS
public static final String DHS
- See Also:
- Constant Field Values
-
INTERPOLATION_FLAG
public static final String INTERPOLATION_FLAG
- See Also:
- Constant Field Values
-
-
Method Detail
-
getCalculationMethod
protected Object[] getCalculationMethod(String sensitivityName, String riskClass)
-
absoluteFunctionPnL
public com.qfs.func.ITriFunction<Double,Double,Double,Double> absoluteFunctionPnL(double priceFactor, Integer derivativeOrder)
-
absoluteFunctionVaR
public BiFunction<Double,Double,Double> absoluteFunctionVaR(double priceFactor, Integer derivativeOrder)
-
relativeFunctionPnL
public com.qfs.func.ITriFunction<Double,Double,Double,Double> relativeFunctionPnL(double priceFactor, Integer derivativeOrder)
-
relativeFunctionVaR
public BiFunction<Double,Double,Double> relativeFunctionVaR(double priceFactor, Integer derivativeOrder)
-
dhsFunction
public com.qfs.func.ITriFunction<Double,Double,Double,Double> dhsFunction(double priceFactor, Integer derivativeOrder, double shift)
-
getPnlExplainFormula
public com.qfs.func.ITriFunction<Double,Double,Double,Double> getPnlExplainFormula(String sensitivityName, String riskClass)
-
getVaRExplainFormula
public BiFunction<Double,Double,Double> getVaRExplainFormula(String sensitivityName, String riskClass)
-
getPnlExplainFormula
public com.qfs.func.ITriFunction<Double,Double,Double,Double> getPnlExplainFormula(com.quartetfs.biz.pivot.query.IQueryCache cache, String sensitivityName, String riskClass)
Description copied from interface:IPnLExplainFormulaProvider
Retrieves a function that computes pnl from a market change from T-1 to T- Specified by:
getPnlExplainFormula
in interfaceIPnLExplainFormulaProvider
- Parameters:
cache
- cachesensitivityName
- sensitivity nameriskClass
- risk class- Returns:
- A function that takes as parameter (double sensi, double quoteTMinus1, double quoteT)
-
getVaRExplainFormula
public BiFunction<Double,Double,Double> getVaRExplainFormula(com.quartetfs.biz.pivot.query.IQueryCache cache, String sensitivityName, String riskClass)
Description copied from interface:IPnLExplainFormulaProvider
Retrieves a function that computes pnl from a market change expressed as a shift that may be * Absolute : shift = MtM(T)-MtM(T-1) * Relative : shift = MtM(T)/MtM(T-1) - 1 * DHS : shift = (MtM(T) + c)/(MtM(T-1) + c) - 1- Specified by:
getVaRExplainFormula
in interfaceIPnLExplainFormulaProvider
- Parameters:
cache
- cachesensitivityName
- sensitivity nameriskClass
- risk class- Returns:
- A function that takes as parameter (double sensi, double shift)
-
getMarketDataInterpolationFlag
public boolean getMarketDataInterpolationFlag(String sensitivityName, String riskClass)
-
getMarketDataInterpolationFlag
public Optional<Boolean> getMarketDataInterpolationFlag(com.quartetfs.biz.pivot.query.IQueryCache cache, String sensitivityName, String riskClass)
Description copied from interface:IPnLExplainFormulaProvider
Retrieves the flag that specifies whether interpolation of the market data is used for the computation of PnL explain- Specified by:
getMarketDataInterpolationFlag
in interfaceIPnLExplainFormulaProvider
- Parameters:
cache
- cachesensitivityName
- the sensitivity nameriskClass
- the risk class- Returns:
- A boolean flag that is true if interpolation is used and false otherwise
-
getPreMarketDataInterpolationFunction
public BiFunction<Double,Double,Double> getPreMarketDataInterpolationFunction(com.quartetfs.biz.pivot.query.IQueryCache cache, int axisIndex, String sensitivityName, String riskClass)
Description copied from interface:IPnLExplainFormulaProvider
Retrieves a function that performs a calculation on the market data for a given axis before interpolation of market data is done- Specified by:
getPreMarketDataInterpolationFunction
in interfaceIPnLExplainFormulaProvider
- Parameters:
cache
- cacheaxisIndex
- index of the axissensitivityName
- sensitivity nameriskClass
- risk class- Returns:
- A function that takes as parameter (double market data)
-
getPostMarketDataInterpolationFunction
public BiFunction<Double,Double,Double> getPostMarketDataInterpolationFunction(com.quartetfs.biz.pivot.query.IQueryCache cache, int axisIndex, String sensitivityName, String riskClass)
Description copied from interface:IPnLExplainFormulaProvider
Retrieves a function that performs a calculation on the market data for a given axis after interpolation of market data is done- Specified by:
getPostMarketDataInterpolationFunction
in interfaceIPnLExplainFormulaProvider
- Parameters:
cache
- cacheaxisIndex
- index of the axissensitivityName
- sensitivity nameriskClass
- risk class- Returns:
- A function that takes as parameter (double market data)
-
computeInterpolatedMarketDataForSingleDimensionalVectorisedSensitivities
public com.quartetfs.fwk.impl.Pair<Double,String> computeInterpolatedMarketDataForSingleDimensionalVectorisedSensitivities(com.qfs.vector.IVector finalQuote, Map.Entry<Double,Integer> tenor, TreeMap<Double,Integer> inputTenors, BiFunction<Double,Double,Double> preInterpolationCalcTenors, BiFunction<Double,Double,Double> postInterpolationCalcTenors, boolean enableDebugString)
Description copied from interface:IPnLExplainFormulaProvider
Computes the interpolation of market daa in the case of a vectorised 1D-sensitivity- Specified by:
computeInterpolatedMarketDataForSingleDimensionalVectorisedSensitivities
in interfaceIPnLExplainFormulaProvider
- Parameters:
finalQuote
- The IVector containing the market datatenor
- The map of all the tenorsinputTenors
- The map of tenors corresponding to the market data entrypreInterpolationCalcTenors
- The function computed before the interpolation of market data is performed on the tenor axispostInterpolationCalcTenors
- The function computed after the interpolation of market data is performed on the tenor axisenableDebugString
- Flag used to enable the generation of a debug string for market data interpolation. If set to 'true', the string is generated, if set to 'false', it is not generated- Returns:
- A
Pair<Double, String>
containing the interpolated market data on the left-hand side and the interpolation debug string on the right-hand side
-
computeInterpolatedMarketDataForBiDimensionalVectorisedSensitivities
public com.quartetfs.fwk.impl.Pair<Double,String> computeInterpolatedMarketDataForBiDimensionalVectorisedSensitivities(com.qfs.vector.IVector finalQuote, Map.Entry<Double,Integer> tenor, TreeMap<Double,Integer> inputTenors, Map.Entry<Double,Integer> maturity, TreeMap<Double,Integer> inputMaturities, BiFunction<Double,Double,Double> preInterpolationCalcTenors, BiFunction<Double,Double,Double> postInterpolationCalcTenors, BiFunction<Double,Double,Double> preInterpolationCalcMaturities, BiFunction<Double,Double,Double> postInterpolationCalcMaturities, boolean enableDebugString)
Description copied from interface:IPnLExplainFormulaProvider
Computes the interpolation of market daa in the case of a vectorised 2D-sensitivity- Specified by:
computeInterpolatedMarketDataForBiDimensionalVectorisedSensitivities
in interfaceIPnLExplainFormulaProvider
- Parameters:
finalQuote
- The IVector containing the market datatenor
- The map of all the tenorsinputTenors
- The map of tenors corresponding to the market data entrymaturity
- The map of all the maturitiesinputMaturities
- The map of maturities corresponding to the market data entrypreInterpolationCalcTenors
- The function computed before the interpolation of market data is performed on the tenor axispostInterpolationCalcTenors
- The function computed after the interpolation of market data is performed on the tenor axispreInterpolationCalcMaturities
- The function computed before the interpolation of market data is performed on the maturity axispostInterpolationCalcMaturities
- The function computed after the interpolation of market data is performed on the maturity axisenableDebugString
- Flag used to enable the generation of a debug string for market data interpolation. If set to 'true', the string is generated, if set to 'false', it is not generated- Returns:
- A
Pair<Double, String>
containing the interpolated market data on the left-hand side and the interpolation debug string on the right-hand side
-
computeInterpolatedMarketDataForTriDimensionalVectorisedSensitivities
public com.quartetfs.fwk.impl.Pair<Double,String> computeInterpolatedMarketDataForTriDimensionalVectorisedSensitivities(com.qfs.vector.IVector finalQuote, Map.Entry<Double,Integer> tenor, TreeMap<Double,Integer> inputTenors, Map.Entry<Double,Integer> maturity, TreeMap<Double,Integer> inputMaturities, Map.Entry<Double,Integer> moneyness, TreeMap<Double,Integer> inputMoneyness, BiFunction<Double,Double,Double> preInterpolationCalcTenors, BiFunction<Double,Double,Double> postInterpolationCalcTenors, BiFunction<Double,Double,Double> preInterpolationCalcMaturities, BiFunction<Double,Double,Double> postInterpolationCalcMaturities, BiFunction<Double,Double,Double> preInterpolationCalcMoneyness, BiFunction<Double,Double,Double> postInterpolationCalcMoneyness, boolean enableDebugString)
Description copied from interface:IPnLExplainFormulaProvider
Computes the interpolation of market daa in the case of a vectorised 3D-sensitivity- Specified by:
computeInterpolatedMarketDataForTriDimensionalVectorisedSensitivities
in interfaceIPnLExplainFormulaProvider
- Parameters:
finalQuote
- The IVector containing the market datatenor
- The map of all the tenorsinputTenors
- The map of tenors corresponding to the market data entrymaturity
- The map of all the maturitiesinputMaturities
- The map of maturities corresponding to the market data entrymoneyness
- The map of all the moneyness valuesinputMoneyness
- The map of moneyness values corresponding to the market data entrypreInterpolationCalcTenors
- The function computed before the interpolation of market data is performed on the tenor axispostInterpolationCalcTenors
- The function computed after the interpolation of market data is performed on the tenor axispreInterpolationCalcMaturities
- The function computed before the interpolation of market data is performed on the maturity axispostInterpolationCalcMaturities
- The function computed after the interpolation of market data is performed on the maturity axispreInterpolationCalcMoneyness
- The function computed before the interpolation of market data is performed on the moneyness axispostInterpolationCalcMoneyness
- The function computed after the interpolation of market data is performed on the moneyness axisenableDebugString
- Flag used to enable the generation of a debug string for market data interpolation. If set to 'true', the string is generated, if set to 'false', it is not generated- Returns:
- A
Pair<Double, String>
containing the interpolated market data on the left-hand side and the interpolation debug string on the right-hand side
-
getMarketDataValueForScalarInterpolation
public com.quartetfs.fwk.impl.Pair<Double,String> getMarketDataValueForScalarInterpolation(MarketPrice marketDataRecord, List<String> pos, int[] interpolationOrder)
Description copied from interface:IPnLExplainFormulaProvider
Retrieves the market data from aMarketPrice
record- Specified by:
getMarketDataValueForScalarInterpolation
in interfaceIPnLExplainFormulaProvider
- Parameters:
marketDataRecord
- The market price recordpos
- A list representing the position of the market daa to retrieve on each axisinterpolationOrder
- Order in which the interpolation of market data is performed. That order is defined as an int[] in which each index indicates the order in which each of the axis defined in thebucketTypes
parameter is processed during the interpolation calculation, starting at the value 0. Ex: if there are three elements defined inbucketTypes
like:{BucketType.TENOR_INPUT, BucketType.MATURITY_INPUT, BucketType.MONEYNESS_INPUT}
and if the interpolation order is defined as:0,1,2
, the interpolation will first be done on the tenors axis, then on the maturity axis, and then on the moneyness axis.- Returns:
- A
Pair<Double, String>
containing the market data (interpolated if interpolation is enabled) on the left-hand side and the interpolation debug string on the right-hand side
-
getEnvironment
public org.springframework.core.env.Environment getEnvironment()
-
-