//-------------------------------------------------------------------------
        public virtual void test_collectIndices()
        {
            KnownAmountSwapLeg test = KnownAmountSwapLeg.builder().payReceive(PAY).accrualSchedule(PeriodicSchedule.builder().startDate(DATE_01_05).endDate(DATE_04_05).frequency(P1M).businessDayAdjustment(BusinessDayAdjustment.of(FOLLOWING, GBLO)).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(P1M).paymentDateOffset(DaysAdjustment.ofBusinessDays(2, GBLO)).build()).amount(ValueSchedule.of(123d)).currency(GBP).build();

            ImmutableSet.Builder <Index> builder = ImmutableSet.builder();
            test.collectIndices(builder);
            assertEquals(builder.build(), ImmutableSet.of());
            assertEquals(test.allIndices(), ImmutableSet.of());
        }
        //-------------------------------------------------------------------------
        public virtual void coverage()
        {
            KnownAmountSwapLeg test = KnownAmountSwapLeg.builder().payReceive(PAY).accrualSchedule(PeriodicSchedule.builder().startDate(DATE_01_05).endDate(DATE_04_05).frequency(P1M).businessDayAdjustment(BusinessDayAdjustment.of(FOLLOWING, GBLO)).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(P1M).paymentDateOffset(PLUS_TWO_DAYS).build()).amount(ValueSchedule.of(123d)).currency(GBP).build();

            coverImmutableBean(test);
            KnownAmountSwapLeg test2 = KnownAmountSwapLeg.builder().payReceive(RECEIVE).accrualSchedule(PeriodicSchedule.builder().startDate(DATE_02_05).endDate(DATE_03_05).frequency(P1M).businessDayAdjustment(BusinessDayAdjustment.of(FOLLOWING, GBLO)).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(P1M).paymentDateOffset(PLUS_THREE_DAYS).build()).amount(ValueSchedule.of(2000d)).currency(EUR).build();

            coverBeanEquals(test, test2);
        }
        //-------------------------------------------------------------------------
        public virtual void test_resolve()
        {
            // test case
            KnownAmountSwapLeg test = KnownAmountSwapLeg.builder().payReceive(PAY).accrualSchedule(PeriodicSchedule.builder().startDate(DATE_01_05).endDate(DATE_04_05).frequency(P1M).businessDayAdjustment(BusinessDayAdjustment.of(FOLLOWING, GBLO)).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(P1M).paymentDateOffset(PLUS_TWO_DAYS).build()).amount(ValueSchedule.builder().initialValue(123d).steps(ValueStep.of(1, ValueAdjustment.ofReplace(234d))).build()).currency(GBP).build();
            // expected
            KnownAmountSwapPaymentPeriod rpp1 = KnownAmountSwapPaymentPeriod.builder().payment(Payment.ofPay(CurrencyAmount.of(GBP, 123d), DATE_02_07)).startDate(DATE_01_06).endDate(DATE_02_05).unadjustedStartDate(DATE_01_05).build();
            KnownAmountSwapPaymentPeriod rpp2 = KnownAmountSwapPaymentPeriod.builder().payment(Payment.ofPay(CurrencyAmount.of(GBP, 234d), DATE_03_07)).startDate(DATE_02_05).endDate(DATE_03_05).build();
            KnownAmountSwapPaymentPeriod rpp3 = KnownAmountSwapPaymentPeriod.builder().payment(Payment.ofPay(CurrencyAmount.of(GBP, 234d), DATE_04_09)).startDate(DATE_03_05).endDate(DATE_04_07).unadjustedEndDate(DATE_04_05).build();

            // assertion
            assertEquals(test.resolve(REF_DATA), ResolvedSwapLeg.builder().type(FIXED).payReceive(PAY).paymentPeriods(rpp1, rpp2, rpp3).build());
        }
Exemplo n.º 4
0
 public override bool Equals(object obj)
 {
     if (obj == this)
     {
         return(true);
     }
     if (obj != null && obj.GetType() == this.GetType())
     {
         KnownAmountSwapLeg other = (KnownAmountSwapLeg)obj;
         return(JodaBeanUtils.equal(payReceive, other.payReceive) && JodaBeanUtils.equal(accrualSchedule, other.accrualSchedule) && JodaBeanUtils.equal(paymentSchedule, other.paymentSchedule) && JodaBeanUtils.equal(amount, other.amount) && JodaBeanUtils.equal(currency, other.currency));
     }
     return(false);
 }
        //-------------------------------------------------------------------------
        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));
        }
Exemplo n.º 6
0
        // a summary of the leg
        private string legSummary(SwapLeg leg)
        {
            if (leg is RateCalculationSwapLeg)
            {
                RateCalculationSwapLeg rcLeg       = (RateCalculationSwapLeg)leg;
                RateCalculation        calculation = rcLeg.Calculation;
                if (calculation is FixedRateCalculation)
                {
                    FixedRateCalculation calc = (FixedRateCalculation)calculation;
                    string vary = calc.Rate.Steps.Count > 0 || calc.Rate.StepSequence.Present ? " variable" : "";
                    return(SummarizerUtils.percent(calc.Rate.InitialValue) + vary);
                }
                if (calculation is IborRateCalculation)
                {
                    IborRateCalculation calc = (IborRateCalculation)calculation;
                    string gearing           = calc.Gearing.map(g => " * " + SummarizerUtils.value(g.InitialValue)).orElse("");
                    string spread            = calc.Spread.map(s => " + " + SummarizerUtils.percent(s.InitialValue)).orElse("");
                    return(calc.Index.Name + gearing + spread);
                }
                if (calculation is OvernightRateCalculation)
                {
                    OvernightRateCalculation calc = (OvernightRateCalculation)calculation;
                    string avg     = calc.AccrualMethod == OvernightAccrualMethod.AVERAGED ? " avg" : "";
                    string gearing = calc.Gearing.map(g => " * " + SummarizerUtils.value(g.InitialValue)).orElse("");
                    string spread  = calc.Spread.map(s => " + " + SummarizerUtils.percent(s.InitialValue)).orElse("");
                    return(calc.Index.Name + avg + gearing + spread);
                }
                if (calculation is InflationRateCalculation)
                {
                    InflationRateCalculation calc = (InflationRateCalculation)calculation;
                    string gearing = calc.Gearing.map(g => " * " + SummarizerUtils.value(g.InitialValue)).orElse("");
                    return(calc.Index.Name + gearing);
                }
            }
            if (leg is KnownAmountSwapLeg)
            {
                KnownAmountSwapLeg kaLeg = (KnownAmountSwapLeg)leg;
                string             vary  = kaLeg.Amount.Steps.Count > 0 || kaLeg.Amount.StepSequence.Present ? " variable" : "";
                return(SummarizerUtils.amount(kaLeg.Currency, kaLeg.Amount.InitialValue) + vary);
            }
            ImmutableSet <Index> allIndices = leg.allIndices();

            return(allIndices.Empty ? "Fixed" : allIndices.ToString());
        }
Exemplo n.º 7
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");
        }
        public virtual void test_serialization()
        {
            KnownAmountSwapLeg test = KnownAmountSwapLeg.builder().payReceive(PAY).accrualSchedule(PeriodicSchedule.builder().startDate(DATE_01_05).endDate(DATE_04_05).frequency(P1M).businessDayAdjustment(BusinessDayAdjustment.of(FOLLOWING, GBLO)).build()).paymentSchedule(PaymentSchedule.builder().paymentFrequency(P1M).paymentDateOffset(DaysAdjustment.ofBusinessDays(2, GBLO)).build()).amount(ValueSchedule.of(123d)).currency(GBP).build();

            assertSerialization(test);
        }