//------------------------------------------------------------------------- // parses the file in grid format private void parseGridFormat(CsvIterator csv, ListMultimap <string, CurveSensitivities> parsed, IList <FailureItem> failures) { // find the applicable reference columns IDictionary <string, CurveName> references = new LinkedHashMap <string, CurveName>(); foreach (string header in csv.headers()) { string headerLowerCase = header.ToLower(Locale.ENGLISH); if (!REF_HEADERS.contains(headerLowerCase) && !resolver.isInfoColumn(headerLowerCase)) { references[header] = CurveName.of(header); } } // loop around all rows, peeking to match batches with the same identifier // no exception catch at this level to avoid infinite loops while (csv.hasNext()) { CsvRow peekedRow = csv.peek(); PortfolioItemInfo info = parseInfo(peekedRow); //JAVA TO C# CONVERTER TODO TASK: Method reference arbitrary object instance method syntax is not converted by Java to C# Converter: string id = info.Id.map(StandardId::toString).orElse(""); // process in batches, where the ID is the same CurveSensitivitiesBuilder builder = CurveSensitivities.builder(info); IList <CsvRow> batchRows = csv.nextBatch(r => matchId(r, id)); foreach (CsvRow batchRow in batchRows) { try { ParameterMetadata metadata = parseMetadata(batchRow, true); CurveSensitivitiesType type = batchRow.findValue(TYPE_HEADER).map(str => CurveSensitivitiesType.of(str)).orElse(CurveSensitivitiesType.ZERO_RATE_DELTA); foreach (KeyValuePair <string, CurveName> entry in references.SetOfKeyValuePairs()) { CurveName reference = entry.Value; CurveName resolvedCurveName = resolver.checkCurveName(reference); string valueStr = batchRow.getField(entry.Key); Currency currency = parseCurrency(batchRow, reference); if (valueStr.Length > 0) { double value = LoaderUtils.parseDouble(valueStr); builder.add(type, resolvedCurveName, currency, metadata, value); } } } catch (System.ArgumentException ex) { failures.Add(FailureItem.of(PARSING, "CSV file could not be parsed at line {}: {}", batchRow.lineNumber(), ex.Message)); } } CurveSensitivities sens = builder.build(); if (!sens.TypedSensitivities.Empty) { parsed.put(sens.Id.map(object.toString).orElse(""), sens); } } }
//------------------------------------------------------------------------- // parses the file in standard format private void parseStandardFormat(CsvIterator csv, ListMultimap <string, CurveSensitivities> parsed, IList <FailureItem> failures) { // loop around all rows, peeking to match batches with the same identifier // no exception catch at this level to avoid infinite loops while (csv.hasNext()) { CsvRow peekedRow = csv.peek(); PortfolioItemInfo info = parseInfo(peekedRow); //JAVA TO C# CONVERTER TODO TASK: Method reference arbitrary object instance method syntax is not converted by Java to C# Converter: string id = info.Id.map(StandardId::toString).orElse(""); // process in batches, where the ID is the same CurveSensitivitiesBuilder builder = CurveSensitivities.builder(info); IList <CsvRow> batchRows = csv.nextBatch(r => matchId(r, id)); foreach (CsvRow batchRow in batchRows) { try { CurveName reference = CurveName.of(batchRow.getValue(REFERENCE_HEADER)); CurveName resolvedCurveName = resolver.checkCurveName(reference); CurveSensitivitiesType type = CurveSensitivitiesType.of(batchRow.getValue(TYPE_HEADER)); ParameterMetadata metadata = parseMetadata(batchRow, false); Currency currency = parseCurrency(batchRow, reference); string valueStr = batchRow.getField(VALUE_HEADER); if (valueStr.Length > 0) { double value = LoaderUtils.parseDouble(valueStr); builder.add(type, resolvedCurveName, currency, metadata, value); } } catch (System.ArgumentException ex) { failures.Add(FailureItem.of(PARSING, "CSV file could not be parsed at line {}: {}", batchRow.lineNumber(), ex.Message)); } } CurveSensitivities sens = builder.build(); if (!sens.TypedSensitivities.Empty) { parsed.put(sens.Id.map(object.toString).orElse(""), sens); } } }
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(); StringBuilder buf = new StringBuilder(); 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); }