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); }
//------------------------------------------------------------------------- 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)); }
//------------------------------------------------------------------------- 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); }
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)); }
//------------------------------------------------------------------------- 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); }
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)); }
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); }
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); }
//------------------------------------------------------------------------- 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()); }
public virtual void test_serialization() { InflationRateCalculation test1 = InflationRateCalculation.builder().index(CH_CPI).lag(Period.ofMonths(3)).indexCalculationMethod(MONTHLY).build(); assertSerialization(test1); }
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)); }
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()); }
public virtual void test_builder_missing_index() { assertThrowsIllegalArg(() => InflationRateCalculation.builder().build()); }