/** * 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_parse_standard_full() { CharSource source = ResourceLocator.ofClasspath("com/opengamma/strata/loader/csv/sensitivity-standard-full.csv").getCharSource(); assertEquals(LOADER_CCP.isKnownFormat(source), true); ValueWithFailures<ListMultimap<String, CurveSensitivities>> test = LOADER_CCP.parse(ImmutableList.of(source)); assertEquals(test.getFailures().size(), 0, test.getFailures().toString()); assertEquals(test.getValue().size(), 2); List<CurveSensitivities> list0 = test.getValue().get("SCHEME~TR1"); assertEquals(list0.size(), 1); CurveSensitivities csens0 = list0.get(0); assertEquals(csens0.getInfo().getAttribute(CCP_ATTR), "LCH"); assertEquals(csens0.getTypedSensitivities().size(), 1); assertSens(csens0, ZERO_RATE_DELTA, "GBCURVE", GBP, "1M, 3M, 6M", 1, 2, 3); List<CurveSensitivities> list1 = test.getValue().get("OG-Sensitivity~TR2"); assertEquals(list1.size(), 1); CurveSensitivities csens1 = list1.get(0); assertEquals(csens1.getInfo().getAttribute(CCP_ATTR), "CME"); assertEquals(csens1.getTypedSensitivities().size(), 1); assertSens(csens1, ZERO_RATE_GAMMA, "GBCURVE", GBP, "1M, 3M, 6M", 4, 5, 6); }
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_parse_list_full() { CharSource source = ResourceLocator.ofClasspath("com/opengamma/strata/loader/csv/sensitivity-list-full.csv").getCharSource(); assertEquals(LOADER_CCP.isKnownFormat(source), true); ValueWithFailures<ListMultimap<String, CurveSensitivities>> test = LOADER_CCP.parse(ImmutableList.of(source)); assertEquals(test.getFailures().size(), 0, test.getFailures().toString()); assertEquals(test.getValue().size(), 2); List<CurveSensitivities> list0 = test.getValue().get("SCHEME~TR1"); assertEquals(list0.size(), 1); CurveSensitivities csens0 = list0.get(0); assertEquals(csens0.getInfo().getAttribute(CCP_ATTR), "LCH"); assertEquals(csens0.getTypedSensitivities().size(), 1); assertSens(csens0, ZERO_RATE_DELTA, "GBCURVE", GBP, "1M, 3M, 6M", 1, 2, 3); List<CurveSensitivities> list1 = test.getValue().get("OG-Sensitivity~TR2"); assertEquals(list1.size(), 1); CurveSensitivities csens1 = list1.get(0); assertEquals(csens1.getInfo().getAttribute(CCP_ATTR), "CME"); assertEquals(csens1.getTypedSensitivities().size(), 1); assertSens(csens1, ZERO_RATE_GAMMA, "GBCURVE", GBP, "1M, 3M, 6M", 4, 5, 6); }
public void test_parse_grid_full() { CharSource source = ResourceLocator.ofClasspath("com/opengamma/strata/loader/csv/sensitivity-grid-full.csv").getCharSource(); assertEquals(LOADER_CCP.isKnownFormat(source), true); ValueWithFailures<ListMultimap<String, CurveSensitivities>> test = LOADER_CCP.parse(ImmutableList.of(source)); assertEquals(test.getFailures().size(), 0, test.getFailures().toString()); List<CurveSensitivities> list0 = test.getValue().get("SCHEME~TR1"); assertEquals(list0.size(), 1); CurveSensitivities csens0 = list0.get(0); assertEquals(csens0.getId(), Optional.of(StandardId.of("SCHEME", "TR1"))); assertEquals(csens0.getInfo().getAttribute(CCP_ATTR), "LCH"); assertEquals(csens0.getTypedSensitivities().size(), 2); assertSens(csens0, ZERO_RATE_DELTA, "GBCURVE", GBP, "1M, 3M, 6M", 1, 2, 3); assertSens(csens0, ZERO_RATE_GAMMA, "GBCURVE", GBP, "1M, 3M, 6M", 4, 5, 6); List<CurveSensitivities> list1 = test.getValue().get("OG-Sensitivity~TR2"); assertEquals(list1.size(), 1); CurveSensitivities csens1 = list1.get(0); assertEquals(csens1.getId(), Optional.of(StandardId.of("OG-Sensitivity", "TR2"))); assertEquals(csens1.getInfo().getAttribute(CCP_ATTR), "CME"); assertEquals(csens1.getTypedSensitivities().size(), 1); assertSens(csens1, ZERO_RATE_DELTA, "GBCURVE", GBP, "1M, 3M, 6M", 7, 8, 9); }