Esempio n. 1
0
 // Converts an FpML 'fixedRateSchedule' to a {@code RateCalculation}.
 private RateCalculation parseFixed(XmlElement legEl, XmlElement calcEl, XmlElement fixedEl, FpmlDocument document)
 {
     // supported elements:
     //  'calculationPeriodAmount/calculation/fixedRateSchedule'
     //  'calculationPeriodAmount/calculation/dayCountFraction'
     //  'stubCalculationPeriodAmount'
     // rejected elements:
     //  'resetDates'
     //  'stubCalculationPeriodAmount/initialStub/floatingRate'
     //  'stubCalculationPeriodAmount/finalStub/floatingRate'
     document.validateNotPresent(legEl, "resetDates");
     FixedRateCalculation.Builder fixedRateBuilder = FixedRateCalculation.builder();
     fixedRateBuilder.rate(parseSchedule(fixedEl, document));
     fixedRateBuilder.dayCount(document.parseDayCountFraction(calcEl.getChild("dayCountFraction")));
     // stub
     legEl.findChild("stubCalculationPeriodAmount").ifPresent(stubsEl =>
     {
         stubsEl.findChild("initialStub").ifPresent(el =>
         {
             fixedRateBuilder.initialStub(parseStubCalculationForFixed(el, document));
         });
         stubsEl.findChild("finalStub").ifPresent(el =>
         {
             fixedRateBuilder.finalStub(parseStubCalculationForFixed(el, document));
         });
     });
     return(fixedRateBuilder.build());
 }
        //-------------------------------------------------------------------------
        // fixed rate calculation
        private static RateCalculation parseFixedRateCalculation(CsvRow row, string leg, Currency currency, DayCount defaultFixedLegDayCount)
        {
            FixedRateCalculation.Builder builder = FixedRateCalculation.builder();
            // basics
            double   fixedRate = LoaderUtils.parseDoublePercent(getValue(row, leg, FIXED_RATE_FIELD));
            DayCount dayCount  = findValue(row, leg, DAY_COUNT_FIELD).map(s => LoaderUtils.parseDayCount(s)).orElse(defaultFixedLegDayCount);

            if (dayCount == null)
            {
                throw new System.ArgumentException("Swap leg must define day count using '" + leg + DAY_COUNT_FIELD + "'");
            }
            builder.dayCount(dayCount);
            builder.rate(ValueSchedule.of(fixedRate));
            // initial stub
            double?initialStubRateOpt   = findValue(row, leg, INITIAL_STUB_RATE_FIELD).map(s => LoaderUtils.parseDoublePercent(s));
            double?initialStubAmountOpt = findValue(row, leg, INITIAL_STUB_AMOUNT_FIELD).map(s => LoaderUtils.parseDouble(s));

            if (initialStubRateOpt.HasValue && initialStubAmountOpt.HasValue)
            {
                throw new System.ArgumentException("Swap leg must not define both '" + leg + INITIAL_STUB_RATE_FIELD + "' and  '" + leg + INITIAL_STUB_AMOUNT_FIELD + "'");
            }
            initialStubRateOpt.ifPresent(v => builder.initialStub(FixedRateStubCalculation.ofFixedRate(v)));
            initialStubAmountOpt.ifPresent(v => builder.initialStub(FixedRateStubCalculation.ofKnownAmount(CurrencyAmount.of(currency, v))));
            // final stub
            double?finalStubRateOpt   = findValue(row, leg, FINAL_STUB_RATE_FIELD).map(s => LoaderUtils.parseDoublePercent(s));
            double?finalStubAmountOpt = findValue(row, leg, FINAL_STUB_AMOUNT_FIELD).map(s => LoaderUtils.parseDouble(s));

            if (finalStubRateOpt.HasValue && finalStubAmountOpt.HasValue)
            {
                throw new System.ArgumentException("Swap leg must not define both '" + leg + FINAL_STUB_RATE_FIELD + "' and  '" + leg + FINAL_STUB_AMOUNT_FIELD + "'");
            }
            finalStubRateOpt.ifPresent(v => builder.finalStub(FixedRateStubCalculation.ofFixedRate(v)));
            finalStubAmountOpt.ifPresent(v => builder.finalStub(FixedRateStubCalculation.ofKnownAmount(CurrencyAmount.of(currency, v))));
            return(builder.build());
        }
        // variable fixed rate
        private static SwapTrade parseVariableRates(SwapTrade trade, IList <CsvRow> variableRows)
        {
            ImmutableList.Builder <ValueStep> stepBuilder = ImmutableList.builder();
            foreach (CsvRow row in variableRows)
            {
                LocalDate date = LoaderUtils.parseDate(row.getValue(START_DATE_FIELD));
                row.findValue(FIXED_RATE_FIELD).map(str => LoaderUtils.parseDoublePercent(str)).ifPresent(fixedRate => stepBuilder.add(ValueStep.of(date, ValueAdjustment.ofReplace(fixedRate))));
            }
            ImmutableList <ValueStep> varRates = stepBuilder.build();

            if (varRates.Empty)
            {
                return(trade);
            }
            // adjust the trade, inserting the variable rates
            ImmutableList.Builder <SwapLeg> legBuilder = ImmutableList.builder();
            foreach (SwapLeg swapLeg in trade.Product.Legs)
            {
                RateCalculationSwapLeg leg = (RateCalculationSwapLeg)swapLeg;
                if (leg.Calculation is FixedRateCalculation)
                {
                    FixedRateCalculation baseCalc = (FixedRateCalculation)leg.Calculation;
                    FixedRateCalculation calc     = baseCalc.toBuilder().rate(ValueSchedule.of(baseCalc.Rate.InitialValue, varRates)).build();
                    legBuilder.add(leg.toBuilder().calculation(calc).build());
                }
                else
                {
                    legBuilder.add(leg);
                }
            }
            return(replaceLegs(trade, legBuilder.build()));
        }
        //-----------------------------------------------------------------------
        public virtual void fixedSwapLeg()
        {
            // a PeriodicSchedule generates a schedule of accrual periods
            // - interest is accrued every 3 months from 2014-02-12 to 2014-07-31
            // - accrual period dates are adjusted "modified following" using the "GBLO" holiday calendar
            // - there will be a long initial stub
            // - the regular accrual period dates will be at the end-of-month
            PeriodicSchedule accrualSchedule = PeriodicSchedule.builder().startDate(LocalDate.of(2014, 2, 12)).endDate(LocalDate.of(2016, 7, 31)).businessDayAdjustment(BusinessDayAdjustment.of(MODIFIED_FOLLOWING, HolidayCalendarIds.GBLO)).frequency(Frequency.P3M).stubConvention(StubConvention.LONG_INITIAL).rollConvention(RollConventions.EOM).build();
            // a PaymentSchedule generates a schedule of payment periods, based on the accrual schedule
            // - payments are every 6 months
            // - payments are 2 business days after the end of the period
            // - straight compounding is used (the payments are less frequent than the accrual, so compounding occurs)
            PaymentSchedule paymentSchedule = PaymentSchedule.builder().paymentFrequency(Frequency.P6M).paymentRelativeTo(PaymentRelativeTo.PERIOD_END).paymentDateOffset(DaysAdjustment.ofBusinessDays(2, HolidayCalendarIds.GBLO)).compoundingMethod(CompoundingMethod.STRAIGHT).build();
            // a NotionalSchedule generates a schedule of notional amounts, based on the payment schedule
            // - in this simple case the notional is 1 million GBP and does not change
            NotionalSchedule notionalSchedule = NotionalSchedule.of(Currency.GBP, 1_000_000);
            // a RateCalculationSwapLeg can represent a fixed or floating swap leg
            // - a FixedRateCalculation is used to represent a fixed rate
            // - the "Act/Act ISDA" day count is used
            // - the rate starts at 0.8% and reduces to 0.7%
            RateCalculationSwapLeg swapLeg = RateCalculationSwapLeg.builder().payReceive(PayReceive.PAY).accrualSchedule(accrualSchedule).paymentSchedule(paymentSchedule).notionalSchedule(notionalSchedule).calculation(FixedRateCalculation.builder().dayCount(DayCounts.ACT_ACT_ISDA).rate(ValueSchedule.of(0.008, ValueStep.of(LocalDate.of(2015, 1, 31), ValueAdjustment.ofReplace(0.007)))).build()).build();
            // a ResolvedSwapLeg has all the dates of the cash flows
            // it remains valid so long as the holiday calendar does not change
            ResolvedSwapLeg resolvedLeg = swapLeg.resolve(ReferenceData.standard());

            Console.WriteLine("===== Fixed =====");
            Console.WriteLine(JodaBeanSer.PRETTY.xmlWriter().write(swapLeg));
            Console.WriteLine();
            Console.WriteLine("===== Fixed resolved =====");
            Console.WriteLine(JodaBeanSer.PRETTY.xmlWriter().write(resolvedLeg));
            Console.WriteLine();
        }
        //-----------------------------------------------------------------------
        public virtual void vanillaFixedVsLibor3mSwap()
        {
            // we are paying a fixed rate every 3 months at 1.5% with a 100 million notional
            RateCalculationSwapLeg payLeg = RateCalculationSwapLeg.builder().payReceive(PayReceive.PAY).accrualSchedule(PeriodicSchedule.builder().startDate(LocalDate.of(2014, 9, 12)).endDate(LocalDate.of(2021, 9, 12)).frequency(Frequency.P3M).businessDayAdjustment(BusinessDayAdjustment.of(MODIFIED_FOLLOWING, HolidayCalendarIds.USNY)).startDateBusinessDayAdjustment(BusinessDayAdjustment.NONE).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(Frequency.P3M).paymentDateOffset(DaysAdjustment.NONE).build()).notionalSchedule(NotionalSchedule.builder().currency(Currency.USD).amount(ValueSchedule.of(100_000_000)).build()).calculation(FixedRateCalculation.of(0.015, DayCounts.THIRTY_U_360)).build();
            // we are receiving USD LIBOR 3M every 3 months with a 100 million notional
            RateCalculationSwapLeg receiveLeg = RateCalculationSwapLeg.builder().payReceive(PayReceive.RECEIVE).accrualSchedule(PeriodicSchedule.builder().startDate(LocalDate.of(2014, 9, 12)).endDate(LocalDate.of(2021, 9, 12)).frequency(Frequency.P3M).businessDayAdjustment(BusinessDayAdjustment.of(MODIFIED_FOLLOWING, HolidayCalendarIds.USNY)).startDateBusinessDayAdjustment(BusinessDayAdjustment.NONE).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(Frequency.P3M).paymentDateOffset(DaysAdjustment.NONE).build()).notionalSchedule(NotionalSchedule.builder().currency(Currency.USD).amount(ValueSchedule.of(100_000_000)).build()).calculation(IborRateCalculation.of(IborIndices.USD_LIBOR_3M)).build();
            // a SwapTrade combines the two legs
            SwapTrade trade = SwapTrade.builder().info(TradeInfo.builder().id(StandardId.of("OG-Trade", "1")).tradeDate(LocalDate.of(2014, 9, 10)).build()).product(Swap.of(payLeg, receiveLeg)).build();

            Console.WriteLine("===== Vanilla fixed vs Libor3m =====");
            Console.WriteLine(JodaBeanSer.PRETTY.xmlWriter().write(trade));
            Console.WriteLine();
            Console.WriteLine("===== Vanilla fixed vs Libor3m pay leg =====");
            Console.WriteLine(JodaBeanSer.PRETTY.xmlWriter().write(payLeg.resolve(ReferenceData.standard())));
            Console.WriteLine();
            Console.WriteLine("===== Vanilla fixed vs Libor3m receive leg =====");
            Console.WriteLine(JodaBeanSer.PRETTY.xmlWriter().write(receiveLeg.resolve(ReferenceData.standard())));
            Console.WriteLine();
        }
        // create a cross-currency USD fixed vs GBP libor 3m swap with initial and final notional exchange
        private static SwapTrade createNotionalExchangeSwap()
        {
            SwapLeg payLeg = RateCalculationSwapLeg.builder().payReceive(PayReceive.PAY).accrualSchedule(PeriodicSchedule.builder().startDate(LocalDate.of(2014, 1, 24)).endDate(LocalDate.of(2021, 1, 24)).frequency(Frequency.P6M).businessDayAdjustment(BusinessDayAdjustment.of(MODIFIED_FOLLOWING, HolidayCalendarIds.GBLO)).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(Frequency.P6M).paymentDateOffset(DaysAdjustment.NONE).build()).notionalSchedule(NotionalSchedule.builder().currency(Currency.USD).amount(ValueSchedule.of(100_000_000)).initialExchange(true).finalExchange(true).build()).calculation(FixedRateCalculation.of(0.03, DayCounts.THIRTY_U_360)).build();

            SwapLeg receiveLeg = RateCalculationSwapLeg.builder().payReceive(PayReceive.RECEIVE).accrualSchedule(PeriodicSchedule.builder().startDate(LocalDate.of(2014, 1, 24)).endDate(LocalDate.of(2021, 1, 24)).frequency(Frequency.P3M).businessDayAdjustment(BusinessDayAdjustment.of(MODIFIED_FOLLOWING, HolidayCalendarIds.GBLO)).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(Frequency.P3M).paymentDateOffset(DaysAdjustment.NONE).build()).notionalSchedule(NotionalSchedule.builder().currency(Currency.GBP).amount(ValueSchedule.of(61_600_000)).initialExchange(true).finalExchange(true).build()).calculation(IborRateCalculation.of(IborIndices.GBP_LIBOR_3M)).build();

            return(SwapTrade.builder().product(Swap.of(payLeg, receiveLeg)).info(TradeInfo.builder().id(StandardId.of("example", "16")).addAttribute(AttributeType.DESCRIPTION, "USD fixed vs GBP Libor 3m (notional exchange)").counterparty(StandardId.of("example", "A")).settlementDate(LocalDate.of(2014, 1, 24)).build()).build());
        }
        // Create a compounding fixed vs fed funds swap
        private static Trade createCompoundingFixedVsFedFundsSwap()
        {
            NotionalSchedule notional = NotionalSchedule.of(Currency.USD, 100_000_000);

            SwapLeg payLeg = RateCalculationSwapLeg.builder().payReceive(PayReceive.PAY).accrualSchedule(PeriodicSchedule.builder().startDate(LocalDate.of(2014, 2, 5)).endDate(LocalDate.of(2014, 4, 7)).frequency(Frequency.TERM).businessDayAdjustment(BusinessDayAdjustment.of(MODIFIED_FOLLOWING, HolidayCalendarIds.USNY)).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(Frequency.TERM).paymentDateOffset(DaysAdjustment.NONE).build()).notionalSchedule(notional).calculation(FixedRateCalculation.of(0.00123, DayCounts.ACT_360)).build();

            SwapLeg receiveLeg = RateCalculationSwapLeg.builder().payReceive(PayReceive.RECEIVE).accrualSchedule(PeriodicSchedule.builder().startDate(LocalDate.of(2014, 2, 5)).endDate(LocalDate.of(2014, 4, 7)).frequency(Frequency.TERM).businessDayAdjustment(BusinessDayAdjustment.of(MODIFIED_FOLLOWING, HolidayCalendarIds.USNY)).stubConvention(StubConvention.SHORT_INITIAL).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(Frequency.TERM).paymentDateOffset(DaysAdjustment.NONE).build()).notionalSchedule(notional).calculation(OvernightRateCalculation.of(OvernightIndices.USD_FED_FUND)).build();

            return(SwapTrade.builder().product(Swap.of(payLeg, receiveLeg)).info(TradeInfo.builder().id(StandardId.of("example", "11")).addAttribute(AttributeType.DESCRIPTION, "Compounding fixed vs fed funds").counterparty(StandardId.of("example", "A")).settlementDate(LocalDate.of(2014, 2, 5)).build()).build());
        }
        // Create a zero-coupon fixed vs libor 3m swap
        private static Trade createZeroCouponFixedVsLibor3mSwap()
        {
            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(2021, 9, 12)).frequency(Frequency.P12M).businessDayAdjustment(BusinessDayAdjustment.of(MODIFIED_FOLLOWING, HolidayCalendarIds.USNY)).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(Frequency.TERM).paymentDateOffset(DaysAdjustment.NONE).compoundingMethod(CompoundingMethod.STRAIGHT).build()).notionalSchedule(notional).calculation(FixedRateCalculation.of(0.015, DayCounts.THIRTY_U_360)).build();

            SwapLeg receiveLeg = RateCalculationSwapLeg.builder().payReceive(PayReceive.RECEIVE).accrualSchedule(PeriodicSchedule.builder().startDate(LocalDate.of(2014, 9, 12)).endDate(LocalDate.of(2021, 9, 12)).frequency(Frequency.P3M).businessDayAdjustment(BusinessDayAdjustment.of(MODIFIED_FOLLOWING, HolidayCalendarIds.USNY)).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(Frequency.TERM).paymentDateOffset(DaysAdjustment.NONE).compoundingMethod(CompoundingMethod.STRAIGHT).build()).notionalSchedule(notional).calculation(IborRateCalculation.of(IborIndices.USD_LIBOR_3M)).build();

            return(SwapTrade.builder().product(Swap.of(payLeg, receiveLeg)).info(TradeInfo.builder().id(StandardId.of("example", "10")).addAttribute(AttributeType.DESCRIPTION, "Zero-coupon fixed vs libor 3m").counterparty(StandardId.of("example", "A")).settlementDate(LocalDate.of(2014, 9, 12)).build()).build());
        }
        // 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());
        }
Esempio n. 10
0
        //-------------------------------------------------------------------------
        public virtual void test_toLeg()
        {
            FixedRateSwapLegConvention @base = FixedRateSwapLegConvention.of(GBP, ACT_365F, P3M, BDA_MOD_FOLLOW);
            LocalDate startDate             = LocalDate.of(2015, 5, 5);
            LocalDate endDate               = LocalDate.of(2020, 5, 5);
            RateCalculationSwapLeg test     = @base.toLeg(startDate, endDate, PAY, NOTIONAL_2M, 0.25d);
            RateCalculationSwapLeg expected = RateCalculationSwapLeg.builder().payReceive(PAY).accrualSchedule(PeriodicSchedule.builder().frequency(P3M).startDate(startDate).endDate(endDate).businessDayAdjustment(BDA_MOD_FOLLOW).stubConvention(StubConvention.SMART_INITIAL).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(P3M).paymentDateOffset(DaysAdjustment.NONE).build()).notionalSchedule(NotionalSchedule.of(GBP, NOTIONAL_2M)).calculation(FixedRateCalculation.of(0.25d, ACT_365F)).build();

            assertEquals(test, expected);
        }
Esempio n. 11
0
 private static SwapLeg fixedLeg(LocalDate start, LocalDate end, Frequency frequency, PayReceive payReceive, NotionalSchedule notional, double fixedRate, StubConvention stubConvention)
 {
     return(RateCalculationSwapLeg.builder().payReceive(payReceive).accrualSchedule(PeriodicSchedule.builder().startDate(start).endDate(end).frequency(frequency).businessDayAdjustment(BDA_MF).stubConvention(stubConvention).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(frequency).paymentDateOffset(DaysAdjustment.NONE).build()).notionalSchedule(notional).calculation(FixedRateCalculation.of(fixedRate, THIRTY_U_360)).build());
 }
        private static Trade createTrade1()
        {
            NotionalSchedule notional = NotionalSchedule.of(Currency.USD, 12_000_000);

            PeriodicSchedule accrual = PeriodicSchedule.builder().startDate(LocalDate.of(2006, 2, 24)).endDate(LocalDate.of(2011, 2, 24)).frequency(Frequency.P3M).businessDayAdjustment(BusinessDayAdjustment.of(MODIFIED_FOLLOWING, HolidayCalendarIds.USNY)).build();

            PaymentSchedule payment = PaymentSchedule.builder().paymentFrequency(Frequency.P3M).paymentDateOffset(DaysAdjustment.ofBusinessDays(2, HolidayCalendarIds.USNY)).build();

            SwapLeg payLeg = RateCalculationSwapLeg.builder().payReceive(PayReceive.PAY).accrualSchedule(accrual).paymentSchedule(payment).notionalSchedule(notional).calculation(FixedRateCalculation.of(0.05004, DayCounts.ACT_360)).build();

            SwapLeg receiveLeg = RateCalculationSwapLeg.builder().payReceive(PayReceive.RECEIVE).accrualSchedule(accrual).paymentSchedule(payment).notionalSchedule(notional).calculation(IborRateCalculation.of(IborIndices.USD_LIBOR_3M)).build();

            return(SwapTrade.builder().product(Swap.builder().legs(payLeg, receiveLeg).build()).info(TradeInfo.builder().id(StandardId.of("mn", "14248")).counterparty(StandardId.of("mn", "Dealer A")).settlementDate(LocalDate.of(2006, 2, 24)).build()).build());
        }
        //-------------------------------------------------------------------------
        public virtual void test_CompoundingOisFixed2mVsFedFund12mSwapWithFixing()
        {
            SwapLeg payLeg = RateCalculationSwapLeg.builder().payReceive(PAY).accrualSchedule(PeriodicSchedule.builder().startDate(LocalDate.of(2014, 1, 17)).endDate(LocalDate.of(2014, 3, 17)).frequency(TERM).businessDayAdjustment(BDA_MF).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(TERM).paymentDateOffset(DaysAdjustment.ofBusinessDays(2, CalendarUSD.NYC)).build()).notionalSchedule(NOTIONAL).calculation(FixedRateCalculation.builder().dayCount(ACT_360).rate(ValueSchedule.of(0.00123)).build()).build();

            SwapLeg receiveLeg = RateCalculationSwapLeg.builder().payReceive(RECEIVE).accrualSchedule(PeriodicSchedule.builder().startDate(LocalDate.of(2014, 1, 17)).endDate(LocalDate.of(2014, 3, 17)).frequency(TERM).businessDayAdjustment(BDA_MF).stubConvention(StubConvention.SHORT_INITIAL).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(TERM).paymentDateOffset(DaysAdjustment.ofBusinessDays(2, CalendarUSD.NYC)).build()).notionalSchedule(NOTIONAL).calculation(OvernightRateCalculation.builder().dayCount(ACT_360).index(USD_FED_FUND).build()).build();

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

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

            assertEquals(pv.Amount, -7352.973875972721, TOLERANCE_PV);
        }
        //-------------------------------------------------------------------------
        public virtual void test_AmortizingFixedVsLibor3mSwap()
        {
            ValueAdjustment   stepReduction = ValueAdjustment.ofDeltaAmount(-3_000_000);
            IList <ValueStep> steps         = new List <ValueStep>();

            for (int i = 1; i < 28; i++)
            {
                steps.Add(ValueStep.of(i, stepReduction));
            }
            ValueSchedule notionalSchedule = ValueSchedule.of(100_000_000, steps);
            SwapLeg       receiveLeg       = RateCalculationSwapLeg.builder().payReceive(RECEIVE).accrualSchedule(PeriodicSchedule.builder().startDate(LocalDate.of(2014, 9, 12)).endDate(LocalDate.of(2021, 9, 12)).frequency(P3M).businessDayAdjustment(BDA_MF).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(P3M).paymentDateOffset(DaysAdjustment.NONE).build()).notionalSchedule(NotionalSchedule.of(USD, notionalSchedule)).calculation(FixedRateCalculation.builder().dayCount(THIRTY_U_360).rate(ValueSchedule.of(0.016)).build()).build();

            SwapLeg payLeg = RateCalculationSwapLeg.builder().payReceive(PAY).accrualSchedule(PeriodicSchedule.builder().startDate(LocalDate.of(2014, 9, 12)).endDate(LocalDate.of(2021, 9, 12)).frequency(P3M).businessDayAdjustment(BDA_MF).stubConvention(StubConvention.SHORT_INITIAL).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(P3M).paymentDateOffset(DaysAdjustment.NONE).build()).notionalSchedule(NotionalSchedule.of(USD, notionalSchedule)).calculation(IborRateCalculation.builder().index(USD_LIBOR_3M).fixingDateOffset(DaysAdjustment.ofBusinessDays(-2, CalendarUSD.NYC, BDA_P)).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, -1850080.2895532502, TOLERANCE_PV);
        }
        //-------------------------------------------------------------------------
        public virtual void test_ZeroCouponFixedVsLibor3mSwap()
        {
            SwapLeg payLeg = RateCalculationSwapLeg.builder().payReceive(PAY).accrualSchedule(PeriodicSchedule.builder().startDate(LocalDate.of(2014, 9, 12)).endDate(LocalDate.of(2021, 9, 12)).frequency(P12M).businessDayAdjustment(BDA_MF).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(TERM).paymentDateOffset(DaysAdjustment.NONE).compoundingMethod(CompoundingMethod.STRAIGHT).build()).notionalSchedule(NOTIONAL).calculation(FixedRateCalculation.builder().dayCount(THIRTY_U_360).rate(ValueSchedule.of(0.015)).build()).build();

            SwapLeg receiveLeg = RateCalculationSwapLeg.builder().payReceive(RECEIVE).accrualSchedule(PeriodicSchedule.builder().startDate(LocalDate.of(2014, 9, 12)).endDate(LocalDate.of(2021, 9, 12)).frequency(P3M).businessDayAdjustment(BDA_MF).stubConvention(StubConvention.SHORT_INITIAL).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(TERM).paymentDateOffset(DaysAdjustment.NONE).compoundingMethod(CompoundingMethod.STRAIGHT).build()).notionalSchedule(NOTIONAL).calculation(IborRateCalculation.builder().index(USD_LIBOR_3M).fixingDateOffset(DaysAdjustment.ofBusinessDays(-2, CalendarUSD.NYC, BDA_P)).build()).build();

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

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

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