//-----------------------------------------------------------------------
        public virtual void floatingSwapLeg()
        {
            // a PeriodicSchedule generates a schedule of accrual periods
            // - interest is accrued every 6 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.P6M).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
            // - no compounding is needed as the payment schedule matches the accrual schedule
            PaymentSchedule paymentSchedule = PaymentSchedule.builder().paymentFrequency(Frequency.P6M).paymentRelativeTo(PaymentRelativeTo.PERIOD_END).paymentDateOffset(DaysAdjustment.ofBusinessDays(2, HolidayCalendarIds.GBLO)).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
            // - an IborRateCalculation is used to represent a floating Ibor rate
            // - the "Act/Act ISDA" day count is used
            // - the index is GBP LIBOR 6M
            // - fixing is 2 days before the start of the period using the "GBLO" holiday calendar
            RateCalculationSwapLeg swapLeg = RateCalculationSwapLeg.builder().payReceive(PayReceive.RECEIVE).accrualSchedule(accrualSchedule).paymentSchedule(paymentSchedule).notionalSchedule(notionalSchedule).calculation(IborRateCalculation.builder().dayCount(DayCounts.ACT_ACT_ISDA).index(IborIndices.GBP_LIBOR_6M).fixingRelativeTo(FixingRelativeTo.PERIOD_START).fixingDateOffset(DaysAdjustment.ofBusinessDays(-2, HolidayCalendarIds.GBLO)).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("===== Floating =====");
            Console.WriteLine(JodaBeanSer.PRETTY.xmlWriter().write(swapLeg));
            Console.WriteLine();
            Console.WriteLine("===== Floating resolved =====");
            Console.WriteLine(JodaBeanSer.PRETTY.xmlWriter().write(resolvedLeg));
            Console.WriteLine();
        }
        //-----------------------------------------------------------------------
        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();
        }
Пример #3
0
        public virtual void test_createSchedule_dualStub()
        {
            PaymentSchedule test     = PaymentSchedule.builder().paymentFrequency(P2M).paymentDateOffset(DaysAdjustment.ofBusinessDays(2, GBLO)).build();
            Schedule        schedule = test.createSchedule(ACCRUAL_SCHEDULE_STUBS, REF_DATA);

            assertEquals(schedule, ACCRUAL_SCHEDULE_STUBS.toBuilder().frequency(P2M).build());
        }
        public virtual void test_inflation_fixed()
        {
            BusinessDayAdjustment  bda              = BusinessDayAdjustment.of(FOLLOWING, GBLO);
            PeriodicSchedule       accrualSchedule  = PeriodicSchedule.builder().startDate(DATE_14_06_09).endDate(DATE_19_06_09).frequency(P12M).businessDayAdjustment(bda).build();
            PaymentSchedule        paymentSchedule  = PaymentSchedule.builder().paymentFrequency(Frequency.ofYears(5)).paymentDateOffset(DaysAdjustment.ofBusinessDays(2, GBLO)).compoundingMethod(STRAIGHT).build();
            FixedRateCalculation   rateCalc         = FixedRateCalculation.builder().rate(ValueSchedule.of(0.05)).dayCount(ONE_ONE).build();
            NotionalSchedule       notionalSchedule = NotionalSchedule.of(GBP, 1000d);
            RateCalculationSwapLeg test             = RateCalculationSwapLeg.builder().payReceive(RECEIVE).accrualSchedule(accrualSchedule).paymentSchedule(paymentSchedule).notionalSchedule(notionalSchedule).calculation(rateCalc).build();

            assertEquals(test.StartDate, AdjustableDate.of(DATE_14_06_09, bda));
            assertEquals(test.EndDate, AdjustableDate.of(DATE_19_06_09, bda));
            assertEquals(test.Currency, GBP);
            assertEquals(test.PayReceive, RECEIVE);
            assertEquals(test.AccrualSchedule, accrualSchedule);
            assertEquals(test.PaymentSchedule, paymentSchedule);
            assertEquals(test.NotionalSchedule, notionalSchedule);
            assertEquals(test.Calculation, rateCalc);
            RateAccrualPeriod rap0       = RateAccrualPeriod.builder().startDate(bda.adjust(DATE_14_06_09, REF_DATA)).endDate(bda.adjust(DATE_14_06_09.plusYears(1), REF_DATA)).unadjustedStartDate(DATE_14_06_09).unadjustedEndDate(DATE_14_06_09.plusYears(1)).yearFraction(1.0).rateComputation(FixedRateComputation.of(0.05)).build();
            RateAccrualPeriod rap1       = RateAccrualPeriod.builder().startDate(bda.adjust(DATE_14_06_09.plusYears(1), REF_DATA)).endDate(bda.adjust(DATE_14_06_09.plusYears(2), REF_DATA)).unadjustedStartDate(DATE_14_06_09.plusYears(1)).unadjustedEndDate(DATE_14_06_09.plusYears(2)).yearFraction(1.0).rateComputation(FixedRateComputation.of(0.05)).build();
            RateAccrualPeriod rap2       = RateAccrualPeriod.builder().startDate(bda.adjust(DATE_14_06_09.plusYears(2), REF_DATA)).endDate(bda.adjust(DATE_14_06_09.plusYears(3), REF_DATA)).unadjustedStartDate(DATE_14_06_09.plusYears(2)).unadjustedEndDate(DATE_14_06_09.plusYears(3)).yearFraction(1.0).rateComputation(FixedRateComputation.of(0.05)).build();
            RateAccrualPeriod rap3       = RateAccrualPeriod.builder().startDate(bda.adjust(DATE_14_06_09.plusYears(3), REF_DATA)).endDate(bda.adjust(DATE_14_06_09.plusYears(4), REF_DATA)).unadjustedStartDate(DATE_14_06_09.plusYears(3)).unadjustedEndDate(DATE_14_06_09.plusYears(4)).yearFraction(1.0).rateComputation(FixedRateComputation.of(0.05)).build();
            RateAccrualPeriod rap4       = RateAccrualPeriod.builder().startDate(bda.adjust(DATE_14_06_09.plusYears(4), REF_DATA)).endDate(bda.adjust(DATE_19_06_09, REF_DATA)).unadjustedStartDate(DATE_14_06_09.plusYears(4)).unadjustedEndDate(DATE_19_06_09).yearFraction(1.0).rateComputation(FixedRateComputation.of(0.05)).build();
            RatePaymentPeriod rpp        = RatePaymentPeriod.builder().paymentDate(DaysAdjustment.ofBusinessDays(2, GBLO).adjust(bda.adjust(DATE_19_06_09, REF_DATA), REF_DATA)).accrualPeriods(rap0, rap1, rap2, rap3, rap4).compoundingMethod(STRAIGHT).dayCount(ONE_ONE).currency(GBP).notional(1000d).build();
            ResolvedSwapLeg   expected   = ResolvedSwapLeg.builder().paymentPeriods(rpp).payReceive(RECEIVE).type(SwapLegType.FIXED).build();
            ResolvedSwapLeg   testExpand = test.resolve(REF_DATA);

            assertEquals(testExpand, expected);
        }
        public virtual void test_inflation_interpolated()
        {
            BusinessDayAdjustment    bda              = BusinessDayAdjustment.of(FOLLOWING, GBLO);
            PeriodicSchedule         accrualSchedule  = PeriodicSchedule.builder().startDate(DATE_14_06_09).endDate(DATE_19_06_09).frequency(Frequency.ofYears(5)).businessDayAdjustment(bda).build();
            PaymentSchedule          paymentSchedule  = PaymentSchedule.builder().paymentFrequency(Frequency.ofYears(5)).paymentDateOffset(DaysAdjustment.ofBusinessDays(2, GBLO)).build();
            InflationRateCalculation rateCalc         = InflationRateCalculation.builder().index(GB_RPI).indexCalculationMethod(INTERPOLATED).lag(Period.ofMonths(3)).build();
            NotionalSchedule         notionalSchedule = NotionalSchedule.of(GBP, 1000d);
            RateCalculationSwapLeg   test             = RateCalculationSwapLeg.builder().payReceive(RECEIVE).accrualSchedule(accrualSchedule).paymentSchedule(paymentSchedule).notionalSchedule(notionalSchedule).calculation(rateCalc).build();

            assertEquals(test.StartDate, AdjustableDate.of(DATE_14_06_09, bda));
            assertEquals(test.EndDate, AdjustableDate.of(DATE_19_06_09, bda));
            assertEquals(test.Currency, GBP);
            assertEquals(test.PayReceive, RECEIVE);
            assertEquals(test.AccrualSchedule, accrualSchedule);
            assertEquals(test.PaymentSchedule, paymentSchedule);
            assertEquals(test.NotionalSchedule, notionalSchedule);
            assertEquals(test.Calculation, rateCalc);

            double            weight     = 1.0 - 9.0 / 30.0;
            RatePaymentPeriod rpp0       = RatePaymentPeriod.builder().paymentDate(DaysAdjustment.ofBusinessDays(2, GBLO).adjust(bda.adjust(DATE_19_06_09, REF_DATA), REF_DATA)).accrualPeriods(RateAccrualPeriod.builder().startDate(bda.adjust(DATE_14_06_09, REF_DATA)).endDate(bda.adjust(DATE_19_06_09, REF_DATA)).unadjustedStartDate(DATE_14_06_09).unadjustedEndDate(DATE_19_06_09).yearFraction(1.0).rateComputation(InflationInterpolatedRateComputation.of(GB_RPI, YearMonth.from(bda.adjust(DATE_14_06_09, REF_DATA)).minusMonths(3), YearMonth.from(bda.adjust(DATE_19_06_09, REF_DATA)).minusMonths(3), weight)).build()).dayCount(ONE_ONE).currency(GBP).notional(1000d).build();
            ResolvedSwapLeg   expected   = ResolvedSwapLeg.builder().paymentPeriods(rpp0).payReceive(RECEIVE).type(SwapLegType.INFLATION).build();
            ResolvedSwapLeg   testExpand = test.resolve(REF_DATA);

            assertEquals(testExpand, expected);
        }
Пример #6
0
        public virtual void test_createSchedule_term()
        {
            PaymentSchedule test     = PaymentSchedule.builder().paymentFrequency(TERM).paymentDateOffset(DaysAdjustment.ofBusinessDays(2, GBLO)).build();
            Schedule        schedule = test.createSchedule(ACCRUAL_SCHEDULE, REF_DATA);

            assertEquals(schedule, ACCRUAL_SCHEDULE_TERM);
        }
Пример #7
0
        public virtual void test_createSchedule_finalStubFullMerge()
        {
            PaymentSchedule test     = PaymentSchedule.builder().paymentFrequency(P2M).paymentDateOffset(DaysAdjustment.ofBusinessDays(2, GBLO)).build();
            Schedule        schedule = test.createSchedule(ACCRUAL_SCHEDULE_FINAL_STUB, REF_DATA);
            Schedule        expected = Schedule.builder().periods(SchedulePeriod.of(DATE_01_06, DATE_03_05, DATE_01_05, DATE_03_05), ACCRUAL3STUB).frequency(P2M).rollConvention(DAY_5).build();

            assertEquals(schedule, expected);
        }
Пример #8
0
        public virtual void test_createSchedule_firstDate_validInitialStub()
        {
            PaymentSchedule test     = PaymentSchedule.builder().paymentFrequency(P2M).paymentDateOffset(DaysAdjustment.ofBusinessDays(2, GBLO)).firstRegularStartDate(DATE_02_05).build();
            Schedule        schedule = test.createSchedule(ACCRUAL_SCHEDULE, REF_DATA);
            Schedule        expected = Schedule.builder().periods(SchedulePeriod.of(DATE_01_06, DATE_02_05, DATE_01_05, DATE_02_05), SchedulePeriod.of(DATE_02_05, DATE_04_07, DATE_02_05, DATE_04_05)).frequency(P2M).rollConvention(DAY_5).build();

            assertEquals(schedule, expected);
        }
Пример #9
0
        public virtual void test_createSchedule_lastDate_finalAccrualStub()
        {
            PaymentSchedule test     = PaymentSchedule.builder().paymentFrequency(P2M).paymentDateOffset(DaysAdjustment.ofBusinessDays(2, GBLO)).lastRegularEndDate(DATE_03_05).build();
            Schedule        schedule = test.createSchedule(ACCRUAL_SCHEDULE_FINAL_STUB_4PERIODS, REF_DATA);
            Schedule        expected = Schedule.builder().periods(SchedulePeriod.of(DATE_01_06, DATE_03_05, DATE_01_05, DATE_03_05), SchedulePeriod.of(DATE_03_05, DATE_04_30, DATE_03_05, DATE_04_30)).frequency(P2M).rollConvention(DAY_5).build();

            assertEquals(schedule, expected);
        }
Пример #10
0
        public virtual void test_createSchedule_initialStubPartMergeBackwards()
        {
            PaymentSchedule test     = PaymentSchedule.builder().paymentFrequency(P2M).paymentDateOffset(DaysAdjustment.ofBusinessDays(2, GBLO)).build();
            Schedule        schedule = test.createSchedule(ACCRUAL_SCHEDULE_INITIAL_STUB, REF_DATA);
            Schedule        expected = Schedule.builder().periods(ACCRUAL1STUB, SchedulePeriod.of(DATE_02_05, DATE_03_05, DATE_02_05, DATE_03_05), SchedulePeriod.of(DATE_03_05, DATE_05_06, DATE_03_05, DATE_05_05)).frequency(P2M).rollConvention(DAY_5).build();

            assertEquals(schedule, expected);
        }
Пример #11
0
        //-------------------------------------------------------------------------
        public virtual void coverage()
        {
            PaymentSchedule test = PaymentSchedule.builder().paymentFrequency(P1M).paymentDateOffset(DaysAdjustment.ofBusinessDays(2, GBLO)).build();

            coverImmutableBean(test);
            PaymentSchedule test2 = PaymentSchedule.builder().paymentFrequency(P3M).businessDayAdjustment(BDA).paymentDateOffset(DaysAdjustment.ofBusinessDays(3, GBLO)).paymentRelativeTo(PERIOD_START).compoundingMethod(STRAIGHT).firstRegularStartDate(DATE_01_06).lastRegularEndDate(DATE_02_05).build();

            coverBeanEquals(test, test2);
        }
Пример #12
0
        //-------------------------------------------------------------------------
        public virtual void test_builder_ensureDefaults()
        {
            PaymentSchedule test = PaymentSchedule.builder().paymentFrequency(P1M).paymentDateOffset(DaysAdjustment.ofBusinessDays(2, GBLO)).build();

            assertEquals(test.PaymentFrequency, P1M);
            assertEquals(test.BusinessDayAdjustment, null);
            assertEquals(test.PaymentDateOffset, DaysAdjustment.ofBusinessDays(2, GBLO));
            assertEquals(test.PaymentRelativeTo, PERIOD_END);
            assertEquals(test.CompoundingMethod, NONE);
        }
Пример #13
0
        public virtual void test_summarize_irs_weird()
        {
            PeriodicSchedule       accrual  = PeriodicSchedule.of(date(2018, 2, 12), date(2020, 2, 12), Frequency.P3M, BusinessDayAdjustment.NONE, SHORT_INITIAL, false);
            PaymentSchedule        payment  = PaymentSchedule.builder().paymentFrequency(Frequency.P3M).paymentDateOffset(DaysAdjustment.NONE).build();
            NotionalSchedule       notional = NotionalSchedule.of(GBP, ValueSchedule.builder().initialValue(1_000_000).stepSequence(ValueStepSequence.of(date(2018, 8, 12), date(2019, 8, 12), Frequency.P6M, ofDeltaAmount(-50_000))).build());
            RateCalculationSwapLeg payLeg   = RateCalculationSwapLeg.builder().payReceive(PAY).accrualSchedule(accrual).paymentSchedule(payment).notionalSchedule(notional).calculation(FixedRateCalculation.builder().dayCount(ACT_360).rate(ValueSchedule.builder().initialValue(0.0012).stepSequence(ValueStepSequence.of(date(2018, 8, 12), date(2019, 8, 12), Frequency.P6M, ofDeltaAmount(0.0001))).build()).build()).build();
            RateCalculationSwapLeg recLeg   = RateCalculationSwapLeg.builder().payReceive(RECEIVE).accrualSchedule(accrual).paymentSchedule(payment).notionalSchedule(notional).calculation(IborRateCalculation.builder().index(IborIndices.GBP_LIBOR_3M).gearing(ValueSchedule.of(1.1)).spread(ValueSchedule.of(0.002)).build()).build();
            Swap test = Swap.of(payLeg, recLeg);

            assertEquals(test.summaryDescription(), "2Y GBP 1mm variable Rec GBP-LIBOR-3M * 1.1 + 0.2% / Pay 0.12% variable : 12Feb18-12Feb20");
        }
        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());
        }
        //-------------------------------------------------------------------------
        // payment schedule
        private static PaymentSchedule parsePaymentSchedule(CsvRow row, string leg, Frequency accrualFrequency)
        {
            PaymentSchedule.Builder builder = PaymentSchedule.builder();
            // basics
            builder.paymentFrequency(findValue(row, leg, PAYMENT_FREQUENCY_FIELD).map(s => Frequency.parse(s)).orElse(accrualFrequency));
            Optional <DaysAdjustment> offsetOpt = parseDaysAdjustment(row, leg, PAYMENT_OFFSET_DAYS_FIELD, PAYMENT_OFFSET_CAL_FIELD, PAYMENT_OFFSET_ADJ_CNV_FIELD, PAYMENT_OFFSET_ADJ_CAL_FIELD);

            builder.paymentDateOffset(offsetOpt.orElse(DaysAdjustment.NONE));
            // optionals
            findValue(row, leg, PAYMENT_RELATIVE_TO_FIELD).map(s => PaymentRelativeTo.of(s)).ifPresent(v => builder.paymentRelativeTo(v));
            findValue(row, leg, COMPOUNDING_METHOD_FIELD).map(s => CompoundingMethod.of(s)).ifPresent(v => builder.compoundingMethod(v));
            findValue(row, leg, PAYMENT_FIRST_REGULAR_START_DATE_FIELD).map(s => LoaderUtils.parseDate(s)).ifPresent(v => builder.firstRegularStartDate(v));
            findValue(row, leg, PAYMENT_LAST_REGULAR_END_DATE_FIELD).map(s => LoaderUtils.parseDate(s)).ifPresent(v => builder.lastRegularEndDate(v));
            return(builder.build());
        }
        //-------------------------------------------------------------------------
        public virtual void test_builder()
        {
            BusinessDayAdjustment bda             = BusinessDayAdjustment.of(FOLLOWING, GBLO);
            PeriodicSchedule      accrualSchedule = PeriodicSchedule.builder().startDate(DATE_01_05).endDate(DATE_04_05).frequency(P1M).businessDayAdjustment(bda).build();
            PaymentSchedule       paymentSchedule = PaymentSchedule.builder().paymentFrequency(P1M).paymentDateOffset(DaysAdjustment.ofBusinessDays(2, GBLO)).build();
            ValueSchedule         amountSchedule  = ValueSchedule.of(123d);
            KnownAmountSwapLeg    test            = KnownAmountSwapLeg.builder().payReceive(PAY).accrualSchedule(accrualSchedule).paymentSchedule(paymentSchedule).amount(amountSchedule).currency(GBP).build();

            assertEquals(test.PayReceive, PAY);
            assertEquals(test.StartDate, AdjustableDate.of(DATE_01_05, bda));
            assertEquals(test.EndDate, AdjustableDate.of(DATE_04_05, bda));
            assertEquals(test.AccrualSchedule, accrualSchedule);
            assertEquals(test.PaymentSchedule, paymentSchedule);
            assertEquals(test.Amount, amountSchedule);
            assertEquals(test.Currency, GBP);
            assertEquals(test.allCurrencies(), ImmutableSet.of(GBP));
        }
        //-------------------------------------------------------------------------
        public virtual void test_builder()
        {
            BusinessDayAdjustment  bda              = BusinessDayAdjustment.of(FOLLOWING, GBLO);
            PeriodicSchedule       accrualSchedule  = PeriodicSchedule.builder().startDate(DATE_01_05).endDate(DATE_04_05).frequency(P1M).businessDayAdjustment(bda).build();
            PaymentSchedule        paymentSchedule  = PaymentSchedule.builder().paymentFrequency(P1M).paymentDateOffset(DaysAdjustment.ofBusinessDays(2, GBLO)).build();
            FixedRateCalculation   rateCalc         = FixedRateCalculation.builder().dayCount(DayCounts.ACT_365F).rate(ValueSchedule.of(0.025d)).build();
            NotionalSchedule       notionalSchedule = NotionalSchedule.of(GBP, 1000d);
            RateCalculationSwapLeg test             = RateCalculationSwapLeg.builder().payReceive(PAY).accrualSchedule(accrualSchedule).paymentSchedule(paymentSchedule).notionalSchedule(notionalSchedule).calculation(rateCalc).build();

            assertEquals(test.StartDate, AdjustableDate.of(DATE_01_05, bda));
            assertEquals(test.EndDate, AdjustableDate.of(DATE_04_05, bda));
            assertEquals(test.Currency, GBP);
            assertEquals(test.PayReceive, PAY);
            assertEquals(test.AccrualSchedule, accrualSchedule);
            assertEquals(test.PaymentSchedule, paymentSchedule);
            assertEquals(test.NotionalSchedule, notionalSchedule);
            assertEquals(test.Calculation, rateCalc);
        }
        //-----------------------------------------------------------------------
        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 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());
        }
        // 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 compounding libor 6m vs libor 3m swap
        private static Trade createCompoundingLibor6mVsLibor3mSwap()
        {
            NotionalSchedule notional = NotionalSchedule.of(Currency.USD, 100_000_000);

            SwapLeg payLeg = RateCalculationSwapLeg.builder().payReceive(PayReceive.PAY).accrualSchedule(PeriodicSchedule.builder().startDate(LocalDate.of(2014, 8, 27)).endDate(LocalDate.of(2024, 8, 27)).frequency(Frequency.P6M).businessDayAdjustment(BusinessDayAdjustment.of(MODIFIED_FOLLOWING, HolidayCalendarIds.USNY)).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(Frequency.P6M).paymentDateOffset(DaysAdjustment.NONE).build()).notionalSchedule(notional).calculation(IborRateCalculation.of(IborIndices.USD_LIBOR_6M)).build();

            SwapLeg receiveLeg = RateCalculationSwapLeg.builder().payReceive(PayReceive.RECEIVE).accrualSchedule(PeriodicSchedule.builder().startDate(LocalDate.of(2014, 8, 27)).endDate(LocalDate.of(2024, 8, 27)).frequency(Frequency.P3M).businessDayAdjustment(BusinessDayAdjustment.of(MODIFIED_FOLLOWING, HolidayCalendarIds.USNY)).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(Frequency.P6M).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", "13")).addAttribute(AttributeType.DESCRIPTION, "Compounding libor 6m vs libor 3m").counterparty(StandardId.of("example", "A")).settlementDate(LocalDate.of(2014, 8, 27)).build()).build());
        }
Пример #22
0
        public virtual void test_serialization()
        {
            PaymentSchedule test = PaymentSchedule.builder().paymentFrequency(P3M).paymentDateOffset(DaysAdjustment.ofBusinessDays(2, GBLO)).build();

            assertSerialization(test);
        }
        // create a cross-currency GBP libor 3m vs USD libor 3m swap with spread
        private static Trade createXCcyGbpLibor3mVsUsdLibor3mSwap()
        {
            SwapLeg payLeg = RateCalculationSwapLeg.builder().payReceive(PayReceive.PAY).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.of(Currency.GBP, 61_600_000)).calculation(IborRateCalculation.of(IborIndices.GBP_LIBOR_3M)).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.USNY)).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(Frequency.P3M).paymentDateOffset(DaysAdjustment.NONE).build()).notionalSchedule(NotionalSchedule.of(Currency.USD, 100_000_000)).calculation(IborRateCalculation.builder().index(IborIndices.USD_LIBOR_3M).spread(ValueSchedule.of(0.0091)).build()).build();

            return(SwapTrade.builder().product(Swap.of(receiveLeg, payLeg)).info(TradeInfo.builder().id(StandardId.of("example", "14")).addAttribute(AttributeType.DESCRIPTION, "GBP Libor 3m vs USD Libor 3m").counterparty(StandardId.of("example", "A")).settlementDate(LocalDate.of(2014, 1, 24)).build()).build());
        }
        // 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());
        }
Пример #25
0
        public virtual void test_createSchedule_lastDate_invalidFinalStub()
        {
            PaymentSchedule test = PaymentSchedule.builder().paymentFrequency(P2M).paymentDateOffset(DaysAdjustment.ofBusinessDays(2, GBLO)).lastRegularEndDate(DATE_04_05).build();

            assertThrows(() => test.createSchedule(ACCRUAL_SCHEDULE, REF_DATA), typeof(ScheduleException));
        }
Пример #26
0
        public virtual void test_summarize_knownAmountVarying()
        {
            Swap test = Swap.of(KnownAmountSwapLeg.builder().accrualSchedule(PeriodicSchedule.of(date(2018, 2, 12), date(2020, 2, 12), Frequency.P3M, BusinessDayAdjustment.NONE, SHORT_INITIAL, false)).amount(ValueSchedule.builder().initialValue(145_000).stepSequence(ValueStepSequence.of(date(2018, 8, 12), date(2019, 8, 12), Frequency.P6M, ofDeltaAmount(-20_000))).build()).currency(GBP).payReceive(PAY).paymentSchedule(PaymentSchedule.builder().paymentFrequency(Frequency.P3M).paymentDateOffset(DaysAdjustment.NONE).build()).build());

            assertEquals(test.summaryDescription(), "2Y Pay GBP 145k variable : 12Feb18-12Feb20");
        }
Пример #27
0
        public virtual void test_resolve_unadjustedAccrualAdjustedPayment()
        {
            Swap test                  = Swap.builder().legs(RateCalculationSwapLeg.builder().payReceive(RECEIVE).accrualSchedule(PeriodicSchedule.builder().startDate(date(2016, 1, 3)).endDate(date(2016, 5, 3)).frequency(Frequency.P1M).businessDayAdjustment(BusinessDayAdjustment.NONE).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(Frequency.P1M).businessDayAdjustment(BusinessDayAdjustment.of(FOLLOWING, SAT_SUN)).paymentDateOffset(DaysAdjustment.ofBusinessDays(2, SAT_SUN)).build()).notionalSchedule(NotionalSchedule.of(GBP, NOTIONAL)).calculation(FixedRateCalculation.of(RATE, ACT_360)).build()).build();
            RatePaymentPeriod pp1      = RatePaymentPeriod.builder().paymentDate(date(2016, 2, 5)).accrualPeriods(RateAccrualPeriod.builder().startDate(date(2016, 1, 3)).unadjustedStartDate(date(2016, 1, 3)).endDate(date(2016, 2, 3)).unadjustedEndDate(date(2016, 2, 3)).yearFraction(ACT_360.yearFraction(date(2016, 1, 3), date(2016, 2, 3))).rateComputation(FixedRateComputation.of(RATE)).build()).dayCount(ACT_360).currency(GBP).notional(NOTIONAL).build();
            RatePaymentPeriod pp2      = RatePaymentPeriod.builder().paymentDate(date(2016, 3, 7)).accrualPeriods(RateAccrualPeriod.builder().startDate(date(2016, 2, 3)).unadjustedStartDate(date(2016, 2, 3)).endDate(date(2016, 3, 3)).unadjustedEndDate(date(2016, 3, 3)).yearFraction(ACT_360.yearFraction(date(2016, 2, 3), date(2016, 3, 3))).rateComputation(FixedRateComputation.of(RATE)).build()).dayCount(ACT_360).currency(GBP).notional(NOTIONAL).build();
            RatePaymentPeriod pp3      = RatePaymentPeriod.builder().paymentDate(date(2016, 4, 6)).accrualPeriods(RateAccrualPeriod.builder().startDate(date(2016, 3, 3)).unadjustedStartDate(date(2016, 3, 3)).endDate(date(2016, 4, 3)).unadjustedEndDate(date(2016, 4, 3)).yearFraction(ACT_360.yearFraction(date(2016, 3, 3), date(2016, 4, 3))).rateComputation(FixedRateComputation.of(RATE)).build()).dayCount(ACT_360).currency(GBP).notional(NOTIONAL).build();
            RatePaymentPeriod pp4      = RatePaymentPeriod.builder().paymentDate(date(2016, 5, 5)).accrualPeriods(RateAccrualPeriod.builder().startDate(date(2016, 4, 3)).unadjustedStartDate(date(2016, 4, 3)).endDate(date(2016, 5, 3)).unadjustedEndDate(date(2016, 5, 3)).yearFraction(ACT_360.yearFraction(date(2016, 4, 3), date(2016, 5, 3))).rateComputation(FixedRateComputation.of(RATE)).build()).dayCount(ACT_360).currency(GBP).notional(NOTIONAL).build();
            ResolvedSwap      expected = ResolvedSwap.builder().legs(ResolvedSwapLeg.builder().paymentPeriods(pp1, pp2, pp3, pp4).payReceive(RECEIVE).type(FIXED).build()).build();

            assertEqualsBean(test.resolve(REF_DATA), expected);
        }
        public virtual void test_toLeg_withSpread()
        {
            IborRateSwapLegConvention @base = IborRateSwapLegConvention.builder().index(GBP_LIBOR_3M).build();
            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).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(P3M).paymentDateOffset(DaysAdjustment.NONE).build()).notionalSchedule(NotionalSchedule.of(GBP, NOTIONAL_2M)).calculation(IborRateCalculation.builder().index(GBP_LIBOR_3M).spread(ValueSchedule.of(0.25d)).build()).build();

            assertEquals(test, expected);
        }
        //-------------------------------------------------------------------------
        public virtual void test_toLeg()
        {
            InflationRateSwapLegConvention @base = InflationRateSwapLegConvention.of(GB_HICP, LAG_3M, MONTHLY, 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);

            RateCalculationSwapLeg expected = RateCalculationSwapLeg.builder().payReceive(PAY).accrualSchedule(PeriodicSchedule.builder().frequency(Frequency.TERM).startDate(startDate).endDate(endDate).businessDayAdjustment(BDA_MOD_FOLLOW).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(Frequency.TERM).paymentDateOffset(DaysAdjustment.NONE).build()).notionalSchedule(NotionalSchedule.of(GBP, NOTIONAL_2M)).calculation(InflationRateCalculation.of(GB_HICP, 3, MONTHLY)).build();

            assertEquals(test, expected);
        }
Пример #30
0
        public virtual void test_createSchedule_term_badLastRegular()
        {
            PaymentSchedule test = PaymentSchedule.builder().paymentFrequency(TERM).paymentDateOffset(DaysAdjustment.ofBusinessDays(2, GBLO)).lastRegularEndDate(DATE_05_05).build();

            assertThrowsIllegalArg(() => test.createSchedule(ACCRUAL_SCHEDULE, REF_DATA));
        }