Package com.activeviam.risk.core.utils
Class PostProcessorUtils
- java.lang.Object
-
- com.activeviam.risk.core.utils.PostProcessorUtils
-
public class PostProcessorUtils extends Object
-
-
Field Summary
Fields Modifier and Type Field Description static String
FORMULA_RULE
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T extends com.quartetfs.biz.pivot.cube.hierarchy.ILevelInfo>
List<T>addPartitioningLevel(List<T> levels, com.quartetfs.biz.pivot.cube.hierarchy.ILevelInfo levelToAdd)
static <T extends com.quartetfs.biz.pivot.cube.hierarchy.ILevelInfo>
Collection<T>addPartitioningLevels(Collection<T> levels, Collection<T> levelsToAdd)
static com.quartetfs.biz.pivot.ILocation
ancestorLocation(com.quartetfs.biz.pivot.ILocation originalLocation, com.quartetfs.biz.pivot.ILocation location, com.quartetfs.biz.pivot.cube.hierarchy.IHierarchyInfo hierarchy)
Get ancestor location along risk factor hierarchy up to level in original locationstatic boolean
checkFilter(com.quartetfs.biz.pivot.ILocation location, com.quartetfs.biz.pivot.cube.hierarchy.ILevelInfo level, Object value)
static com.quartetfs.biz.pivot.ILocation
childLocation(com.quartetfs.biz.pivot.ILocation location, com.quartetfs.biz.pivot.cube.hierarchy.ILevelInfo level)
static com.quartetfs.biz.pivot.ILocation
childLocation(com.quartetfs.biz.pivot.ILocation location, List<com.quartetfs.biz.pivot.cube.hierarchy.ILevelInfo> levels)
static com.activeviam.copper.api.CopperHierarchy
copperHierarchy(String level)
Transforms a legacy hierarchy string into a copper legacy it could be * level@hierarchy@dimension * hierarchy@dimension * hierarchystatic com.activeviam.copper.api.CopperLevel
copperLevel(String level)
Transforms a legacy level string : level@hierarchy@dimension into a copper levelstatic com.qfs.agg.IAggregationFunction
createAggregationFunction(String type)
static Object[]
createPath(com.quartetfs.biz.pivot.cube.hierarchy.ILevelInfo level, Object member)
static <T> Optional<T>
dateSearch(LocalDate startDate, BiFunction<LocalDate,Boolean,LocalDate> dateStepper, int maxSteps, Function<LocalDate,Optional<T>> function)
Utility method to search through the datastore for the "next" or "previous" date which contains the desired data.static com.quartetfs.biz.pivot.ILocation
descendentLocation(com.quartetfs.biz.pivot.ILocation location, com.quartetfs.biz.pivot.cube.hierarchy.ILevelInfo level)
Add wildcards down to the descendent levelstatic String
getBucket(com.quartetfs.biz.pivot.ILocation location, List<com.quartetfs.biz.pivot.cube.hierarchy.ILevelInfo> levels, String bucketDefaultValue)
Retrieve the bucket by scanning the location level by level on the list orderstatic Object[]
getCalculationMethod(org.springframework.core.env.Environment environment, String sensitivityName, String riskClass)
Return a calculation method found at the key formula.rule.[sensitivityName].[riskClass]static Object[]
getCalculationMethod(org.springframework.core.env.Environment environment, String sensitivityKind, String sensitivityName, String riskClass)
Return the calculation method found in the config filestatic <T,K>
TgetInCacheOrCompute(ConcurrentMap<K,? super Optional<T>> cache, K key, Supplier<T> supplier)
This function does mainly the same as computeIfAbsent, except that it is not synchronized, so it won't produces dead locks in case of nested calls, and will run faster.static <T,K>
TgetInCacheOrComputeNeverNull(ConcurrentMap<K,? super T> cache, K key, Supplier<T> supplier)
This function does mainly the same as computeIfAbsent, except that it is not synchronized, so it won't produces dead locks in case of nested calls, and will run faster.static com.quartetfs.fwk.IPair<Boolean,double[]>
getLadderScale(com.qfs.store.IDatastoreVersion datastoreVersion, com.quartetfs.biz.pivot.query.IQueryCache queryCache, com.quartetfs.biz.pivot.ILocation location, com.quartetfs.biz.pivot.cube.hierarchy.ILevelInfo asOfDateLevelInfo, com.quartetfs.biz.pivot.cube.hierarchy.ILevelInfo riskClassLevelInfo)
Retrieves the sensitivity ladder scale and type, based on an as-of date and risk class retrieved from the location, with caching.static com.quartetfs.fwk.IPair<Boolean,double[]>
getLadderScale(com.qfs.store.IDatastoreVersion datastoreVersion, com.quartetfs.biz.pivot.query.IQueryCache queryCache, LocalDate asOfDate, String riskClass)
Retrieves the sensitivity ladder scale and type depending on as-of date and risk class, with caching.static com.quartetfs.biz.pivot.cube.hierarchy.ILevelInfo
optionalLevelInfo(com.quartetfs.biz.pivot.IActivePivot pivot, String description)
static void
reduce(com.quartetfs.biz.pivot.ILocation location, List<com.quartetfs.biz.pivot.cellset.IAggregatesRetrievalResult> partialResults, com.quartetfs.biz.pivot.cellset.IPostProcessedRetrievalResultWriter writer, com.qfs.agg.IAggregationFunction aggregationFunction)
IPartitionedPostProcessor.reduce(ILocation, List, IPostProcessedRetrievalResultWriter)
static <T extends com.quartetfs.biz.pivot.cube.hierarchy.ILevelInfo>
Collection<T>removePartitioningLevel(Collection<T> levels, com.quartetfs.biz.pivot.cube.hierarchy.ILevelInfo levelToRemove)
static <T extends com.quartetfs.biz.pivot.cube.hierarchy.ILevelInfo>
Collection<T>removePartitioningLevels(Collection<T> levels, Collection<? extends com.quartetfs.biz.pivot.cube.hierarchy.ILevelInfo> levelsToRemove)
static com.quartetfs.biz.pivot.ILocation
setCoordinate(com.quartetfs.biz.pivot.ILocation location, com.quartetfs.biz.pivot.cube.hierarchy.ILevelInfo level, Object value)
static com.quartetfs.biz.pivot.ILocation
setFilter(com.quartetfs.biz.pivot.ILocation location, com.quartetfs.biz.pivot.cube.hierarchy.ILevelInfo level, Object value)
static com.quartetfs.biz.pivot.ILocation
setWildCardsToLevel(com.quartetfs.biz.pivot.ILocation location, com.quartetfs.biz.pivot.cube.hierarchy.ILevelInfo level)
static com.quartetfs.biz.pivot.ILocation
shift(com.quartetfs.biz.pivot.ILocation location, com.quartetfs.biz.pivot.cube.hierarchy.ILevelInfo level, Object oldValue, Object newValue)
static List<com.quartetfs.biz.pivot.cube.hierarchy.IHierarchyInfo>
toHierarchyInfo(com.quartetfs.biz.pivot.IActivePivot pivot, String descriptions)
static List<com.quartetfs.biz.pivot.cube.hierarchy.IHierarchyInfo>
toHierarchyInfo(com.quartetfs.biz.pivot.IActivePivot pivot, String seperator, String descriptions)
static List<com.quartetfs.biz.pivot.cube.hierarchy.ILevelInfo>
toLevelInfo(com.quartetfs.biz.pivot.IActivePivot pivot, String descriptions)
static List<com.quartetfs.biz.pivot.cube.hierarchy.ILevelInfo>
toLevelInfo(com.quartetfs.biz.pivot.IActivePivot pivot, String seperator, String descriptions)
static Map<com.quartetfs.biz.pivot.cube.hierarchy.IHierarchyInfo,com.quartetfs.biz.pivot.cube.hierarchy.ILevelInfo>
toLevelInfoByHierarchy(com.quartetfs.biz.pivot.IActivePivot pivot, String descriptions)
static Map<com.quartetfs.biz.pivot.cube.hierarchy.IHierarchyInfo,com.quartetfs.biz.pivot.cube.hierarchy.ILevelInfo>
toLevelInfoByHierarchy(com.quartetfs.biz.pivot.IActivePivot pivot, String seperator, String descriptions)
static Map<com.quartetfs.biz.pivot.cube.hierarchy.ILevelInfo,String>
toLevelInfoMap(com.quartetfs.biz.pivot.IActivePivot pivot, String descriptions)
static Map<com.quartetfs.biz.pivot.cube.hierarchy.ILevelInfo,String>
toLevelInfoMap(com.quartetfs.biz.pivot.IActivePivot pivot, String seperator, String descriptions)
static com.quartetfs.biz.pivot.ILocation
truncateOrSetWildCardsToLevel(com.quartetfs.biz.pivot.ILocation location, com.quartetfs.biz.pivot.cube.hierarchy.ILevelInfo level)
static com.quartetfs.biz.pivot.ILocation
truncateToLevel(com.quartetfs.biz.pivot.ILocation location, com.quartetfs.biz.pivot.cube.hierarchy.ILevelInfo level)
static com.quartetfs.biz.pivot.ILocation
truncateToLevelZero(com.quartetfs.biz.pivot.ILocation location, com.quartetfs.biz.pivot.cube.hierarchy.IHierarchyInfo hierarchyInfo)
static com.quartetfs.biz.pivot.ILocation
truncateToLevelZero(com.quartetfs.biz.pivot.ILocation location, Collection<com.quartetfs.biz.pivot.cube.hierarchy.IHierarchyInfo> hierarchyInfos)
-
-
-
Field Detail
-
FORMULA_RULE
public static final String FORMULA_RULE
- See Also:
- Constant Field Values
-
-
Method Detail
-
optionalLevelInfo
public static com.quartetfs.biz.pivot.cube.hierarchy.ILevelInfo optionalLevelInfo(com.quartetfs.biz.pivot.IActivePivot pivot, String description) throws com.quartetfs.fwk.QuartetException
- Throws:
com.quartetfs.fwk.QuartetException
-
toLevelInfo
public static List<com.quartetfs.biz.pivot.cube.hierarchy.ILevelInfo> toLevelInfo(com.quartetfs.biz.pivot.IActivePivot pivot, String descriptions) throws com.quartetfs.fwk.QuartetException
- Throws:
com.quartetfs.fwk.QuartetException
-
toLevelInfo
public static List<com.quartetfs.biz.pivot.cube.hierarchy.ILevelInfo> toLevelInfo(com.quartetfs.biz.pivot.IActivePivot pivot, String seperator, String descriptions) throws com.quartetfs.fwk.QuartetException
- Throws:
com.quartetfs.fwk.QuartetException
-
toHierarchyInfo
public static List<com.quartetfs.biz.pivot.cube.hierarchy.IHierarchyInfo> toHierarchyInfo(com.quartetfs.biz.pivot.IActivePivot pivot, String descriptions) throws com.quartetfs.fwk.QuartetException
- Throws:
com.quartetfs.fwk.QuartetException
-
toHierarchyInfo
public static List<com.quartetfs.biz.pivot.cube.hierarchy.IHierarchyInfo> toHierarchyInfo(com.quartetfs.biz.pivot.IActivePivot pivot, String seperator, String descriptions) throws com.quartetfs.fwk.QuartetException
- Throws:
com.quartetfs.fwk.QuartetException
-
toLevelInfoMap
public static Map<com.quartetfs.biz.pivot.cube.hierarchy.ILevelInfo,String> toLevelInfoMap(com.quartetfs.biz.pivot.IActivePivot pivot, String descriptions) throws com.quartetfs.fwk.QuartetException
- Throws:
com.quartetfs.fwk.QuartetException
-
toLevelInfoMap
public static Map<com.quartetfs.biz.pivot.cube.hierarchy.ILevelInfo,String> toLevelInfoMap(com.quartetfs.biz.pivot.IActivePivot pivot, String seperator, String descriptions) throws com.quartetfs.fwk.QuartetException
- Throws:
com.quartetfs.fwk.QuartetException
-
toLevelInfoByHierarchy
public static Map<com.quartetfs.biz.pivot.cube.hierarchy.IHierarchyInfo,com.quartetfs.biz.pivot.cube.hierarchy.ILevelInfo> toLevelInfoByHierarchy(com.quartetfs.biz.pivot.IActivePivot pivot, String descriptions) throws com.quartetfs.fwk.QuartetException
- Throws:
com.quartetfs.fwk.QuartetException
-
toLevelInfoByHierarchy
public static Map<com.quartetfs.biz.pivot.cube.hierarchy.IHierarchyInfo,com.quartetfs.biz.pivot.cube.hierarchy.ILevelInfo> toLevelInfoByHierarchy(com.quartetfs.biz.pivot.IActivePivot pivot, String seperator, String descriptions) throws com.quartetfs.fwk.QuartetException
- Throws:
com.quartetfs.fwk.QuartetException
-
createAggregationFunction
public static com.qfs.agg.IAggregationFunction createAggregationFunction(String type) throws com.quartetfs.fwk.QuartetException
- Throws:
com.quartetfs.fwk.QuartetException
-
truncateToLevelZero
public static com.quartetfs.biz.pivot.ILocation truncateToLevelZero(com.quartetfs.biz.pivot.ILocation location, Collection<com.quartetfs.biz.pivot.cube.hierarchy.IHierarchyInfo> hierarchyInfos)
-
truncateToLevelZero
public static com.quartetfs.biz.pivot.ILocation truncateToLevelZero(com.quartetfs.biz.pivot.ILocation location, com.quartetfs.biz.pivot.cube.hierarchy.IHierarchyInfo hierarchyInfo)
-
truncateOrSetWildCardsToLevel
public static com.quartetfs.biz.pivot.ILocation truncateOrSetWildCardsToLevel(com.quartetfs.biz.pivot.ILocation location, com.quartetfs.biz.pivot.cube.hierarchy.ILevelInfo level)
-
setWildCardsToLevel
public static com.quartetfs.biz.pivot.ILocation setWildCardsToLevel(com.quartetfs.biz.pivot.ILocation location, com.quartetfs.biz.pivot.cube.hierarchy.ILevelInfo level)
-
truncateToLevel
public static com.quartetfs.biz.pivot.ILocation truncateToLevel(com.quartetfs.biz.pivot.ILocation location, com.quartetfs.biz.pivot.cube.hierarchy.ILevelInfo level)
-
setCoordinate
public static com.quartetfs.biz.pivot.ILocation setCoordinate(com.quartetfs.biz.pivot.ILocation location, com.quartetfs.biz.pivot.cube.hierarchy.ILevelInfo level, Object value)
-
setFilter
public static com.quartetfs.biz.pivot.ILocation setFilter(com.quartetfs.biz.pivot.ILocation location, com.quartetfs.biz.pivot.cube.hierarchy.ILevelInfo level, Object value)
-
shift
public static com.quartetfs.biz.pivot.ILocation shift(com.quartetfs.biz.pivot.ILocation location, com.quartetfs.biz.pivot.cube.hierarchy.ILevelInfo level, Object oldValue, Object newValue)
-
checkFilter
public static boolean checkFilter(com.quartetfs.biz.pivot.ILocation location, com.quartetfs.biz.pivot.cube.hierarchy.ILevelInfo level, Object value)
-
childLocation
public static com.quartetfs.biz.pivot.ILocation childLocation(com.quartetfs.biz.pivot.ILocation location, List<com.quartetfs.biz.pivot.cube.hierarchy.ILevelInfo> levels)
-
childLocation
public static com.quartetfs.biz.pivot.ILocation childLocation(com.quartetfs.biz.pivot.ILocation location, com.quartetfs.biz.pivot.cube.hierarchy.ILevelInfo level)
-
descendentLocation
public static com.quartetfs.biz.pivot.ILocation descendentLocation(com.quartetfs.biz.pivot.ILocation location, com.quartetfs.biz.pivot.cube.hierarchy.ILevelInfo level)
Add wildcards down to the descendent level- Parameters:
location
- locationlevel
- level- Returns:
- ILocation
-
createPath
public static Object[] createPath(com.quartetfs.biz.pivot.cube.hierarchy.ILevelInfo level, Object member)
-
ancestorLocation
public static com.quartetfs.biz.pivot.ILocation ancestorLocation(com.quartetfs.biz.pivot.ILocation originalLocation, com.quartetfs.biz.pivot.ILocation location, com.quartetfs.biz.pivot.cube.hierarchy.IHierarchyInfo hierarchy)
Get ancestor location along risk factor hierarchy up to level in original location- Parameters:
originalLocation
- originalLocationlocation
- locationhierarchy
- hierarchy- Returns:
- ILocation
-
addPartitioningLevel
public static <T extends com.quartetfs.biz.pivot.cube.hierarchy.ILevelInfo> List<T> addPartitioningLevel(List<T> levels, com.quartetfs.biz.pivot.cube.hierarchy.ILevelInfo levelToAdd)
-
addPartitioningLevels
public static <T extends com.quartetfs.biz.pivot.cube.hierarchy.ILevelInfo> Collection<T> addPartitioningLevels(Collection<T> levels, Collection<T> levelsToAdd)
-
removePartitioningLevel
public static <T extends com.quartetfs.biz.pivot.cube.hierarchy.ILevelInfo> Collection<T> removePartitioningLevel(Collection<T> levels, com.quartetfs.biz.pivot.cube.hierarchy.ILevelInfo levelToRemove)
-
removePartitioningLevels
public static <T extends com.quartetfs.biz.pivot.cube.hierarchy.ILevelInfo> Collection<T> removePartitioningLevels(Collection<T> levels, Collection<? extends com.quartetfs.biz.pivot.cube.hierarchy.ILevelInfo> levelsToRemove)
-
reduce
public static void reduce(com.quartetfs.biz.pivot.ILocation location, List<com.quartetfs.biz.pivot.cellset.IAggregatesRetrievalResult> partialResults, com.quartetfs.biz.pivot.cellset.IPostProcessedRetrievalResultWriter writer, com.qfs.agg.IAggregationFunction aggregationFunction)
IPartitionedPostProcessor.reduce(ILocation, List, IPostProcessedRetrievalResultWriter)
- Parameters:
location
- The location on which this post-processor is being executedpartialResults
- The results of the execution of this post-processor on each partitionwriter
- The writer to contribute toaggregationFunction
- The aggregation function to use
-
getInCacheOrCompute
public static <T,K> T getInCacheOrCompute(ConcurrentMap<K,? super Optional<T>> cache, K key, Supplier<T> supplier)
This function does mainly the same as computeIfAbsent, except that it is not synchronized, so it won't produces dead locks in case of nested calls, and will run faster. The supplier may be called even if the key is present in case of close concurrency See https://bugs.openjdk.java.net/browse/JDK-8161372- Type Parameters:
T
- The type of the cached objectK
- The type of the key- Parameters:
cache
- The used cache mainly returned by getQueryCache()key
- The key in the cachesupplier
- The function that produces the return value- Returns:
- The result of supplier
-
getInCacheOrComputeNeverNull
public static <T,K> T getInCacheOrComputeNeverNull(ConcurrentMap<K,? super T> cache, K key, Supplier<T> supplier)
This function does mainly the same as computeIfAbsent, except that it is not synchronized, so it won't produces dead locks in case of nested calls, and will run faster. The supplier may be called even if the key is present in case of close concurrency See https://bugs.openjdk.java.net/browse/JDK-8161372- Type Parameters:
T
- The type of the cached objectK
- The type of the key- Parameters:
cache
- The used cache mainly returned by getQueryCache()key
- The key in the cachesupplier
- The function that produces the return value- Returns:
- The result of supplier
-
getBucket
public static String getBucket(com.quartetfs.biz.pivot.ILocation location, List<com.quartetfs.biz.pivot.cube.hierarchy.ILevelInfo> levels, String bucketDefaultValue)
Retrieve the bucket by scanning the location level by level on the list order- Parameters:
location
- The input locationlevels
- The list of levels to look forbucketDefaultValue
- The default value of the bucket- Returns:
- The retrieved bucket
-
copperLevel
public static com.activeviam.copper.api.CopperLevel copperLevel(String level)
Transforms a legacy level string : level@hierarchy@dimension into a copper level- Parameters:
level
- The legacy level string- Returns:
- the corresponding level string
-
copperHierarchy
public static com.activeviam.copper.api.CopperHierarchy copperHierarchy(String level)
Transforms a legacy hierarchy string into a copper legacy it could be * level@hierarchy@dimension * hierarchy@dimension * hierarchy- Parameters:
level
- the hierarchy string- Returns:
- the corresponding hierarchy
-
getLadderScale
public static com.quartetfs.fwk.IPair<Boolean,double[]> getLadderScale(com.qfs.store.IDatastoreVersion datastoreVersion, com.quartetfs.biz.pivot.query.IQueryCache queryCache, com.quartetfs.biz.pivot.ILocation location, com.quartetfs.biz.pivot.cube.hierarchy.ILevelInfo asOfDateLevelInfo, com.quartetfs.biz.pivot.cube.hierarchy.ILevelInfo riskClassLevelInfo)
Retrieves the sensitivity ladder scale and type, based on an as-of date and risk class retrieved from the location, with caching.- Parameters:
datastoreVersion
- The datastore version object.queryCache
- The query cache.location
- The cube location.asOfDateLevelInfo
- The as-of date level info.riskClassLevelInfo
- The risk class level info.- Returns:
- The sensitivity ladder scale and type.
-
getLadderScale
public static com.quartetfs.fwk.IPair<Boolean,double[]> getLadderScale(com.qfs.store.IDatastoreVersion datastoreVersion, com.quartetfs.biz.pivot.query.IQueryCache queryCache, LocalDate asOfDate, String riskClass)
Retrieves the sensitivity ladder scale and type depending on as-of date and risk class, with caching.- Parameters:
datastoreVersion
- The datastore version object.queryCache
- The query cache.asOfDate
- The as-of date.riskClass
- The risk class.- Returns:
- The sensitivity ladder scale and type.
-
dateSearch
public static <T> Optional<T> dateSearch(LocalDate startDate, BiFunction<LocalDate,Boolean,LocalDate> dateStepper, int maxSteps, Function<LocalDate,Optional<T>> function)
Utility method to search through the datastore for the "next" or "previous" date which contains the desired data.- Type Parameters:
T
- The type of the data record returned- Parameters:
startDate
- The initial as-of date; the next/previous date will be relative to this.dateStepper
- A function to step through the candidate dates. Given a date, it will return the next/previous date; the boolean parameter is true for the first step. For example see @see com.activeviam.risk.core.utils.MarketDataDates#stepDate(IActivePivot, IQueryCache, String, String, LocalDate, boolean))}.maxSteps
- The maximum number of iterations to step through datefunction
- Evaluation function, this returns the desired data, if available for the input date. For example a closure of see @see com.activeviam.risk.core.postprocessor.impl.AMarketDataPostProcessor#getMarketDataRecord(LocalDate, IMarketDataSet, String)} (with the market data set and risk factor provided).- Returns:
- The desired data, if found within maxSteps iterations.
-
getCalculationMethod
public static Object[] getCalculationMethod(org.springframework.core.env.Environment environment, String sensitivityName, String riskClass)
Return a calculation method found at the key formula.rule.[sensitivityName].[riskClass]- Parameters:
environment
- spring environmentsensitivityName
- The name or the kind of the sensi : inflation / ir-gamma / ... or delta / vega / gamma / ...riskClass
- The risk class of the sensi : FX / GIRR / ... or *- Returns:
- An object describing the formula
-
getCalculationMethod
public static Object[] getCalculationMethod(org.springframework.core.env.Environment environment, String sensitivityKind, String sensitivityName, String riskClass)
Return the calculation method found in the config file- Parameters:
environment
- Spring environmentsensitivityKind
- The king of the sensi : delta / vega / gamma / ...sensitivityName
- The name of the sensi : inflation / ir-gamma / ...riskClass
- The risk class of the sensi : FX / GIRR / ...- Returns:
- An object describing the formula
-
-