Esempio n. 1
0
        //-------------------------------------------------------------------------
        // build conventions
        private static OvernightIborSwapConvention makeConvention(string name, OvernightIndex onIndex, IborIndex iborIndex, DayCount dayCount, Frequency frequency, int paymentLag, int cutOffDays, OvernightAccrualMethod accrual)
        {
            HolidayCalendarId calendarOn        = onIndex.FixingCalendar;
            DaysAdjustment    paymentDateOffset = DaysAdjustment.ofBusinessDays(paymentLag, calendarOn);

            return(ImmutableOvernightIborSwapConvention.of(name, OvernightRateSwapLegConvention.builder().index(onIndex).accrualMethod(accrual).accrualFrequency(frequency).paymentFrequency(frequency).paymentDateOffset(paymentDateOffset).stubConvention(StubConvention.SMART_INITIAL).rateCutOffDays(cutOffDays).build(), IborRateSwapLegConvention.of(iborIndex)));
        }
Esempio n. 2
0
        //-------------------------------------------------------------------------
        // build conventions
        private static FixedOvernightSwapConvention makeConvention(string name, OvernightIndex index, DayCount dayCount, Frequency frequency, int paymentLag, int spotLag)
        {
            HolidayCalendarId calendar          = index.FixingCalendar;
            DaysAdjustment    paymentDateOffset = DaysAdjustment.ofBusinessDays(paymentLag, calendar);
            DaysAdjustment    spotDateOffset    = DaysAdjustment.ofBusinessDays(spotLag, calendar);

            return(ImmutableFixedOvernightSwapConvention.of(name, FixedRateSwapLegConvention.builder().currency(index.Currency).dayCount(dayCount).accrualFrequency(frequency).accrualBusinessDayAdjustment(BusinessDayAdjustment.of(MODIFIED_FOLLOWING, calendar)).paymentFrequency(frequency).paymentDateOffset(paymentDateOffset).stubConvention(StubConvention.SMART_INITIAL).build(), OvernightRateSwapLegConvention.builder().index(index).accrualMethod(COMPOUNDED).accrualFrequency(frequency).paymentFrequency(frequency).paymentDateOffset(paymentDateOffset).stubConvention(StubConvention.SMART_INITIAL).build(), spotDateOffset));
        }
Esempio n. 3
0
        public virtual void test_nzdOis()
        {
            OvernightIndex test = OvernightIndex.of("NZD-NZIONA");

            assertEquals(test.Name, "NZD-NZIONA");
            assertEquals(test.Currency, NZD);
            assertEquals(test.Active, true);
            assertEquals(test.FixingCalendar, HolidayCalendarId.of("NZBD"));
            assertEquals(test.PublicationDateOffset, 0);
            assertEquals(test.EffectiveDateOffset, 0);
            assertEquals(test.DayCount, ACT_365F);
            assertEquals(test.DefaultFixedLegDayCount, ACT_365F);
            assertEquals(test.ToString(), "NZD-NZIONA");
        }
Esempio n. 4
0
        public virtual void test_inrOis()
        {
            OvernightIndex test = OvernightIndex.of("INR-OMIBOR");

            assertEquals(test.Name, "INR-OMIBOR");
            assertEquals(test.Currency, INR);
            assertEquals(test.Active, true);
            assertEquals(test.FixingCalendar, HolidayCalendarId.of("INMU"));
            assertEquals(test.PublicationDateOffset, 0);
            assertEquals(test.EffectiveDateOffset, 0);
            assertEquals(test.DayCount, ACT_365F);
            assertEquals(test.DefaultFixedLegDayCount, ACT_365F);
            assertEquals(test.ToString(), "INR-OMIBOR");
        }
Esempio n. 5
0
        public virtual void test_sgdSonar()
        {
            HolidayCalendarId SGSI = HolidayCalendarId.of("SGSI");
            OvernightIndex    test = OvernightIndex.of("SGD-SONAR");

            assertEquals(test.Name, "SGD-SONAR");
            assertEquals(test.Currency, SGD);
            assertEquals(test.Active, true);
            assertEquals(test.FixingCalendar, SGSI);
            assertEquals(test.PublicationDateOffset, 0);
            assertEquals(test.EffectiveDateOffset, 0);
            assertEquals(test.DayCount, ACT_365F);
            assertEquals(test.DefaultFixedLegDayCount, ACT_365F);
            assertEquals(test.ToString(), "SGD-SONAR");
        }
Esempio n. 6
0
        public virtual void test_sgd_sibor()
        {
            HolidayCalendarId SGSI = HolidayCalendarId.of("SGSI");
            IborIndex         test = IborIndex.of("SGD-SIBOR-3M");

            assertEquals(test.Currency, SGD);
            assertEquals(test.Name, "SGD-SIBOR-3M");
            assertEquals(test.Tenor, TENOR_3M);
            assertEquals(test.FixingCalendar, SGSI);
            assertEquals(test.FixingDateOffset, DaysAdjustment.ofBusinessDays(-2, SGSI));
            assertEquals(test.EffectiveDateOffset, DaysAdjustment.ofBusinessDays(2, SGSI));
            assertEquals(test.MaturityDateOffset, TenorAdjustment.of(TENOR_3M, PeriodAdditionConventions.NONE, BusinessDayAdjustment.of(MODIFIED_FOLLOWING, SGSI)));
            assertEquals(test.DayCount, ACT_365F);
            assertEquals(test.DefaultFixedLegDayCount, ACT_365F);
            assertEquals(test.ToString(), "SGD-SIBOR-3M");
        }
Esempio n. 7
0
        public virtual void test_krw_cd()
        {
            HolidayCalendarId KRSE = HolidayCalendarId.of("KRSE");
            IborIndex         test = IborIndex.of("KRW-CD-13W");

            assertEquals(test.Currency, KRW);
            assertEquals(test.Name, "KRW-CD-13W");
            assertEquals(test.Tenor, TENOR_13W);
            assertEquals(test.FixingCalendar, KRSE);
            assertEquals(test.FixingDateOffset, DaysAdjustment.ofBusinessDays(-1, KRSE));
            assertEquals(test.EffectiveDateOffset, DaysAdjustment.ofBusinessDays(1, KRSE));
            assertEquals(test.MaturityDateOffset, TenorAdjustment.of(TENOR_13W, PeriodAdditionConventions.NONE, BusinessDayAdjustment.of(FOLLOWING, KRSE)));
            assertEquals(test.DayCount, ACT_365F);
            assertEquals(test.DefaultFixedLegDayCount, ACT_365F);
            assertEquals(test.ToString(), "KRW-CD-13W");

            IborIndex test2 = IborIndex.of("KRW-CD-3M");

            assertEquals(test2.Name, "KRW-CD-13W");
        }
Esempio n. 8
0
        private Trade parseNdf(FpmlDocument document, XmlElement fxEl, XmlElement ndfEl, CurrencyAmount curr1Amount, CurrencyAmount curr2Amount, LocalDate valueDate, TradeInfoBuilder tradeInfoBuilder)
        {
            // rate
            XmlElement rateEl = fxEl.getChild("exchangeRate");
            double     rate   = document.parseDecimal(rateEl.getChild("rate"));
            XmlElement pairEl = rateEl.getChild("quotedCurrencyPair");
            Currency   curr1  = document.parseCurrency(pairEl.getChild("currency1"));
            Currency   curr2  = document.parseCurrency(pairEl.getChild("currency2"));
            string     basis  = pairEl.getChild("quoteBasis").Content;
            FxRate     fxRate;

            if ("Currency2PerCurrency1".Equals(basis))
            {
                fxRate = FxRate.of(curr1, curr2, rate);
            }
            else if ("Currency1PerCurrency2".Equals(basis))
            {
                fxRate = FxRate.of(curr2, curr1, rate);
            }
            else
            {
                throw new FpmlParseException("Unknown quote basis: " + basis);
            }
            // settlement currency
            Currency       settleCurr       = document.parseCurrency(ndfEl.getChild("settlementCurrency"));
            CurrencyAmount settleCurrAmount = curr1Amount.Currency.Equals(settleCurr) ? curr1Amount : curr2Amount;
            // index
            XmlElement        fixingEl        = ndfEl.getChild("fixing"); // only support one of these in pricing model
            LocalDate         fixingDate      = document.parseDate(fixingEl.getChild("fixingDate"));
            DaysAdjustment    offset          = DaysAdjustment.ofCalendarDays(Math.toIntExact(valueDate.until(fixingDate, DAYS)));
            XmlElement        sourceEl        = fixingEl.getChild("fxSpotRateSource"); // required for our model
            XmlElement        primarySourceEl = sourceEl.getChild("primaryRateSource");
            string            primarySource   = primarySourceEl.getChild("rateSource").Content;
            string            primaryPage     = primarySourceEl.findChild("rateSourcePage").map(e => e.Content).orElse("");
            LocalTime         time            = document.parseTime(sourceEl.getChild("fixingTime").getChild("hourMinuteTime")); // required for our model
            HolidayCalendarId calendar        = document.parseBusinessCenter(sourceEl.getChild("fixingTime").getChild("businessCenter"));
            FxIndex           index           = ImmutableFxIndex.builder().name(primarySource + "/" + primaryPage + "/" + time).currencyPair(CurrencyPair.of(curr1, curr2)).fixingCalendar(calendar).maturityDateOffset(offset).build();

            return(FxNdfTrade.builder().info(tradeInfoBuilder.build()).product(FxNdf.builder().settlementCurrencyNotional(settleCurrAmount).agreedFxRate(fxRate).index(index).paymentDate(valueDate).build()).build());
        }
 // Create a zero-coupon fixed leg convention
 private static FixedRateSwapLegConvention fixedLegZcConvention(Currency ccy, HolidayCalendarId cal)
 {
     return(FixedRateSwapLegConvention.builder().paymentFrequency(Frequency.TERM).accrualFrequency(Frequency.P12M).accrualBusinessDayAdjustment(BusinessDayAdjustment.of(MODIFIED_FOLLOWING, cal)).startDateBusinessDayAdjustment(BusinessDayAdjustment.of(MODIFIED_FOLLOWING, cal)).endDateBusinessDayAdjustment(BusinessDayAdjustment.of(MODIFIED_FOLLOWING, cal)).compoundingMethod(CompoundingMethod.STRAIGHT).dayCount(ONE_ONE).currency(ccy).build());
 }
        // parses the payment date adjustment, which consists of two linked optional fields
        internal static Optional <BusinessDayAdjustment> parsePaymentDateAdjustment(CsvRow row)
        {
            Optional <BusinessDayAdjustment> paymentAdj = null;
            Optional <string> paymentDateCnv            = row.findValue(PAYMENT_DATE_CNV_FIELD); // Optional field with Business day adjustment

            if (paymentDateCnv.Present)
            {
                BusinessDayConvention bdCnv = LoaderUtils.parseBusinessDayConvention(paymentDateCnv.get());
                if (!bdCnv.Equals(BusinessDayConventions.NO_ADJUST))
                {
                    Optional <string> paymentDateCalOpt = row.findValue(PAYMENT_DATE_CAL_FIELD);
                    if (paymentDateCalOpt.Present)
                    {
                        paymentAdj = BusinessDayAdjustment.of(LoaderUtils.parseBusinessDayConvention(paymentDateCnv.get()), HolidayCalendarId.of(paymentDateCalOpt.get()));
                    }
                }
            }
            return(paymentAdj);
        }
        // parse the row to a trade
        private static TermDepositTrade parseRow(CsvRow row, TradeInfo info, TradeCsvInfoResolver resolver)
        {
            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 <TermDepositConvention> conventionOpt = row.findValue(CONVENTION_FIELD).map(s => TermDepositConvention.of(s));
            Optional <Period>            tenorOpt          = row.findValue(TENOR_FIELD).map(s => LoaderUtils.parseTenor(s).Period);
            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 <Currency>          currencyOpt       = row.findValue(CURRENCY_FIELD).map(s => Currency.parse(s));
            Optional <DayCount>          dayCountOpt       = row.findValue(DAY_COUNT_FIELD).map(s => LoaderUtils.parseDayCount(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));

            // use convention if available
            if (conventionOpt.Present)
            {
                if (currencyOpt.Present || dayCountOpt.Present)
                {
                    throw new System.ArgumentException("TermDeposit trade had invalid combination of fields. When '" + CONVENTION_FIELD + "' is present these fields must not be present: " + ImmutableList.of(CURRENCY_FIELD, DAY_COUNT_FIELD));
                }
                TermDepositConvention convention = conventionOpt.get();
                // explicit dates take precedence over relative ones
                if (startDateOpt.Present && endDateOpt.Present)
                {
                    if (tenorOpt.Present)
                    {
                        throw new System.ArgumentException("TermDeposit 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(TENOR_FIELD));
                    }
                    LocalDate        startDate = startDateOpt.get();
                    LocalDate        endDate   = endDateOpt.get();
                    TermDepositTrade trade     = convention.toTrade(info, startDate, endDate, buySell, notional, fixedRate);
                    return(adjustTrade(trade, dateCnv, dateCalOpt));
                }
                // relative dates
                if (tenorOpt.Present && info.TradeDate.Present)
                {
                    if (startDateOpt.Present || endDateOpt.Present)
                    {
                        throw new System.ArgumentException("TermDeposit trade had invalid combination of fields. When these fields are found " + ImmutableList.of(CONVENTION_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 = tenorOpt.get();
                    TermDepositTrade trade         = convention.createTrade(tradeDate, periodToStart, buySell, notional, fixedRate, resolver.ReferenceData);
                    trade = trade.toBuilder().info(info).build();
                    return(adjustTrade(trade, dateCnv, dateCalOpt));
                }
            }
            else if (startDateOpt.Present && endDateOpt.Present && currencyOpt.Present && dayCountOpt.Present)
            {
                LocalDate           startDate = startDateOpt.get();
                LocalDate           endDate   = endDateOpt.get();
                Currency            currency  = currencyOpt.get();
                DayCount            dayCount  = dayCountOpt.get();
                TermDeposit.Builder builder   = TermDeposit.builder().buySell(buySell).currency(currency).notional(notional).startDate(startDate).endDate(endDate).dayCount(dayCount).rate(fixedRate);
                TermDepositTrade    trade     = TermDepositTrade.of(info, builder.build());
                return(adjustTrade(trade, dateCnv, dateCalOpt));
            }
            // no match
            throw new System.ArgumentException("TermDeposit 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, TENOR_FIELD) + " or " + ImmutableList.of(CONVENTION_FIELD, START_DATE_FIELD, END_DATE_FIELD) + " or " + ImmutableList.of(START_DATE_FIELD, END_DATE_FIELD, CURRENCY_FIELD, DAY_COUNT_FIELD));
        }
Esempio n. 12
0
        // parse the row to a trade
        private static FraTrade parseRow(CsvRow row, TradeInfo info, TradeCsvInfoResolver resolver)
        {
            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 <FraConvention>     conventionOpt    = row.findValue(CONVENTION_FIELD).map(s => FraConvention.of(s));
            Optional <Period>            periodToStartOpt = row.findValue(PERIOD_TO_START_FIELD).map(s => LoaderUtils.parsePeriod(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 <IborIndex>         indexOpt         = row.findValue(INDEX_FIELD).map(s => IborIndex.of(s));
            Optional <IborIndex>         interpolatedOpt  = row.findValue(INTERPOLATED_INDEX_FIELD).map(s => IborIndex.of(s));
            Optional <DayCount>          dayCountOpt      = row.findValue(DAY_COUNT_FIELD).map(s => LoaderUtils.parseDayCount(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));

            // not parsing paymentDate, fixingDateOffset, discounting

            // use convention if available
            if (conventionOpt.Present)
            {
                if (indexOpt.Present || interpolatedOpt.Present || dayCountOpt.Present)
                {
                    throw new System.ArgumentException("Fra trade had invalid combination of fields. When '" + CONVENTION_FIELD + "' is present these fields must not be present: " + ImmutableList.of(INDEX_FIELD, INTERPOLATED_INDEX_FIELD, DAY_COUNT_FIELD));
                }
                FraConvention convention = conventionOpt.get();
                // explicit dates take precedence over relative ones
                if (startDateOpt.Present && endDateOpt.Present)
                {
                    if (periodToStartOpt.Present)
                    {
                        throw new System.ArgumentException("Fra 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));
                    }
                    LocalDate startDate = startDateOpt.get();
                    LocalDate endDate   = endDateOpt.get();
                    // NOTE: payment date assumed to be the start date
                    FraTrade trade = convention.toTrade(info, startDate, endDate, startDate, buySell, notional, fixedRate);
                    return(adjustTrade(trade, dateCnv, dateCalOpt));
                }
                // relative dates
                if (periodToStartOpt.Present && info.TradeDate.Present)
                {
                    if (startDateOpt.Present || endDateOpt.Present)
                    {
                        throw new System.ArgumentException("Fra trade had invalid combination of fields. When these fields are found " + ImmutableList.of(CONVENTION_FIELD, PERIOD_TO_START_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();
                    FraTrade  trade         = convention.createTrade(tradeDate, periodToStart, buySell, notional, fixedRate, resolver.ReferenceData);
                    trade = trade.toBuilder().info(info).build();
                    return(adjustTrade(trade, dateCnv, dateCalOpt));
                }
            }
            else if (startDateOpt.Present && endDateOpt.Present && indexOpt.Present)
            {
                LocalDate   startDate = startDateOpt.get();
                LocalDate   endDate   = endDateOpt.get();
                IborIndex   index     = indexOpt.get();
                Fra.Builder builder   = Fra.builder().buySell(buySell).notional(notional).startDate(startDate).endDate(endDate).fixedRate(fixedRate).index(index);
                interpolatedOpt.ifPresent(interpolated => builder.indexInterpolated(interpolated));
                dayCountOpt.ifPresent(dayCount => builder.dayCount(dayCount));
                return(adjustTrade(FraTrade.of(info, builder.build()), dateCnv, dateCalOpt));
            }
            // no match
            throw new System.ArgumentException("Fra 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) + " or " + ImmutableList.of(CONVENTION_FIELD, START_DATE_FIELD, END_DATE_FIELD) + " or " + ImmutableList.of(START_DATE_FIELD, END_DATE_FIELD, INDEX_FIELD));
        }
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test(dataProvider = "calendar") public void test_calendar(ImmutableFxSwapConvention convention, com.opengamma.strata.basics.date.HolidayCalendarId cal)
        public virtual void test_calendar(ImmutableFxSwapConvention convention, HolidayCalendarId cal)
        {
            assertEquals(convention.SpotDateOffset.Calendar, cal);
            assertEquals(convention.BusinessDayAdjustment.Calendar, cal);
        }