Class AMarketDataRetrievalService

    • Field Detail

      • vectorInterpolation

        protected final IInterpolation<com.qfs.vector.IVector[],​com.qfs.vector.IVector> vectorInterpolation
      • defaultValue

        protected final double defaultValue
    • Constructor Detail

    • 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 interface IMarketDataRetrievalService
        Parameters:
        context - The caller context
        sensitivityKind - the type of sensitivity delta / gamma /vega / ....
        sensitivityName - the sensitivity name
        riskClass - 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 interface IMarketDataRetrievalService
        Parameters:
        context - The caller context
        sensitivityKind - the type of sensitivity delta / gamma /vega / ....
        sensitivityName - the sensitivity name
        riskClass - 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 interface IMarketDataRetrievalService
        Parameters:
        context - The caller context
        date - The as of date of the market data
        marketDataSet - The set of data to look for
        sensitivityKind - the type of sensitivity delta / gamma /vega / ....
        sensitivityName - The kind of sensi
        riskClass - The risk class of the requested market data
        riskFactor - The name of the market data
        requestedPillars - The list of the requested pillar. For instance IPillarSets[0] for tenor, IPillarSets[1] for maturity, IPillarSets[2] for moneyness
        interpolate - Is the interpolation allowed
        type - 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 / store
        debugKey - 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 shift
        matToLoc - The data topology
        axis - 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 type
        U - The boxed type of an item of the result
        Parameters:
        context - the caller context
        requestedPillars - The pillars of the result
        inputData - The pillars of the input values and the values to be copied to the result
        debugKey - If not null, debug info will be store at this position
        defaultValue - 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 type
        U - The boxed type of an item of the result
        Parameters:
        result - The result matching the output pillars
        values - The entry matching the input pillars
        depth - The axis nr currently processed
        mapping - The mapping if indexes from output to input
        shiftOut - The current index position in the result array
        shiftIn - 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 set
        input - 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 interface IMarketDataRetrievalService
        Parameters:
        context - The caller context
        date - The as of date of the market data
        scenario - The VaR scenario to look for
        marketDataSet - The set of data to look for
        sensitivityKind - the type of sensitivity delta / gamma /vega / ....
        sensitivityName - The kind of sensi
        riskClass - The risk class of the requested market data
        riskFactor - The name of the market data
        requestedPillars - The list of the requested pillar. For instance IPillarSets[0] for tenor, IPillarSets[1] for maturity, IPillarSets[2] for moneyness
        interpolate - Is the interpolation allowed
        type - 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 / store
        debugKey - 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 context
        result - the data to convert (may be modified)
        type - the requested type
        date - The requested date
        marketDataSet - The requested dataset
        sensitivityKind - The king of sensitivity
        sensitivityName - Th underlying name
        riskClass - the risk class
        riskFactor - 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 context
        result - the data to convert (may be modified)
        type - the requested type
        date - The requested date
        scenario - The current scenario
        marketDataSet - The requested dataset
        sensitivityKind - The kind of sensitivity
        sensitivityName - Th underlying name
        riskClass - the risk class
        riskFactor - 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 context
        date - The requested date
        scenario - The requested scenario
        marketDataSet - The requested dataset
        sensitivityKind - The kind of sensitivity
        sensitivityName - Th underlying name
        riskClass - the risk class
        riskFactor - The requested name
        pillarSets - 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 context
        date - The requested date
        marketDataSet - The requested dataset
        sensitivityKind - The type of sensitivity delta / gamma /vega / ....
        sensitivityName - Th underlying name
        riskClass - the risk class
        riskFactor - The requested name
        nrDim - 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 context
        cacheKeyQ - The key used to store the compiled query in the cache
        querySupplier - The query
        parameters - 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 context
        pillarVector - The input data containing pillar info and pillar position
        pillarsMapping - The info about the pillars, mainly we only use the size of the pillar description
        bucketTypes - 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 dimensions
        dataset - The cursor
        pillarsMapping - 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 cursor
        line - 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 type
        U - The boxed type of an item of the result
        Parameters:
        dataset - The input data set
        pillarVector - The description of the pillars
        data - The output data set
        pillarsMapping - 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 context
        date - The requested date
        scenario - The requested dataset
        marketDataSet - The requested market data set
        sensitivityKind - The type of sensitivity delta / gamma /vega / ....
        sensitivityName - The underlying
        riskClass - The risk class
        riskFactor - The requested name
        nrDim - 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 context
        date - The requested date
        marketDataSet - The requested dataset
        sensitivityKind - The type of sensitivity delta / gamma /vega / ....
        sensitivityName - The underlying
        riskClass - The risk class
        riskFactor - The requested name
        Returns:
        The value of the Nominal