Beispiel #1
0
        static ForwardOvernightAveragedRateComputationFnTest()
        {
            LocalDateDoubleTimeSeriesBuilder builder = LocalDateDoubleTimeSeries.builder();

            for (int i = 0; i < FIXING_DATES.Length; i++)
            {
                builder.put(FIXING_DATES[i], FIXING_RATES[i]);
            }
            TIME_SERIES = builder.build();
        }
Beispiel #2
0
        //-------------------------------------------------------------------------
        // loads a single fixing series CSV file
        private static ImmutableMap <ObservableId, LocalDateDoubleTimeSeries> parseSingle(CharSource resource)
        {
            IDictionary <ObservableId, LocalDateDoubleTimeSeriesBuilder> builders = new Dictionary <ObservableId, LocalDateDoubleTimeSeriesBuilder>();

            try
            {
                CsvFile csv = CsvFile.of(resource, true);
                foreach (CsvRow row in csv.rows())
                {
                    string referenceStr = row.getField(REFERENCE_FIELD);
                    string dateStr      = row.getField(DATE_FIELD);
                    string valueStr     = row.getField(VALUE_FIELD);

                    Index        index = LoaderUtils.findIndex(referenceStr);
                    ObservableId id    = IndexQuoteId.of(index);
                    double       value = double.Parse(valueStr);
                    LocalDate    date;
                    if (index is PriceIndex)
                    {
                        try
                        {
                            YearMonth ym = LoaderUtils.parseYearMonth(dateStr);
                            date = ym.atEndOfMonth();
                        }
                        catch (Exception)
                        {
                            date = LoaderUtils.parseDate(dateStr);
                            if (date.DayOfMonth != date.lengthOfMonth())
                            {
                                throw new System.ArgumentException(Messages.format("Fixing Series CSV loader for price index must have date at end of month: {}", resource));
                            }
                        }
                    }
                    else
                    {
                        date = LoaderUtils.parseDate(dateStr);
                    }

                    LocalDateDoubleTimeSeriesBuilder builder = builders.computeIfAbsent(id, k => LocalDateDoubleTimeSeries.builder());
                    builder.put(date, value);
                }
            }
            catch (Exception ex)
            {
                throw new System.ArgumentException(Messages.format("Error processing resource as CSV file: {}", resource), ex);
            }
            return(MapStream.of(builders).mapValues(builder => builder.build()).toMap());
        }