@Override public CurveSensitivities build() { return new CurveSensitivities( info, typedSensitivities); }
/** * Obtains an instance from a map of sensitivities. * * @param info the additional information * @param typedSensitivities the map of sensitivities by type * @return the sensitivities instance */ public static CurveSensitivities of( PortfolioItemInfo info, Map<CurveSensitivitiesType, CurrencyParameterSensitivities> typedSensitivities) { return new CurveSensitivities(info, ImmutableMap.copyOf(typedSensitivities)); }
/** * Obtains an instance from a single set of sensitivities. * * @param info the additional information * @param type the type of the sensitivities * @param sensitivities the sensitivities * @return the sensitivities instance */ public static CurveSensitivities of( PortfolioItemInfo info, CurveSensitivitiesType type, CurrencyParameterSensitivities sensitivities) { return new CurveSensitivities(info, ImmutableMap.of(type, sensitivities)); }
/** * Obtains an empty instance. * * @return the empty sensitivities instance */ public static CurveSensitivities empty() { return new CurveSensitivities(PortfolioItemInfo.empty(), ImmutableMap.of()); }
/** * Checks and adjusts the market data names. * <p> * The supplied function is invoked for each market data name in this sensitivities. * A typical use case would be to convert index names to curve names valid for an underlying system. * * @param nameFn the function for checking and adjusting the name * @return the adjusted sensitivity * @throws RuntimeException if the function throws an exception */ public CurveSensitivities withMarketDataNames(Function<MarketDataName<?>, MarketDataName<?>> nameFn) { return new CurveSensitivities( info, MapStream.of(typedSensitivities) .mapValues(sens -> sens.withMarketDataNames(nameFn)) .toMap()); }
/** * Checks and adjusts the parameter metadata. * <p> * The supplied function is invoked for each parameter metadata in this sensitivities. * If the function returns the same metadata for two different inputs, the sensitivity value will be summed. * A typical use case would be to normalize parameter metadata tenors to be valid for an underlying system. * * @param mdFn the function for checking and adjusting the metadata * @return the adjusted sensitivity * @throws RuntimeException if the function throws an exception */ public CurveSensitivities withParameterMetadatas(UnaryOperator<ParameterMetadata> mdFn) { return new CurveSensitivities( info, MapStream.of(typedSensitivities) .mapValues(sens -> sens.withParameterMetadatas(mdFn)) .toMap()); }
/** * Converts the sensitivities in this instance to an equivalent in the specified currency. * <p> * Any FX conversion that is required will use rates from the provider. * * @param resultCurrency the currency of the result * @param rateProvider the provider of FX rates * @return the sensitivity object expressed in terms of the result currency * @throws RuntimeException if no FX rate could be found */ @Override public CurveSensitivities convertedTo(Currency resultCurrency, FxRateProvider rateProvider) { return new CurveSensitivities( info, MapStream.of(typedSensitivities) .mapValues(v -> v.convertedTo(resultCurrency, rateProvider)) .toMap()); }
/** * Combines this set of sensitivities with another set. * <p> * This returns a new curve sensitivities with a combined map of typed sensitivities. * Any sensitivities of the same type will be combined as though using * {@link CurrencyParameterSensitivities#mergedWith(CurrencyParameterSensitivities)}. * The identifier and attributes of this instance will take precedence. * * @param other the other parameter sensitivities * @return an instance based on this one, with the other instance added */ @SuppressWarnings({"rawtypes", "unchecked"}) public CurveSensitivities mergedWith(CurveSensitivities other) { PortfolioItemInfo combinedInfo = info; if (!info.getId().isPresent() && other.info.getId().isPresent()) { combinedInfo = combinedInfo.withId(other.info.getId().get()); } for (AttributeType attrType : other.info.getAttributeTypes()) { if (!combinedInfo.getAttributeTypes().contains(attrType)) { combinedInfo = combinedInfo.withAttribute(attrType, other.info.getAttribute(attrType)); } } return new CurveSensitivities(combinedInfo, mergedWith(other.typedSensitivities).getTypedSensitivities()); }
/** * Merges this set of sensitivities with another set. * <p> * This returns a new curve sensitivities with a combined map of typed sensitivities. * Any sensitivities of the same type will be combined as though using * {@link CurrencyParameterSensitivities#mergedWith(CurrencyParameterSensitivities)}. * * @param other the other parameter sensitivities * @return an instance based on this one, with the other instance added */ public CurveSensitivities mergedWith(Map<CurveSensitivitiesType, CurrencyParameterSensitivities> other) { // this uses a collector to merge all the instances at once which is more efficient than reduction // because it creates a single CurrencyParameterSensitivitiesBuilder ImmutableMap<CurveSensitivitiesType, CurrencyParameterSensitivities> combinedSens = MapStream.concat(MapStream.of(typedSensitivities), MapStream.of(other)) .toMapGrouping(mergeSensitivities()); return new CurveSensitivities(info, combinedSens); }