示例#1
0
        //-------------------------------------------------------------------------
        // 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);
                }
            }
        }
        //-------------------------------------------------------------------------
        private void assertSens(CurveSensitivities sens, CurveSensitivitiesType type, string curveNameStr, Currency currency, string tenors, params double[] values)
        {
            CurveName curveName = CurveName.of(curveNameStr);
            CurrencyParameterSensitivity sensitivity = sens.getTypedSensitivity(type).getSensitivity(curveName, currency);

            assertEquals(sensitivity.MarketDataName, CurveName.of(curveNameStr));
            assertEquals(sensitivity.Currency, currency);
            assertEquals(metadataString(sensitivity.ParameterMetadata), tenors);
            assertEquals(sensitivity.Sensitivity, DoubleArray.ofUnsafe(values));
        }
示例#3
0
        //-------------------------------------------------------------------------
        // 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);
                }
            }
        }
        // writes the rows for a single CurrencyParameterSensitivity
        private void write(string reference, CurveSensitivitiesType type, CurveSensitivities curveSens, CurrencyParameterSensitivity paramSens, IList <string> additionalHeaders, bool containsDates, CsvOutput csv)
        {
            IList <string> additionalCells = supplier.values(additionalHeaders, curveSens, paramSens);

            for (int i = 0; i < paramSens.ParameterCount; i++)
            {
                ParameterMetadata pmd   = paramSens.getParameterMetadata(i);
                Tenor             tenor = ((TenoredParameterMetadata)pmd).Tenor;
                double            value = paramSens.Sensitivity.get(i);
                csv.writeCell(reference);
                csv.writeCell(type.Name);
                csv.writeCell(tenor.ToString());
                if (containsDates)
                {
                    csv.writeCell(pmd is DatedParameterMetadata ? ((DatedParameterMetadata)pmd).Date.ToString() : "");
                }
                csv.writeCell(paramSens.Currency.Code);
                csv.writeCell(decimal.valueOf(value).toPlainString());
                csv.writeLine(additionalCells);
            }
        }