// an Ibor stub
        private static Optional <IborRateStubCalculation> parseIborStub(CsvRow row, string leg, Currency currency, IborRateCalculation.Builder builder, string rateField, string amountField, string indexField, string interpolatedField)
        {
            double?stubRateOpt   = findValue(row, leg, rateField).map(s => LoaderUtils.parseDoublePercent(s));
            double?stubAmountOpt = findValue(row, leg, amountField).map(s => LoaderUtils.parseDouble(s));
            Optional <IborIndex> stubIndexOpt  = findValue(row, leg, indexField).map(s => IborIndex.of(s));
            Optional <IborIndex> stubIndex2Opt = findValue(row, leg, interpolatedField).map(s => IborIndex.of(s));

            if (stubRateOpt.HasValue && !stubAmountOpt.HasValue && !stubIndexOpt.Present && !stubIndex2Opt.Present)
            {
                return(IborRateStubCalculation.ofFixedRate(stubRateOpt.Value));
            }
            else if (!stubRateOpt.HasValue && stubAmountOpt.HasValue && !stubIndexOpt.Present && !stubIndex2Opt.Present)
            {
                return(IborRateStubCalculation.ofKnownAmount(CurrencyAmount.of(currency, stubAmountOpt.Value)));
            }
            else if (!stubRateOpt.HasValue && !stubAmountOpt.HasValue && stubIndexOpt.Present)
            {
                if (stubIndex2Opt.Present)
                {
                    return(IborRateStubCalculation.ofIborInterpolatedRate(stubIndexOpt.get(), stubIndex2Opt.get()));
                }
                else
                {
                    return(IborRateStubCalculation.ofIborRate(stubIndexOpt.get()));
                }
            }
            else if (stubRateOpt.HasValue || stubAmountOpt.HasValue || stubIndexOpt.Present || stubIndex2Opt.Present)
            {
                throw new System.ArgumentException("Swap leg must define only one of the following fields " + ImmutableList.of(leg + rateField, leg + amountField, leg + indexField) + ", and '" + leg + interpolatedField + "' is only allowed with '" + leg + indexField + "'");
            }
            return(null);
        }
Beispiel #2
0
        // Converts an FpML 'StubValue' to a {@code IborRateStubCalculation}.
        private IborRateStubCalculation parseStubCalculation(XmlElement baseEl, FpmlDocument document)
        {
            Optional <XmlElement> rateOptEl = baseEl.findChild("stubRate");

            if (rateOptEl.Present)
            {
                return(IborRateStubCalculation.ofFixedRate(document.parseDecimal(rateOptEl.get())));
            }
            Optional <XmlElement> amountOptEl = baseEl.findChild("stubAmount");

            if (amountOptEl.Present)
            {
                return(IborRateStubCalculation.ofKnownAmount(document.parseCurrencyAmount(amountOptEl.get())));
            }
            IList <XmlElement> indicesEls = baseEl.getChildren("floatingRate");

            if (indicesEls.Count == 1)
            {
                XmlElement indexEl = indicesEls[0];
                document.validateNotPresent(indexEl, "floatingRateMultiplierSchedule");
                document.validateNotPresent(indexEl, "spreadSchedule");
                document.validateNotPresent(indexEl, "rateTreatment");
                document.validateNotPresent(indexEl, "capRateSchedule");
                document.validateNotPresent(indexEl, "floorRateSchedule");
                return(IborRateStubCalculation.ofIborRate((IborIndex)document.parseIndex(indexEl)));
            }
            else if (indicesEls.Count == 2)
            {
                XmlElement index1El = indicesEls[0];
                document.validateNotPresent(index1El, "floatingRateMultiplierSchedule");
                document.validateNotPresent(index1El, "spreadSchedule");
                document.validateNotPresent(index1El, "rateTreatment");
                document.validateNotPresent(index1El, "capRateSchedule");
                document.validateNotPresent(index1El, "floorRateSchedule");
                XmlElement index2El = indicesEls[1];
                document.validateNotPresent(index2El, "floatingRateMultiplierSchedule");
                document.validateNotPresent(index2El, "spreadSchedule");
                document.validateNotPresent(index2El, "rateTreatment");
                document.validateNotPresent(index2El, "capRateSchedule");
                document.validateNotPresent(index2El, "floorRateSchedule");
                return(IborRateStubCalculation.ofIborInterpolatedRate((IborIndex)document.parseIndex(index1El), (IborIndex)document.parseIndex(index2El)));
            }
            throw new FpmlParseException("Unknown stub structure: " + baseEl);
        }
        // Create a fixed vs libor 6m swap
        private static Trade createInterpolatedStub4mFixedVsLibor6mSwap()
        {
            NotionalSchedule notional = NotionalSchedule.of(Currency.USD, 100_000_000);

            SwapLeg payLeg = RateCalculationSwapLeg.builder().payReceive(PayReceive.PAY).accrualSchedule(PeriodicSchedule.builder().startDate(LocalDate.of(2014, 9, 12)).endDate(LocalDate.of(2016, 7, 12)).frequency(Frequency.P6M).businessDayAdjustment(BusinessDayAdjustment.of(MODIFIED_FOLLOWING, HolidayCalendarIds.USNY)).stubConvention(StubConvention.SHORT_INITIAL).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(Frequency.P6M).paymentDateOffset(DaysAdjustment.NONE).build()).notionalSchedule(notional).calculation(IborRateCalculation.builder().index(IborIndices.USD_LIBOR_6M).initialStub(IborRateStubCalculation.ofIborInterpolatedRate(IborIndices.USD_LIBOR_3M, IborIndices.USD_LIBOR_6M)).build()).build();

            SwapLeg receiveLeg = RateCalculationSwapLeg.builder().payReceive(PayReceive.RECEIVE).accrualSchedule(PeriodicSchedule.builder().startDate(LocalDate.of(2014, 9, 12)).endDate(LocalDate.of(2016, 7, 12)).stubConvention(StubConvention.SHORT_INITIAL).frequency(Frequency.P6M).businessDayAdjustment(BusinessDayAdjustment.of(MODIFIED_FOLLOWING, HolidayCalendarIds.USNY)).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(Frequency.P6M).paymentDateOffset(DaysAdjustment.NONE).build()).notionalSchedule(notional).calculation(FixedRateCalculation.of(0.01, DayCounts.THIRTY_U_360)).build();

            return(SwapTrade.builder().product(Swap.of(payLeg, receiveLeg)).info(TradeInfo.builder().id(StandardId.of("example", "9")).addAttribute(AttributeType.DESCRIPTION, "Fixed vs Libor 6m (interpolated 4m short initial stub)").counterparty(StandardId.of("example", "A")).settlementDate(LocalDate.of(2014, 9, 12)).build()).build());
        }
        //-------------------------------------------------------------------------
        public virtual void test_InterpolatedStub4mFixed6mVsLibor6mSwap()
        {
            SwapLeg receiveLeg = fixedLeg(LocalDate.of(2014, 9, 12), LocalDate.of(2016, 7, 12), P6M, RECEIVE, NOTIONAL, 0.01, StubConvention.SHORT_INITIAL);

            SwapLeg payLeg = RateCalculationSwapLeg.builder().payReceive(PAY).accrualSchedule(PeriodicSchedule.builder().startDate(LocalDate.of(2014, 9, 12)).endDate(LocalDate.of(2016, 7, 12)).frequency(P6M).businessDayAdjustment(BDA_MF).stubConvention(StubConvention.SHORT_INITIAL).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(P6M).paymentDateOffset(DaysAdjustment.NONE).build()).notionalSchedule(NOTIONAL).calculation(IborRateCalculation.builder().index(USD_LIBOR_6M).fixingDateOffset(DaysAdjustment.ofBusinessDays(-2, CalendarUSD.NYC, BDA_P)).initialStub(IborRateStubCalculation.ofIborInterpolatedRate(USD_LIBOR_3M, USD_LIBOR_6M)).build()).build();

            ResolvedSwapTrade trade = SwapTrade.builder().info(TradeInfo.builder().tradeDate(LocalDate.of(2014, 9, 10)).build()).product(Swap.of(receiveLeg, payLeg)).build().resolve(REF_DATA);

            DiscountingSwapTradePricer pricer = swapPricer();
            CurrencyAmount             pv     = pricer.presentValue(trade, provider()).getAmount(USD);

            assertEquals(pv.Amount, 314215.2347116342, TOLERANCE_PV);
        }