private PortfolioItemInfo parseInfo(CsvRow row) { PortfolioItemInfo info = PortfolioItemInfo.empty(); String scheme = row.findValue(ID_SCHEME_HEADER).orElse(DEFAULT_SCHEME); StandardId id = row.findValue(ID_HEADER).map(str -> StandardId.of(scheme, str)).orElse(null); if (id != null) { info = info.withId(id); } return resolver.parseSensitivityInfo(row, info); }
/** * 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()); }
public void test_withers() { PortfolioItemInfo test = PortfolioItemInfo.empty() .withId(ID) .withAttribute(AttributeType.DESCRIPTION, "A"); assertEquals(test.getId(), Optional.of(ID)); assertEquals(test.getAttributeTypes(), ImmutableSet.of(AttributeType.DESCRIPTION)); assertEquals(test.getAttribute(AttributeType.DESCRIPTION), "A"); assertEquals(test.findAttribute(AttributeType.DESCRIPTION), Optional.of("A")); assertThrows(IllegalArgumentException.class, () -> test.getAttribute(AttributeType.NAME)); }
public void test_mergedWith_sens_mergeAndAdd() { CurveSensitivities base1 = sut(); CurveSensitivities base2 = sut2(); CurveSensitivities test = base1.mergedWith(base2); assertEquals(test.getInfo(), PortfolioItemInfo.empty() .withId(ID2) .withAttribute(NAME, "2") .withAttribute(DESCRIPTION, "1")); assertEquals(test.getTypedSensitivities().keySet(), ImmutableSet.of(ZERO_RATE_DELTA, ZERO_RATE_GAMMA)); assertEquals(test.getTypedSensitivities().get(ZERO_RATE_DELTA), SENSI1.multipliedBy(2)); assertEquals(test.getTypedSensitivities().get(ZERO_RATE_GAMMA), SENSI2); }