Class AMarketDataRetrievalService
- java.lang.Object
-
- com.activeviam.risk.ref.services.impl.AMarketDataRetrievalService
-
- All Implemented Interfaces:
IMarketDataRetrievalService
- Direct Known Subclasses:
MarketDataRetrievalService
,ScalarMarketDataRetrievalService
public abstract class AMarketDataRetrievalService extends Object implements IMarketDataRetrievalService
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface com.activeviam.risk.core.services.IMarketDataRetrievalService
IMarketDataRetrievalService.IPillar, IMarketDataRetrievalService.IPillarSet, IMarketDataRetrievalService.MarketType
-
-
Field Summary
Fields Modifier and Type Field Description protected double
defaultValue
protected IInterpolation<double[],Double>
doubleInterpolation
protected IInterpolationConfiguration
interpolationConfiguration
protected IInterpolation<com.qfs.vector.IVector[],com.qfs.vector.IVector>
vectorInterpolation
-
Constructor Summary
Constructors Modifier Constructor Description protected
AMarketDataRetrievalService(IInterpolationConfiguration interpolationConfiguration, IInterpolation<double[],Double> doubleInterpolation, IInterpolation<com.qfs.vector.IVector[],com.qfs.vector.IVector> vectorInterpolation, double defaultValue)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected int
computeShift(int pillar, TreeMap<Double,Integer>[] matToLoc, int axis)
This function compute the shift on the data vector corresponding to the given pillar according to the pillar set topologyprotected <T,U>
voidextractData(com.qfs.store.query.ICursor dataset, List<Map<Object,Integer>> pillarVector, IMarketDataset<T,U> data, int[][] pillarsMapping)
This function is intended to extract data from a query cursor in order to fill internal structuresprotected <T,U>
voidfillResult(IMarketDataset<T,U> result, IMarketDataset<T,U> values, int depth, int[][] mapping, int shiftOut, int shiftIn)
This is a recursive function that will be called for each axis of pillarsprotected int[]
findMapping(IMarketDataRetrievalService.IPillarSet output, IMarketDataRetrievalService.IPillarSet input)
This function will link the output index to the input index of the pillar setsdouble[]
getMarketData(IServiceContext context, LocalDate date, String marketDataSet, String sensitivityKind, String sensitivityName, String riskClass, String riskFactor, IMarketDataRetrievalService.IPillarSet[] requestedPillars, boolean interpolate, IMarketDataRetrievalService.MarketType type, String debugKey)
Get some market dataprotected double[]
getMarketDataForShiftNormalization(IServiceContext context, LocalDate date, String scenario, String marketDataSet, String sensitivityKind, String sensitivityName, String riskClass, String riskFactor, IMarketDataRetrievalService.IPillarSet[] pillarSets)
Function that retrieves market data for shift normalizationboolean
getMarketDataInterpolationFlag(IServiceContext context, String sensitivityKind, String sensitivityName, String riskClass)
Retrieves the flag that specifies whether interpolation of the market data is used for the computation of PnL explainprotected <T,U>
IMarketDataset<T,U>getMarketDataNoInterpolate(IServiceContext context, IMarketDataRetrievalService.IPillarSet[] requestedPillars, IMarketDataset<T,U> inputData, String debugKey, U defaultValue)
Transforms the values with the inputPillars format into requestedPillars formatprotected abstract Double
getNominal(IServiceContext context, LocalDate date, String marketDataSet, String sensitivityKind, String sensitivityName, String riskClass, String riskFactor)
Retrieve the nominal of a risk factorprotected IMarketDataRetrievalService.IPillarSet[]
getPillarSets(IServiceContext context, List<Map<Object,Integer>> pillarVector, int[][] pillarsMapping, BucketType[] bucketTypes)
Convert a list of pillars info into a IPillarSet[]protected List<Map<Object,Integer>>
getPillarVectorMap(int nrDim, com.qfs.store.query.ICursor dataset, int[][] pillarsMapping)
Extract pillars from a cursorcom.qfs.vector.IVector[]
getPnlVector(IServiceContext context, LocalDate date, String scenario, String marketDataSet, String sensitivityKind, String sensitivityName, String riskClass, String riskFactor, IMarketDataRetrievalService.IPillarSet[] requestedPillars, boolean interpolate, IMarketDataRetrievalService.MarketType type, String debugKey)
Get some market dataprotected abstract IMarketDataset<double[],Double>
getRawMarketData(IServiceContext context, LocalDate date, String marketDataSet, String sensitivityKind, String sensitivityName, String riskClass, String riskFactor, int nrDim)
This function retrieves the data before any manipulationprotected abstract IMarketDataset<com.qfs.vector.IVector[],com.qfs.vector.IVector>
getRawPnlVector(IServiceContext context, LocalDate date, String scenario, String marketDataSet, String sensitivityKind, String sensitivityName, String riskClass, String riskFactor, int nrDim)
This function retrieves the data before any manipulationboolean
getShiftDataInterpolationFlag(IServiceContext context, String sensitivityKind, String sensitivityName, String riskClass)
Retrieves the flag that specifies whether interpolation of the shift data vector is used for the computation of VaRprotected double[]
handleAbsoluteRelativeResult(IServiceContext context, double[] result, IMarketDataRetrievalService.MarketType type, LocalDate date, String marketDataSet, String sensitivityKind, String sensitivityName, String riskClass, String riskFactor)
Convert the data from absolute to relative or vice-versa if neededprotected com.qfs.vector.IVector[]
handleAbsoluteRelativeResult(IServiceContext context, IMarketDataset<com.qfs.vector.IVector[],com.qfs.vector.IVector> result, IMarketDataRetrievalService.MarketType type, LocalDate date, String scenario, String marketDataSet, String sensitivityKind, String sensitivityName, String riskClass, String riskFactor)
Convert the data from absolute to relative or vice-versa if neededprotected Object
recToPillar(int[] map, com.qfs.store.record.IRecordReader line)
Store the pillar read from a cursor into an objectprotected com.qfs.store.query.IDictionaryCursor
runAsCompiledQuery(IServiceContext context, String cacheKeyQ, Supplier<com.qfs.store.query.IQuery> querySupplier, Object[] parameters)
Simply used to run a query as a pre-compiled query
-
-
-
Field Detail
-
interpolationConfiguration
protected final IInterpolationConfiguration interpolationConfiguration
-
doubleInterpolation
protected final IInterpolation<double[],Double> doubleInterpolation
-
vectorInterpolation
protected final IInterpolation<com.qfs.vector.IVector[],com.qfs.vector.IVector> vectorInterpolation
-
defaultValue
protected final double defaultValue
-
-
Constructor Detail
-
AMarketDataRetrievalService
protected AMarketDataRetrievalService(IInterpolationConfiguration interpolationConfiguration, IInterpolation<double[],Double> doubleInterpolation, IInterpolation<com.qfs.vector.IVector[],com.qfs.vector.IVector> vectorInterpolation, double defaultValue)
-
-
Method Detail
-
getMarketDataInterpolationFlag
public boolean getMarketDataInterpolationFlag(IServiceContext context, String sensitivityKind, String sensitivityName, String riskClass)
Description copied from interface:IMarketDataRetrievalService
Retrieves the flag that specifies whether interpolation of the market data is used for the computation of PnL explain- Specified by:
getMarketDataInterpolationFlag
in interfaceIMarketDataRetrievalService
- Parameters:
context
- The caller contextsensitivityKind
- the type of sensitivity delta / gamma /vega / ....sensitivityName
- the sensitivity nameriskClass
- the risk class- Returns:
- A boolean flag that is true if interpolation is used and false otherwise
-
getShiftDataInterpolationFlag
public boolean getShiftDataInterpolationFlag(IServiceContext context, String sensitivityKind, String sensitivityName, String riskClass)
Description copied from interface:IMarketDataRetrievalService
Retrieves the flag that specifies whether interpolation of the shift data vector is used for the computation of VaR- Specified by:
getShiftDataInterpolationFlag
in interfaceIMarketDataRetrievalService
- Parameters:
context
- The caller contextsensitivityKind
- the type of sensitivity delta / gamma /vega / ....sensitivityName
- the sensitivity nameriskClass
- the risk class- Returns:
- A boolean flag that is true if interpolation is used and false otherwise
-
getMarketData
public double[] getMarketData(IServiceContext context, LocalDate date, String marketDataSet, String sensitivityKind, String sensitivityName, String riskClass, String riskFactor, IMarketDataRetrievalService.IPillarSet[] requestedPillars, boolean interpolate, IMarketDataRetrievalService.MarketType type, String debugKey)
Description copied from interface:IMarketDataRetrievalService
Get some market data- Specified by:
getMarketData
in interfaceIMarketDataRetrievalService
- Parameters:
context
- The caller contextdate
- The as of date of the market datamarketDataSet
- The set of data to look forsensitivityKind
- the type of sensitivity delta / gamma /vega / ....sensitivityName
- The kind of sensiriskClass
- The risk class of the requested market datariskFactor
- The name of the market datarequestedPillars
- The list of the requested pillar. For instance IPillarSets[0] for tenor, IPillarSets[1] for maturity, IPillarSets[2] for moneynessinterpolate
- Is the interpolation allowedtype
- The type of the returned market data : absolute means the market price in currency (for bonds price x nominal), relative to the nominal, raw aka as it is normally used / storedebugKey
- If not null will store debug info in the cache at the ket location- Returns:
- A list of values describing a vector / map / cube depending of the requested dimensions, coordinates are (i * size(j) + j) * size(k) + k
-
computeShift
protected int computeShift(int pillar, TreeMap<Double,Integer>[] matToLoc, int axis)
This function compute the shift on the data vector corresponding to the given pillar according to the pillar set topology- Parameters:
pillar
- The pillar number we want to convert into shiftmatToLoc
- The data topologyaxis
- The axis number of the related pillar- Returns:
- A shift compatible with the data vector
-
getMarketDataNoInterpolate
protected <T,U> IMarketDataset<T,U> getMarketDataNoInterpolate(IServiceContext context, IMarketDataRetrievalService.IPillarSet[] requestedPillars, IMarketDataset<T,U> inputData, String debugKey, U defaultValue)
Transforms the values with the inputPillars format into requestedPillars format- Type Parameters:
T
- The result vector typeU
- The boxed type of an item of the result- Parameters:
context
- the caller contextrequestedPillars
- The pillars of the resultinputData
- The pillars of the input values and the values to be copied to the resultdebugKey
- If not null, debug info will be store at this positiondefaultValue
- The value when no data is found- Returns:
- Values with the specified format
-
fillResult
protected <T,U> void fillResult(IMarketDataset<T,U> result, IMarketDataset<T,U> values, int depth, int[][] mapping, int shiftOut, int shiftIn)
This is a recursive function that will be called for each axis of pillars- Type Parameters:
T
- The result vector typeU
- The boxed type of an item of the result- Parameters:
result
- The result matching the output pillarsvalues
- The entry matching the input pillarsdepth
- The axis nr currently processedmapping
- The mapping if indexes from output to inputshiftOut
- The current index position in the result arrayshiftIn
- The current index position in the values array
-
findMapping
protected int[] findMapping(IMarketDataRetrievalService.IPillarSet output, IMarketDataRetrievalService.IPillarSet input)
This function will link the output index to the input index of the pillar sets- Parameters:
output
- The resulting pillar setinput
- The retrieved pillar set- Returns:
- An arrays with -1 for no mapping or the corresponding index in the input
-
getPnlVector
public com.qfs.vector.IVector[] getPnlVector(IServiceContext context, LocalDate date, String scenario, String marketDataSet, String sensitivityKind, String sensitivityName, String riskClass, String riskFactor, IMarketDataRetrievalService.IPillarSet[] requestedPillars, boolean interpolate, IMarketDataRetrievalService.MarketType type, String debugKey)
Description copied from interface:IMarketDataRetrievalService
Get some market data- Specified by:
getPnlVector
in interfaceIMarketDataRetrievalService
- Parameters:
context
- The caller contextdate
- The as of date of the market datascenario
- The VaR scenario to look formarketDataSet
- The set of data to look forsensitivityKind
- the type of sensitivity delta / gamma /vega / ....sensitivityName
- The kind of sensiriskClass
- The risk class of the requested market datariskFactor
- The name of the market datarequestedPillars
- The list of the requested pillar. For instance IPillarSets[0] for tenor, IPillarSets[1] for maturity, IPillarSets[2] for moneynessinterpolate
- Is the interpolation allowedtype
- The type of the returned market data : absolute means the market price in currency, relative to the nominal (current configuration for VaR computation), raw aka as it is normally used / storedebugKey
- If not null will store debug info in the cache at the ket location- Returns:
- A list of values describing a vector / map / cube depending of the requested dimensions, coordinates are (i * size(j) + j) * size(k) + k
-
handleAbsoluteRelativeResult
protected double[] handleAbsoluteRelativeResult(IServiceContext context, double[] result, IMarketDataRetrievalService.MarketType type, LocalDate date, String marketDataSet, String sensitivityKind, String sensitivityName, String riskClass, String riskFactor)
Convert the data from absolute to relative or vice-versa if needed- Parameters:
context
- The caller contextresult
- the data to convert (may be modified)type
- the requested typedate
- The requested datemarketDataSet
- The requested datasetsensitivityKind
- The king of sensitivitysensitivityName
- Th underlying nameriskClass
- the risk classriskFactor
- The requested name- Returns:
- the result with the right convention or null if missing data
-
handleAbsoluteRelativeResult
protected com.qfs.vector.IVector[] handleAbsoluteRelativeResult(IServiceContext context, IMarketDataset<com.qfs.vector.IVector[],com.qfs.vector.IVector> result, IMarketDataRetrievalService.MarketType type, LocalDate date, String scenario, String marketDataSet, String sensitivityKind, String sensitivityName, String riskClass, String riskFactor)
Convert the data from absolute to relative or vice-versa if needed- Parameters:
context
- The caller contextresult
- the data to convert (may be modified)type
- the requested typedate
- The requested datescenario
- The current scenariomarketDataSet
- The requested datasetsensitivityKind
- The kind of sensitivitysensitivityName
- Th underlying nameriskClass
- the risk classriskFactor
- The requested name- Returns:
- the result with the right convention or null if missing data
-
getMarketDataForShiftNormalization
protected double[] getMarketDataForShiftNormalization(IServiceContext context, LocalDate date, String scenario, String marketDataSet, String sensitivityKind, String sensitivityName, String riskClass, String riskFactor, IMarketDataRetrievalService.IPillarSet[] pillarSets)
Function that retrieves market data for shift normalization- Parameters:
context
- The caller contextdate
- The requested datescenario
- The requested scenariomarketDataSet
- The requested datasetsensitivityKind
- The kind of sensitivitysensitivityName
- Th underlying nameriskClass
- the risk classriskFactor
- The requested namepillarSets
- The requested pillars- Returns:
- A list of market data
-
getRawMarketData
protected abstract IMarketDataset<double[],Double> getRawMarketData(IServiceContext context, LocalDate date, String marketDataSet, String sensitivityKind, String sensitivityName, String riskClass, String riskFactor, int nrDim)
This function retrieves the data before any manipulation- Parameters:
context
- The caller contextdate
- The requested datemarketDataSet
- The requested datasetsensitivityKind
- The type of sensitivity delta / gamma /vega / ....sensitivityName
- Th underlying nameriskClass
- the risk classriskFactor
- The requested namenrDim
- The number of dimension of the result- Returns:
- A list of MD and its axis description
-
runAsCompiledQuery
protected com.qfs.store.query.IDictionaryCursor runAsCompiledQuery(IServiceContext context, String cacheKeyQ, Supplier<com.qfs.store.query.IQuery> querySupplier, Object[] parameters)
Simply used to run a query as a pre-compiled query- Parameters:
context
- The caller contextcacheKeyQ
- The key used to store the compiled query in the cachequerySupplier
- The queryparameters
- The query parameters- Returns:
- A cursor to the result
-
getPillarSets
protected IMarketDataRetrievalService.IPillarSet[] getPillarSets(IServiceContext context, List<Map<Object,Integer>> pillarVector, int[][] pillarsMapping, BucketType[] bucketTypes)
Convert a list of pillars info into a IPillarSet[]- Parameters:
context
- The caller contextpillarVector
- The input data containing pillar info and pillar positionpillarsMapping
- The info about the pillars, mainly we only use the size of the pillar descriptionbucketTypes
- Pillar type- Returns:
- A normalized set of pillar sets
-
getPillarVectorMap
protected List<Map<Object,Integer>> getPillarVectorMap(int nrDim, com.qfs.store.query.ICursor dataset, int[][] pillarsMapping)
Extract pillars from a cursor- Parameters:
nrDim
- Number of wanted dimensionsdataset
- The cursorpillarsMapping
- The location of the pillars in the line of the cursor- Returns:
- A map of pillars
-
recToPillar
protected Object recToPillar(int[] map, com.qfs.store.record.IRecordReader line)
Store the pillar read from a cursor into an object- Parameters:
map
- the position(s) of the pillar on the cursorline
- the current line of the cursor- Returns:
- An object describing the pillar
-
extractData
protected <T,U> void extractData(com.qfs.store.query.ICursor dataset, List<Map<Object,Integer>> pillarVector, IMarketDataset<T,U> data, int[][] pillarsMapping)
This function is intended to extract data from a query cursor in order to fill internal structures- Type Parameters:
T
- The result vector typeU
- The boxed type of an item of the result- Parameters:
dataset
- The input data setpillarVector
- The description of the pillarsdata
- The output data setpillarsMapping
- The position of the pillars entries in the input data set
-
getRawPnlVector
protected abstract IMarketDataset<com.qfs.vector.IVector[],com.qfs.vector.IVector> getRawPnlVector(IServiceContext context, LocalDate date, String scenario, String marketDataSet, String sensitivityKind, String sensitivityName, String riskClass, String riskFactor, int nrDim)
This function retrieves the data before any manipulation- Parameters:
context
- The caller contextdate
- The requested datescenario
- The requested datasetmarketDataSet
- The requested market data setsensitivityKind
- The type of sensitivity delta / gamma /vega / ....sensitivityName
- The underlyingriskClass
- The risk classriskFactor
- The requested namenrDim
- The number of dimension of the result- Returns:
- A list of pnl vector and its axis description
-
getNominal
protected abstract Double getNominal(IServiceContext context, LocalDate date, String marketDataSet, String sensitivityKind, String sensitivityName, String riskClass, String riskFactor)
Retrieve the nominal of a risk factor- Parameters:
context
- The caller contextdate
- The requested datemarketDataSet
- The requested datasetsensitivityKind
- The type of sensitivity delta / gamma /vega / ....sensitivityName
- The underlyingriskClass
- The risk classriskFactor
- The requested name- Returns:
- The value of the Nominal
-
-