private static IborIndex parseIborIndex(CsvRow row)
        {
            string            name      = row.getValue(NAME_FIELD);
            Currency          currency  = Currency.parse(row.getValue(CURRENCY_FIELD));
            bool              active    = bool.Parse(row.getValue(ACTIVE_FIELD));
            DayCount          dayCount  = DayCount.of(row.getValue(DAY_COUNT_FIELD));
            HolidayCalendarId fixingCal = HolidayCalendarId.of(row.getValue(FIXING_CALENDAR_FIELD));
            int offsetDays = int.Parse(row.getValue(OFFSET_DAYS_FIELD));
            HolidayCalendarId offsetCal        = HolidayCalendarId.of(row.getValue(OFFSET_CALENDAR_FIELD));
            HolidayCalendarId effectiveCal     = HolidayCalendarId.of(row.getValue(EFFECTIVE_DATE_CALENDAR_FIELD));
            Tenor             tenor            = Tenor.parse(row.getValue(TENOR_FIELD));
            LocalTime         time             = LocalTime.parse(row.getValue(FIXING_TIME_FIELD), TIME_FORMAT);
            ZoneId            zoneId           = ZoneId.of(row.getValue(FIXING_ZONE_FIELD));
            DayCount          fixedLegDayCount = DayCount.of(row.getValue(FIXED_LEG_DAY_COUNT));

            // interpret CSV
            DaysAdjustment fixingOffset    = DaysAdjustment.ofBusinessDays(-offsetDays, offsetCal, BusinessDayAdjustment.of(PRECEDING, fixingCal)).normalized();
            DaysAdjustment effectiveOffset = DaysAdjustment.ofBusinessDays(offsetDays, offsetCal, BusinessDayAdjustment.of(FOLLOWING, effectiveCal)).normalized();

            // convention can be two different things
            PeriodAdditionConvention periodAdditionConvention = PeriodAdditionConvention.extendedEnum().find(row.getField(TENOR_CONVENTION_FIELD)).orElse(PeriodAdditionConventions.NONE);
            BusinessDayConvention    tenorBusinessConvention  = BusinessDayConvention.extendedEnum().find(row.getField(TENOR_CONVENTION_FIELD)).orElse(isEndOfMonth(periodAdditionConvention) ? MODIFIED_FOLLOWING : FOLLOWING);
            BusinessDayAdjustment    adj             = BusinessDayAdjustment.of(tenorBusinessConvention, effectiveCal);
            TenorAdjustment          tenorAdjustment = TenorAdjustment.of(tenor, periodAdditionConvention, adj);

            // build result
            return(ImmutableIborIndex.builder().name(name).currency(currency).active(active).dayCount(dayCount).fixingCalendar(fixingCal).fixingDateOffset(fixingOffset).effectiveDateOffset(effectiveOffset).maturityDateOffset(tenorAdjustment).fixingTime(time).fixingZone(zoneId).defaultFixedLegDayCount(fixedLegDayCount).build());
        }
        // days adjustment, defaulting calendar and adjustment
        private static Optional <DaysAdjustment> parseDaysAdjustment(CsvRow row, string leg, string daysField, string daysCalField, string cnvField, string calField)
        {
            int?daysOpt = findValue(row, leg, daysField).map(s => Convert.ToInt32(s));
            HolidayCalendarId     cal = findValue(row, leg, daysCalField).map(s => HolidayCalendarId.of(s)).orElse(HolidayCalendarIds.NO_HOLIDAYS);
            BusinessDayAdjustment bda = parseBusinessDayAdjustment(row, leg, cnvField, calField).orElse(BusinessDayAdjustment.NONE);

            if (!daysOpt.HasValue)
            {
                return(null);
            }
            return(DaysAdjustment.builder().days(daysOpt.Value).calendar(cal).adjustment(bda).build());
        }
        private static FxIndex parseFxIndex(CsvRow row)
        {
            string            name            = row.getField(NAME_FIELD);
            Currency          baseCurrency    = Currency.parse(row.getField(BASE_CURRENCY_FIELD));
            Currency          counterCurrency = Currency.parse(row.getField(COUNTER_CURRENCY_FIELD));
            HolidayCalendarId fixingCal       = HolidayCalendarId.of(row.getField(FIXING_CALENDAR_FIELD));
            int maturityDays = int.Parse(row.getField(MATURITY_DAYS_FIELD));
            HolidayCalendarId maturityCal = HolidayCalendarId.of(row.getField(MATURITY_CALENDAR_FIELD));

            // build result
            return(ImmutableFxIndex.builder().name(name).currencyPair(CurrencyPair.of(baseCurrency, counterCurrency)).fixingCalendar(fixingCal).maturityDateOffset(DaysAdjustment.ofBusinessDays(maturityDays, maturityCal)).build());
        }
        // adjustable date, defaulting business day convention and holiday calendar
        private static Optional <AdjustableDate> parseAdjustableDate(CsvRow row, string leg, string dateField, string cnvField, string calField)
        {
            Optional <LocalDate> dateOpt = findValue(row, leg, dateField).map(s => LoaderUtils.parseDate(s));

            if (!dateOpt.Present)
            {
                return(null);
            }
            BusinessDayConvention dateCnv = findValue(row, leg, cnvField).map(s => LoaderUtils.parseBusinessDayConvention(s)).orElse(BusinessDayConventions.MODIFIED_FOLLOWING);
            HolidayCalendarId     cal     = findValue(row, leg, calField).map(s => HolidayCalendarId.of(s)).orElse(HolidayCalendarIds.NO_HOLIDAYS);

            return(AdjustableDate.of(dateOpt.get(), BusinessDayAdjustment.of(dateCnv, cal)));
        }
示例#5
0
        private static OvernightIndex parseOvernightIndex(CsvRow row)
        {
            string            name      = row.getValue(NAME_FIELD);
            Currency          currency  = Currency.parse(row.getValue(CURRENCY_FIELD));
            bool              active    = bool.Parse(row.getValue(ACTIVE_FIELD));
            DayCount          dayCount  = DayCount.of(row.getValue(DAY_COUNT_FIELD));
            HolidayCalendarId fixingCal = HolidayCalendarId.of(row.getValue(FIXING_CALENDAR_FIELD));
            int      publicationDays    = int.Parse(row.getValue(PUBLICATION_DAYS_FIELD));
            int      effectiveDays      = int.Parse(row.getValue(EFFECTIVE_DAYS_FIELD));
            DayCount fixedLegDayCount   = DayCount.of(row.getValue(FIXED_LEG_DAY_COUNT));

            // build result
            return(ImmutableOvernightIndex.builder().name(name).currency(currency).active(active).dayCount(dayCount).fixingCalendar(fixingCal).publicationDateOffset(publicationDays).effectiveDateOffset(effectiveDays).defaultFixedLegDayCount(fixedLegDayCount).build());
        }
        //-------------------------------------------------------------------------
        // days adjustment, defaulting business day convention
        private static Optional <BusinessDayAdjustment> parseBusinessDayAdjustment(CsvRow row, string leg, string cnvField, string calField)
        {
            BusinessDayConvention dateCnv = findValue(row, leg, cnvField).map(s => LoaderUtils.parseBusinessDayConvention(s)).orElse(BusinessDayConventions.MODIFIED_FOLLOWING);

            return(findValue(row, leg, calField).map(s => HolidayCalendarId.of(s)).map(cal => BusinessDayAdjustment.of(dateCnv, cal)));
        }
 /// <summary>
 /// Converts an FpML business center string to a {@code HolidayCalendar}.
 /// </summary>
 /// <param name="fpmlBusinessCenter">  the business center name used by FpML </param>
 /// <returns> the holiday calendar </returns>
 /// <exception cref="IllegalArgumentException"> if the holiday calendar is not known </exception>
 public HolidayCalendarId convertHolidayCalendar(string fpmlBusinessCenter)
 {
     return(HolidayCalendarId.of(fpmlBusinessCenter));
 }
        // parse a trade based on a convention
        internal static SwapTrade parseWithConvention(CsvRow row, TradeInfo info, TradeCsvInfoResolver resolver, string conventionStr)
        {
            BuySell                      buySell              = LoaderUtils.parseBuySell(row.getValue(BUY_SELL_FIELD));
            double                       notional             = LoaderUtils.parseDouble(row.getValue(NOTIONAL_FIELD));
            double                       fixedRate            = LoaderUtils.parseDoublePercent(row.getValue(FIXED_RATE_FIELD));
            Optional <Period>            periodToStartOpt     = row.findValue(PERIOD_TO_START_FIELD).map(s => LoaderUtils.parsePeriod(s));
            Optional <Tenor>             tenorOpt             = row.findValue(TENOR_FIELD).map(s => LoaderUtils.parseTenor(s));
            Optional <LocalDate>         startDateOpt         = row.findValue(START_DATE_FIELD).map(s => LoaderUtils.parseDate(s));
            Optional <LocalDate>         endDateOpt           = row.findValue(END_DATE_FIELD).map(s => LoaderUtils.parseDate(s));
            Optional <RollConvention>    rollCnvOpt           = row.findValue(ROLL_CONVENTION_FIELD).map(s => LoaderUtils.parseRollConvention(s));
            Optional <StubConvention>    stubCnvOpt           = row.findValue(STUB_CONVENTION_FIELD).map(s => StubConvention.of(s));
            Optional <LocalDate>         firstRegStartDateOpt = row.findValue(FIRST_REGULAR_START_DATE_FIELD).map(s => LoaderUtils.parseDate(s));
            Optional <LocalDate>         lastRegEndDateOpt    = row.findValue(LAST_REGULAR_END_DATE_FIELD).map(s => LoaderUtils.parseDate(s));
            BusinessDayConvention        dateCnv              = row.findValue(DATE_ADJ_CNV_FIELD).map(s => LoaderUtils.parseBusinessDayConvention(s)).orElse(BusinessDayConventions.MODIFIED_FOLLOWING);
            Optional <HolidayCalendarId> dateCalOpt           = row.findValue(DATE_ADJ_CAL_FIELD).map(s => HolidayCalendarId.of(s));
            double?                      fxRateOpt            = row.findValue(FX_RATE_FIELD).map(str => LoaderUtils.parseDouble(str));

            // explicit dates take precedence over relative ones
            if (startDateOpt.Present && endDateOpt.Present)
            {
                if (periodToStartOpt.Present || tenorOpt.Present)
                {
                    throw new System.ArgumentException("Swap trade had invalid combination of fields. When these fields are found " + ImmutableList.of(CONVENTION_FIELD, START_DATE_FIELD, END_DATE_FIELD) + " then these fields must not be present " + ImmutableList.of(PERIOD_TO_START_FIELD, TENOR_FIELD));
                }
                LocalDate startDate = startDateOpt.get();
                LocalDate endDate   = endDateOpt.get();
                SwapTrade trade     = createSwap(info, conventionStr, startDate, endDate, buySell, notional, fixedRate, fxRateOpt);
                return(adjustTrade(trade, rollCnvOpt, stubCnvOpt, firstRegStartDateOpt, lastRegEndDateOpt, dateCnv, dateCalOpt));
            }

            // start date + tenor
            if (startDateOpt.Present && tenorOpt.Present)
            {
                if (periodToStartOpt.Present || endDateOpt.Present)
                {
                    throw new System.ArgumentException("Swap trade had invalid combination of fields. When these fields are found " + ImmutableList.of(CONVENTION_FIELD, START_DATE_FIELD, TENOR_FIELD) + " then these fields must not be present " + ImmutableList.of(PERIOD_TO_START_FIELD, END_DATE_FIELD));
                }
                LocalDate startDate = startDateOpt.get();
                Tenor     tenor     = tenorOpt.get();
                LocalDate endDate   = startDate.plus(tenor);
                SwapTrade trade     = createSwap(info, conventionStr, startDate, endDate, buySell, notional, fixedRate, fxRateOpt);
                return(adjustTrade(trade, rollCnvOpt, stubCnvOpt, firstRegStartDateOpt, lastRegEndDateOpt, dateCnv, dateCalOpt));
            }

            // relative dates
            if (periodToStartOpt.Present && tenorOpt.Present && info.TradeDate.Present)
            {
                if (startDateOpt.Present || endDateOpt.Present)
                {
                    throw new System.ArgumentException("Swap trade had invalid combination of fields. When these fields are found " + ImmutableList.of(CONVENTION_FIELD, PERIOD_TO_START_FIELD, TENOR_FIELD, TRADE_DATE_FIELD) + " then these fields must not be present " + ImmutableList.of(START_DATE_FIELD, END_DATE_FIELD));
                }
                LocalDate tradeDate     = info.TradeDate.get();
                Period    periodToStart = periodToStartOpt.get();
                Tenor     tenor         = tenorOpt.get();
                if (fxRateOpt.HasValue)
                {
                    XCcyIborIborSwapConvention convention = XCcyIborIborSwapConvention.of(conventionStr);
                    double    notionalFlat = notional * fxRateOpt.Value;
                    SwapTrade trade        = convention.createTrade(tradeDate, periodToStart, tenor, buySell, notional, notionalFlat, fixedRate, resolver.ReferenceData);
                    trade = trade.toBuilder().info(info).build();
                    return(adjustTrade(trade, rollCnvOpt, stubCnvOpt, firstRegStartDateOpt, lastRegEndDateOpt, dateCnv, dateCalOpt));
                }
                else
                {
                    SingleCurrencySwapConvention convention = SingleCurrencySwapConvention.of(conventionStr);
                    SwapTrade trade = convention.createTrade(tradeDate, periodToStart, tenor, buySell, notional, fixedRate, resolver.ReferenceData);
                    trade = trade.toBuilder().info(info).build();
                    return(adjustTrade(trade, rollCnvOpt, stubCnvOpt, firstRegStartDateOpt, lastRegEndDateOpt, dateCnv, dateCalOpt));
                }
            }

            // no match
            throw new System.ArgumentException("Swap trade had invalid combination of fields. These fields are mandatory:" + ImmutableList.of(BUY_SELL_FIELD, NOTIONAL_FIELD, FIXED_RATE_FIELD) + " and one of these combinations is mandatory: " + ImmutableList.of(CONVENTION_FIELD, TRADE_DATE_FIELD, PERIOD_TO_START_FIELD, TENOR_FIELD) + " or " + ImmutableList.of(CONVENTION_FIELD, START_DATE_FIELD, TENOR_FIELD) + " or " + ImmutableList.of(CONVENTION_FIELD, START_DATE_FIELD, END_DATE_FIELD));
        }