// creates the tasks for a single target
        private static IList <CalculationTask> createTargetTasks <T1>(CalculationTarget resolvedTarget, int rowIndex, CalculationFunction <T1> function, IList <Column> columns)
        {
            // create the cells and group them
            ListMultimap <CalculationParameters, CalculationTaskCell> grouped = ArrayListMultimap.create();

            for (int colIndex = 0; colIndex < columns.Count; colIndex++)
            {
                Column  column  = columns[colIndex];
                Measure measure = column.Measure;

                ReportingCurrency   reportingCurrency = column.ReportingCurrency.orElse(ReportingCurrency.NATURAL);
                CalculationTaskCell cell = CalculationTaskCell.of(rowIndex, colIndex, measure, reportingCurrency);
                // group to find cells that can be shared, with same mappings and params (minus reporting currency)
                CalculationParameters @params = column.Parameters.filter(resolvedTarget, measure);
                grouped.put(@params, cell);
            }

            // build tasks
            ImmutableList.Builder <CalculationTask> taskBuilder = ImmutableList.builder();
            foreach (CalculationParameters @params in grouped.Keys)
            {
                taskBuilder.add(CalculationTask.of(resolvedTarget, function, @params, grouped.get(@params)));
            }
            return(taskBuilder.build());
        }
        // find all trade IDs by party herf id
        private ListMultimap <string, StandardId> parseAllTradeIds(XmlElement tradeHeaderEl)
        {
            // look through each partyTradeIdentifier
            ListMultimap <string, StandardId> allIds   = ArrayListMultimap.create();
            IList <XmlElement> partyTradeIdentifierEls = tradeHeaderEl.getChildren("partyTradeIdentifier");

            foreach (XmlElement partyTradeIdentifierEl in partyTradeIdentifierEls)
            {
                Optional <XmlElement> partyRefOptEl = partyTradeIdentifierEl.findChild("partyReference");
                if (partyRefOptEl.Present && partyRefOptEl.get().findAttribute(HREF).Present)
                {
                    string partyHref = partyRefOptEl.get().findAttribute(HREF).get();
                    // try to find a tradeId, either in versionedTradeId or as a direct child
                    Optional <XmlElement> vtradeIdOptEl = partyTradeIdentifierEl.findChild("versionedTradeId");
                    Optional <XmlElement> tradeIdOptEl  = vtradeIdOptEl.map(vt => vt.getChild("tradeId")).orElse(partyTradeIdentifierEl.findChild("tradeId"));
                    if (tradeIdOptEl.Present && tradeIdOptEl.get().findAttribute("tradeIdScheme").Present)
                    {
                        XmlElement tradeIdEl = tradeIdOptEl.get();
                        string     scheme    = tradeIdEl.getAttribute("tradeIdScheme");
                        // ignore if there is an empty scheme or value
                        if (scheme.Length > 0 && tradeIdEl.Content.Length > 0)
                        {
                            allIds.put(partyHref, StandardId.of(StandardId.encodeScheme(scheme), tradeIdEl.Content));
                        }
                    }
                }
            }
            return(allIds);
        }
Exemplo n.º 3
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);
                }
            }
        }
Exemplo n.º 4
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);
                }
            }
        }