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);
        }
Esempio n. 2
0
        //-------------------------------------------------------------------------
        public virtual void test_collectIndices()
        {
            InflationRateCalculation test = InflationRateCalculation.builder().index(GB_HICP).lag(Period.ofMonths(3)).indexCalculationMethod(MONTHLY).build();

            ImmutableSet.Builder <Index> builder = ImmutableSet.builder();
            test.collectIndices(builder);
            assertEquals(builder.build(), ImmutableSet.of(GB_HICP));
        }
Esempio n. 3
0
        //-------------------------------------------------------------------------
        public virtual void coverage()
        {
            InflationRateCalculation test1 = InflationRateCalculation.builder().index(CH_CPI).lag(Period.ofMonths(3)).indexCalculationMethod(MONTHLY).build();

            coverImmutableBean(test1);
            InflationRateCalculation test2 = InflationRateCalculation.builder().index(GB_HICP).lag(Period.ofMonths(4)).indexCalculationMethod(INTERPOLATED).gearing(GEARING).build();

            coverBeanEquals(test1, test2);
        }
Esempio n. 4
0
        public virtual void test_createAccrualPeriods_Monthly_firstKnown()
        {
            InflationRateCalculation          test    = InflationRateCalculation.builder().index(GB_HICP).lag(Period.ofMonths(3)).indexCalculationMethod(MONTHLY).firstIndexValue(123d).build();
            RateAccrualPeriod                 rap1    = RateAccrualPeriod.builder(ACCRUAL1).yearFraction(1.0).rateComputation(InflationEndMonthRateComputation.of(GB_HICP, 123d, YearMonth.from(DATE_2015_02_05).minusMonths(3))).build();
            RateAccrualPeriod                 rap2    = RateAccrualPeriod.builder(ACCRUAL2).yearFraction(1.0).rateComputation(InflationMonthlyRateComputation.of(GB_HICP, YearMonth.from(DATE_2015_02_05).minusMonths(3), YearMonth.from(DATE_2015_03_07).minusMonths(3))).build();
            RateAccrualPeriod                 rap3    = RateAccrualPeriod.builder(ACCRUAL3).yearFraction(1.0).rateComputation(InflationMonthlyRateComputation.of(GB_HICP, YearMonth.from(DATE_2015_03_07).minusMonths(3), YearMonth.from(DATE_2015_04_05).minusMonths(3))).build();
            ImmutableList <RateAccrualPeriod> periods = test.createAccrualPeriods(ACCRUAL_SCHEDULE, ACCRUAL_SCHEDULE, REF_DATA);

            assertEquals(periods, ImmutableList.of(rap1, rap2, rap3));
        }
Esempio n. 5
0
        //-------------------------------------------------------------------------
        public virtual void test_createRateComputation_Monthly()
        {
            InflationRateCalculation         test = InflationRateCalculation.builder().index(GB_HICP).lag(Period.ofMonths(3)).indexCalculationMethod(MONTHLY).firstIndexValue(START_INDEX).build();
            InflationEndMonthRateComputation obs1 = InflationEndMonthRateComputation.of(GB_HICP, START_INDEX, YearMonth.from(DATE_2015_02_05).minusMonths(3));
            InflationEndMonthRateComputation obs2 = InflationEndMonthRateComputation.of(GB_HICP, START_INDEX, YearMonth.from(DATE_2015_03_07).minusMonths(3));
            InflationEndMonthRateComputation obs3 = InflationEndMonthRateComputation.of(GB_HICP, START_INDEX, YearMonth.from(DATE_2015_04_05).minusMonths(3));

            assertEquals(test.createRateComputation(DATE_2015_02_05), obs1);
            assertEquals(test.createRateComputation(DATE_2015_03_07), obs2);
            assertEquals(test.createRateComputation(DATE_2015_04_05), obs3);
        }
Esempio n. 6
0
        public virtual void test_of_firstIndexValue()
        {
            InflationRateCalculation test1 = InflationRateCalculation.of(CH_CPI, 3, MONTHLY, 123d);

            assertEquals(test1.Index, CH_CPI);
            assertEquals(test1.Lag, Period.ofMonths(3));
            assertEquals(test1.IndexCalculationMethod, MONTHLY);
            assertEquals(test1.FirstIndexValue, double?.of(123d));
            assertEquals(test1.Gearing, null);
            assertEquals(test1.Type, SwapLegType.INFLATION);
        }
 public override bool Equals(object obj)
 {
     if (obj == this)
     {
         return(true);
     }
     if (obj != null && obj.GetType() == this.GetType())
     {
         InflationRateCalculation other = (InflationRateCalculation)obj;
         return(JodaBeanUtils.equal(index, other.index) && JodaBeanUtils.equal(lag, other.lag) && JodaBeanUtils.equal(indexCalculationMethod, other.indexCalculationMethod) && JodaBeanUtils.equal(firstIndexValue, other.firstIndexValue) && JodaBeanUtils.equal(gearing, other.gearing));
     }
     return(false);
 }
Esempio n. 8
0
        public virtual void test_createAccrualPeriods_Interpolated()
        {
            InflationRateCalculation test             = InflationRateCalculation.builder().index(CH_CPI).lag(Period.ofMonths(3)).indexCalculationMethod(INTERPOLATED).build();
            double            weight1                 = 1.0 - 4.0 / 28.0;
            double            weight2                 = 1.0 - 6.0 / 31.0;
            double            weight3                 = 1.0 - 4.0 / 30.0;
            RateAccrualPeriod rap1                    = RateAccrualPeriod.builder(ACCRUAL1).yearFraction(1.0).rateComputation(InflationInterpolatedRateComputation.of(CH_CPI, YearMonth.from(DATE_2015_01_05).minusMonths(3), YearMonth.from(DATE_2015_02_05).minusMonths(3), weight1)).build();
            RateAccrualPeriod rap2                    = RateAccrualPeriod.builder(ACCRUAL2).yearFraction(1.0).rateComputation(InflationInterpolatedRateComputation.of(CH_CPI, YearMonth.from(DATE_2015_02_05).minusMonths(3), YearMonth.from(DATE_2015_03_07).minusMonths(3), weight2)).build();
            RateAccrualPeriod rap3                    = RateAccrualPeriod.builder(ACCRUAL3).yearFraction(1.0).rateComputation(InflationInterpolatedRateComputation.of(CH_CPI, YearMonth.from(DATE_2015_03_07).minusMonths(3), YearMonth.from(DATE_2015_04_05).minusMonths(3), weight3)).build();
            ImmutableList <RateAccrualPeriod> periods = test.createAccrualPeriods(ACCRUAL_SCHEDULE, ACCRUAL_SCHEDULE, REF_DATA);

            assertEquals(periods, ImmutableList.of(rap1, rap2, rap3));
        }
Esempio n. 9
0
        public virtual void test_createRateComputation_Interpolated()
        {
            InflationRateCalculation test = InflationRateCalculation.builder().index(CH_CPI).lag(Period.ofMonths(3)).indexCalculationMethod(INTERPOLATED).firstIndexValue(START_INDEX).build();
            double weight1 = 1.0 - 4.0 / 28.0;
            double weight2 = 1.0 - 6.0 / 31.0;
            double weight3 = 1.0 - 4.0 / 30.0;
            InflationEndInterpolatedRateComputation obs1 = InflationEndInterpolatedRateComputation.of(CH_CPI, START_INDEX, YearMonth.from(DATE_2015_02_05).minusMonths(3), weight1);
            InflationEndInterpolatedRateComputation obs2 = InflationEndInterpolatedRateComputation.of(CH_CPI, START_INDEX, YearMonth.from(DATE_2015_03_07).minusMonths(3), weight2);
            InflationEndInterpolatedRateComputation obs3 = InflationEndInterpolatedRateComputation.of(CH_CPI, START_INDEX, YearMonth.from(DATE_2015_04_05).minusMonths(3), weight3);

            assertEquals(test.createRateComputation(DATE_2015_02_05), obs1);
            assertEquals(test.createRateComputation(DATE_2015_03_07), obs2);
            assertEquals(test.createRateComputation(DATE_2015_04_05), obs3);
        }
Esempio n. 10
0
        public virtual void test_createRateComputation_InterpolatedJapan()
        {
            LocalDate date1 = LocalDate.of(2013, 3, 9);
            LocalDate date2 = LocalDate.of(2013, 3, 10);
            LocalDate date3 = LocalDate.of(2013, 3, 11);
            InflationRateCalculation test = InflationRateCalculation.builder().index(JP_CPI_EXF).lag(Period.ofMonths(3)).indexCalculationMethod(INTERPOLATED_JAPAN).firstIndexValue(START_INDEX).build();
            double weight1 = 1.0 - (9.0 + 28.0 - 10.0) / 28.0;
            double weight2 = 1.0;
            double weight3 = 1.0 - 1.0 / 31.0;
            InflationEndInterpolatedRateComputation obs1 = InflationEndInterpolatedRateComputation.of(JP_CPI_EXF, START_INDEX, YearMonth.from(date1).minusMonths(4), weight1);
            InflationEndInterpolatedRateComputation obs2 = InflationEndInterpolatedRateComputation.of(JP_CPI_EXF, START_INDEX, YearMonth.from(date2).minusMonths(3), weight2);
            InflationEndInterpolatedRateComputation obs3 = InflationEndInterpolatedRateComputation.of(JP_CPI_EXF, START_INDEX, YearMonth.from(date3).minusMonths(3), weight3);

            assertEquals(test.createRateComputation(date1), obs1);
            assertEquals(test.createRateComputation(date2), obs2);
            assertEquals(test.createRateComputation(date3), obs3);
        }
Esempio n. 11
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());
        }
Esempio n. 12
0
        //-------------------------------------------------------------------------
        public virtual void test_builder()
        {
            InflationRateCalculation test1 = InflationRateCalculation.builder().index(CH_CPI).lag(Period.ofMonths(3)).indexCalculationMethod(MONTHLY).firstIndexValue(123d).build();

            assertEquals(test1.Index, CH_CPI);
            assertEquals(test1.Lag, Period.ofMonths(3));
            assertEquals(test1.IndexCalculationMethod, MONTHLY);
            assertEquals(test1.Gearing, null);
            assertEquals(test1.FirstIndexValue, double?.of(123d));
            assertEquals(test1.Type, SwapLegType.INFLATION);
            InflationRateCalculation test2 = InflationRateCalculation.builder().index(GB_HICP).lag(Period.ofMonths(4)).indexCalculationMethod(INTERPOLATED).gearing(GEARING).build();

            assertEquals(test2.Index, GB_HICP);
            assertEquals(test2.Lag, Period.ofMonths(4));
            assertEquals(test2.IndexCalculationMethod, INTERPOLATED);
            assertEquals(test2.FirstIndexValue, double?.empty());
            assertEquals(test2.Gearing.get(), GEARING);
            assertEquals(test2.Type, SwapLegType.INFLATION);
        }
 /// <summary>
 /// Obtains a rate calculation for the specified price index with known start index value.
 /// <para>
 /// The calculation will use the specified month lag.
 /// The first index value will be set to the specified value
 /// All other optional fields will be set to their default values.
 /// Thus, fixing will be in advance, with no gearing.
 /// If this method provides insufficient control, use the <seealso cref="#builder() builder"/>.
 ///
 /// </para>
 /// </summary>
 /// <param name="index">  the price index </param>
 /// <param name="monthLag">  the month lag </param>
 /// <param name="indexCalculationMethod">  the reference price index calculation method </param>
 /// <param name="firstIndexValue">  the first index value </param>
 /// <returns> the inflation rate calculation </returns>
 public static InflationRateCalculation of(PriceIndex index, int monthLag, PriceIndexCalculationMethod indexCalculationMethod, double firstIndexValue)
 {
     return(InflationRateCalculation.builder().index(index).lag(Period.ofMonths(monthLag)).indexCalculationMethod(indexCalculationMethod).firstIndexValue(firstIndexValue).build());
 }
Esempio n. 14
0
        public virtual void test_serialization()
        {
            InflationRateCalculation test1 = InflationRateCalculation.builder().index(CH_CPI).lag(Period.ofMonths(3)).indexCalculationMethod(MONTHLY).build();

            assertSerialization(test1);
        }
Esempio n. 15
0
 public virtual void test_builder_missing_index()
 {
     assertThrowsIllegalArg(() => InflationRateCalculation.builder().build());
 }
Esempio n. 16
0
        public virtual void test_createRateComputation_noFirstIndexValue()
        {
            InflationRateCalculation test = InflationRateCalculation.builder().index(CH_CPI).lag(Period.ofMonths(3)).indexCalculationMethod(INTERPOLATED).build();

            assertThrows(() => test.createRateComputation(DATE_2015_04_05), typeof(System.InvalidOperationException));
        }
Esempio n. 17
0
 public virtual void test_builder_badLag()
 {
     assertThrowsIllegalArg(() => InflationRateCalculation.builder().index(GB_HICP).lag(Period.ZERO).build());
     assertThrowsIllegalArg(() => InflationRateCalculation.builder().index(GB_HICP).lag(Period.ofMonths(-1)).build());
 }