@Override public PortfolioItemInfo parseSensitivityInfo(CsvRow row, PortfolioItemInfo info) { return info.withAttribute(CCP_ATTR, row.getValue("CCP")); }
/** * 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_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); }
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_write_standard() { CurveName curve1 = CurveName.of("GBDSC"); CurveName curve2 = CurveName.of("GBFWD"); // listed in reverse order to check ordering CurveSensitivities sens = CurveSensitivities.builder(PortfolioItemInfo.empty().withAttribute(CCP_ATTR, "LCH")) .add(ZERO_RATE_GAMMA, curve2, Currency.GBP, TenorParameterMetadata.of(Tenor.TENOR_3M), 1) .add(ZERO_RATE_GAMMA, curve2, Currency.GBP, TenorParameterMetadata.of(Tenor.TENOR_6M), 2) .add(ZERO_RATE_DELTA, curve2, Currency.GBP, TenorParameterMetadata.of(Tenor.TENOR_3M), 3) .add(ZERO_RATE_DELTA, curve2, Currency.GBP, TenorParameterMetadata.of(Tenor.TENOR_6M), 5) .add(ZERO_RATE_DELTA, curve1, Currency.GBP, TenorParameterMetadata.of(Tenor.TENOR_3M), 2) .add(ZERO_RATE_DELTA, curve1, Currency.GBP, TenorParameterMetadata.of(Tenor.TENOR_6M), 4) .build(); StringBuffer buf = new StringBuffer(); WRITER_CCP.write(sens, buf); String content = buf.toString(); String expected = "" + "Reference,Sensitivity Type,Sensitivity Tenor,Currency,Value,CCP\n" + "GBDSC,ZeroRateDelta,3M,GBP,2.0,LCH\n" + "GBDSC,ZeroRateDelta,6M,GBP,4.0,LCH\n" + "GBFWD,ZeroRateDelta,3M,GBP,3.0,LCH\n" + "GBFWD,ZeroRateDelta,6M,GBP,5.0,LCH\n" + "GBFWD,ZeroRateGamma,3M,GBP,1.0,LCH\n" + "GBFWD,ZeroRateGamma,6M,GBP,2.0,LCH\n"; assertEquals(content, expected); }
public void test_write_standard_withDate() { CurveName curve1 = CurveName.of("GBDSC"); CurveName curve2 = CurveName.of("GBFWD"); // listed in reverse order to check ordering CurveSensitivities sens = CurveSensitivities.builder(PortfolioItemInfo.empty().withAttribute(CCP_ATTR, "LCH")) .add(ZERO_RATE_GAMMA, curve2, Currency.GBP, TenorParameterMetadata.of(Tenor.TENOR_3M), 1) .add(ZERO_RATE_GAMMA, curve2, Currency.GBP, TenorParameterMetadata.of(Tenor.TENOR_6M), 2) .add(ZERO_RATE_DELTA, curve2, Currency.GBP, TenorParameterMetadata.of(Tenor.TENOR_3M), 3) .add(ZERO_RATE_DELTA, curve2, Currency.GBP, TenorParameterMetadata.of(Tenor.TENOR_6M), 5) .add(ZERO_RATE_DELTA, curve1, Currency.GBP, TenorDateParameterMetadata.of(date(2018, 6, 30), Tenor.TENOR_3M), 2) .add(ZERO_RATE_DELTA, curve1, Currency.GBP, TenorParameterMetadata.of(Tenor.TENOR_6M), 4) .build(); StringBuffer buf = new StringBuffer(); WRITER_CCP.write(sens, buf); String content = buf.toString(); String expected = "" + "Reference,Sensitivity Type,Sensitivity Tenor,Sensitivity Date,Currency,Value,CCP\n" + "GBDSC,ZeroRateDelta,3M,2018-06-30,GBP,2.0,LCH\n" + "GBDSC,ZeroRateDelta,6M,,GBP,4.0,LCH\n" + "GBFWD,ZeroRateDelta,3M,,GBP,3.0,LCH\n" + "GBFWD,ZeroRateDelta,6M,,GBP,5.0,LCH\n" + "GBFWD,ZeroRateGamma,3M,,GBP,1.0,LCH\n" + "GBFWD,ZeroRateGamma,6M,,GBP,2.0,LCH\n"; assertEquals(content, expected); }