//-------------------------------------------------------------------------
        public virtual void test_collectIndices()
        {
            OvernightRateCalculation test = OvernightRateCalculation.builder().dayCount(ACT_365F).index(GBP_SONIA).build();

            ImmutableSet.Builder <Index> builder = ImmutableSet.builder();
            test.collectIndices(builder);
            assertEquals(builder.build(), ImmutableSet.of(GBP_SONIA));
        }
        //-------------------------------------------------------------------------
        public virtual void coverage()
        {
            OvernightRateCalculation test = OvernightRateCalculation.builder().dayCount(ACT_365F).index(GBP_SONIA).build();

            coverImmutableBean(test);
            OvernightRateCalculation test2 = OvernightRateCalculation.builder().dayCount(ACT_360).index(USD_FED_FUND).accrualMethod(AVERAGED).negativeRateMethod(NOT_NEGATIVE).rateCutOffDays(2).gearing(ValueSchedule.of(2d)).spread(ValueSchedule.of(-0.025d)).build();

            coverBeanEquals(test, test2);
        }
        public virtual void test_expand_gearingSpreadEverythingElse()
        {
            OvernightRateCalculation          test    = OvernightRateCalculation.builder().dayCount(ACT_365F).index(GBP_SONIA).accrualMethod(AVERAGED).negativeRateMethod(NOT_NEGATIVE).rateCutOffDays(2).gearing(ValueSchedule.of(1d, ValueStep.of(2, ValueAdjustment.ofReplace(2d)))).spread(ValueSchedule.of(0d, ValueStep.of(1, ValueAdjustment.ofReplace(-0.025d)))).build();
            RateAccrualPeriod                 rap1    = RateAccrualPeriod.builder(ACCRUAL1).yearFraction(ACCRUAL1.yearFraction(ACT_365F, ACCRUAL_SCHEDULE)).rateComputation(OvernightAveragedRateComputation.of(GBP_SONIA, DATE_01_06, DATE_02_05, 0, REF_DATA)).negativeRateMethod(NOT_NEGATIVE).build();
            RateAccrualPeriod                 rap2    = RateAccrualPeriod.builder(ACCRUAL2).yearFraction(ACCRUAL2.yearFraction(ACT_365F, ACCRUAL_SCHEDULE)).rateComputation(OvernightAveragedRateComputation.of(GBP_SONIA, DATE_02_05, DATE_03_05, 0, REF_DATA)).negativeRateMethod(NOT_NEGATIVE).spread(-0.025d).build();
            RateAccrualPeriod                 rap3    = RateAccrualPeriod.builder(ACCRUAL3).yearFraction(ACCRUAL3.yearFraction(ACT_365F, ACCRUAL_SCHEDULE)).rateComputation(OvernightAveragedRateComputation.of(GBP_SONIA, DATE_03_05, DATE_04_07, 2, REF_DATA)).negativeRateMethod(NOT_NEGATIVE).gearing(2d).spread(-0.025d).build();
            ImmutableList <RateAccrualPeriod> periods = test.createAccrualPeriods(ACCRUAL_SCHEDULE, PAYMENT_SCHEDULE, REF_DATA);

            assertEquals(periods, ImmutableList.of(rap1, rap2, rap3));
        }
        public virtual void test_expand_rateCutOffDays_threeAccrualsInPaymentPeriod()
        {
            OvernightRateCalculation          test    = OvernightRateCalculation.builder().dayCount(ACT_365F).index(GBP_SONIA).rateCutOffDays(2).build();
            RateAccrualPeriod                 rap1    = RateAccrualPeriod.builder(ACCRUAL1).yearFraction(ACCRUAL1.yearFraction(ACT_365F, ACCRUAL_SCHEDULE)).rateComputation(OvernightCompoundedRateComputation.of(GBP_SONIA, DATE_01_06, DATE_02_05, 0, REF_DATA)).build();
            RateAccrualPeriod                 rap2    = RateAccrualPeriod.builder(ACCRUAL2).yearFraction(ACCRUAL2.yearFraction(ACT_365F, ACCRUAL_SCHEDULE)).rateComputation(OvernightCompoundedRateComputation.of(GBP_SONIA, DATE_02_05, DATE_03_05, 0, REF_DATA)).build();
            RateAccrualPeriod                 rap3    = RateAccrualPeriod.builder(ACCRUAL3).yearFraction(ACCRUAL3.yearFraction(ACT_365F, ACCRUAL_SCHEDULE)).rateComputation(OvernightCompoundedRateComputation.of(GBP_SONIA, DATE_03_05, DATE_04_07, 2, REF_DATA)).build();
            ImmutableList <RateAccrualPeriod> periods = test.createAccrualPeriods(ACCRUAL_SCHEDULE, PAYMENT_SCHEDULE, REF_DATA);

            assertEquals(periods, ImmutableList.of(rap1, rap2, rap3));
        }
        public virtual void test_expand_tomNext()
        {
            OvernightRateCalculation          test    = OvernightRateCalculation.builder().dayCount(ACT_360).index(CHF_TOIS).build();
            RateAccrualPeriod                 rap1    = RateAccrualPeriod.builder(ACCRUAL1).yearFraction(ACCRUAL1.yearFraction(ACT_360, ACCRUAL_SCHEDULE)).rateComputation(OvernightCompoundedRateComputation.of(CHF_TOIS, DATE_01_06, DATE_02_05, 0, REF_DATA)).build();
            RateAccrualPeriod                 rap2    = RateAccrualPeriod.builder(ACCRUAL2).yearFraction(ACCRUAL2.yearFraction(ACT_360, ACCRUAL_SCHEDULE)).rateComputation(OvernightCompoundedRateComputation.of(CHF_TOIS, DATE_02_05, DATE_03_05, 0, REF_DATA)).build();
            RateAccrualPeriod                 rap3    = RateAccrualPeriod.builder(ACCRUAL3).yearFraction(ACCRUAL3.yearFraction(ACT_360, ACCRUAL_SCHEDULE)).rateComputation(OvernightCompoundedRateComputation.of(CHF_TOIS, DATE_03_05, DATE_04_07, 0, REF_DATA)).build();
            ImmutableList <RateAccrualPeriod> periods = test.createAccrualPeriods(ACCRUAL_SCHEDULE, ACCRUAL_SCHEDULE, REF_DATA);

            assertEquals(periods, ImmutableList.of(rap1, rap2, rap3));
        }
        public virtual void test_builder_ensureDefaults()
        {
            OvernightRateCalculation test = OvernightRateCalculation.builder().index(GBP_SONIA).build();

            assertEquals(test.DayCount, ACT_365F);
            assertEquals(test.Index, GBP_SONIA);
            assertEquals(test.AccrualMethod, COMPOUNDED);
            assertEquals(test.NegativeRateMethod, ALLOW_NEGATIVE);
            assertEquals(test.RateCutOffDays, 0);
            assertEquals(test.Gearing, null);
            assertEquals(test.Spread, null);
        }
Beispiel #7
0
 public override bool Equals(object obj)
 {
     if (obj == this)
     {
         return(true);
     }
     if (obj != null && obj.GetType() == this.GetType())
     {
         OvernightRateCalculation other = (OvernightRateCalculation)obj;
         return(JodaBeanUtils.equal(dayCount, other.dayCount) && JodaBeanUtils.equal(index, other.index) && JodaBeanUtils.equal(accrualMethod, other.accrualMethod) && JodaBeanUtils.equal(negativeRateMethod, other.negativeRateMethod) && (rateCutOffDays == other.rateCutOffDays) && JodaBeanUtils.equal(gearing, other.gearing) && JodaBeanUtils.equal(spread, other.spread));
     }
     return(false);
 }
        //-------------------------------------------------------------------------
        public virtual void test_of()
        {
            OvernightRateCalculation test = OvernightRateCalculation.of(GBP_SONIA);

            assertEquals(test.Type, SwapLegType.OVERNIGHT);
            assertEquals(test.DayCount, ACT_365F);
            assertEquals(test.Index, GBP_SONIA);
            assertEquals(test.AccrualMethod, COMPOUNDED);
            assertEquals(test.NegativeRateMethod, ALLOW_NEGATIVE);
            assertEquals(test.RateCutOffDays, 0);
            assertEquals(test.Gearing, null);
            assertEquals(test.Spread, null);
        }
        // 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());
        }
Beispiel #10
0
 //-------------------------------------------------------------------------
 /// <summary>
 /// Obtains a rate calculation for the specified index with accrual by compounding.
 /// <para>
 /// The calculation will use the day count of the index.
 /// All optional fields will be set to their default values.
 /// Thus, there will be no spread, gearing or rate cut-off.
 /// If this method provides insufficient control, use the <seealso cref="#builder() builder"/>.
 ///
 /// </para>
 /// </summary>
 /// <param name="index">  the index </param>
 /// <returns> the calculation </returns>
 public static OvernightRateCalculation of(OvernightIndex index)
 {
     return(OvernightRateCalculation.builder().index(index).build());
 }
        public virtual void test_serialization()
        {
            OvernightRateCalculation test = OvernightRateCalculation.builder().dayCount(ACT_365F).index(GBP_SONIA).build();

            assertSerialization(test);
        }
 public virtual void test_builder_noIndex()
 {
     assertThrowsIllegalArg(() => OvernightRateCalculation.builder().build());
 }