InflationRateCalculation.Builder builder = InflationRateCalculation.builder(); builder.index(document.parsePriceIndex(inflationEl)); builder.lag(document.parsePeriod(inflationEl.getChild("inflationLag"))); builder.indexCalculationMethod(interpStr.toLowerCase(Locale.ENGLISH).contains("linear") ? PriceIndexCalculationMethod.INTERPOLATED : PriceIndexCalculationMethod.MONTHLY); builder.firstIndexValue(document.parseDecimal(el)); }); builder.gearing(parseSchedule(el, document)); }); return builder.build();
.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()
.build(); InflationRateCalculation rateCalc = InflationRateCalculation.builder() .index(GB_RPI) .indexCalculationMethod(MONTHLY) .lag(Period.ofMonths(3)) .build(); NotionalSchedule notionalSchedule = NotionalSchedule.of(GBP, 1000d); RateCalculationSwapLeg test = RateCalculationSwapLeg.builder()
.notionalSchedule(notional) .calculation(InflationRateCalculation.builder() .index(PriceIndices.US_CPI_U) .lag(Period.ofMonths(3)) .indexCalculationMethod(PriceIndexCalculationMethod.INTERPOLATED) .build()) .build(); assertEqualsBean((Bean) swap.getLegs().get(0), payLeg);
.build()) .calculation(InflationRateCalculation.builder() .index(index) .indexCalculationMethod(indexCalculationMethod) .lag(lag) .build()) .notionalSchedule(NotionalSchedule.of(getCurrency(), notional)) .build();
public 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;
public 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)
public void test_createAccrualPeriods_Monthly() { InflationRateCalculation test = InflationRateCalculation.builder() .index(GB_HICP) .lag(Period.ofMonths(3)) .indexCalculationMethod(MONTHLY) .build(); RateAccrualPeriod rap1 = RateAccrualPeriod.builder(ACCRUAL1) .yearFraction(1.0)
private SwapLeg createInflationSwapLeg(boolean interpolated, PayReceive pay) { BusinessDayAdjustment adj = BusinessDayAdjustment.of(FOLLOWING, GBLO); PeriodicSchedule accrualSchedule = PeriodicSchedule.builder() .startDate(DATE_14_06_09) .endDate(DATE_19_06_09) .frequency(Frequency.ofYears(5)) .businessDayAdjustment(adj) .build(); PaymentSchedule paymentSchedule = PaymentSchedule.builder() .paymentFrequency(Frequency.ofYears(5)) .paymentDateOffset(DaysAdjustment.ofBusinessDays(2, GBLO)) .build(); InflationRateCalculation rateCalc = InflationRateCalculation.builder() .index(GB_RPI) .indexCalculationMethod(interpolated ? INTERPOLATED : MONTHLY) .lag(Period.ofMonths(3)) .build(); NotionalSchedule notionalSchedule = NotionalSchedule.of(GBP, NOTIONAL); SwapLeg swapLeg = RateCalculationSwapLeg.builder() .payReceive(pay) .accrualSchedule(accrualSchedule) .paymentSchedule(paymentSchedule) .notionalSchedule(notionalSchedule) .calculation(rateCalc) .build(); return swapLeg; }
public 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 void test_builder() { InflationRateCalculation test1 = InflationRateCalculation.builder() .index(CH_CPI) .lag(Period.ofMonths(3)) .indexCalculationMethod(MONTHLY) .firstIndexValue(123d) .build(); assertEquals(test1.getIndex(), CH_CPI); assertEquals(test1.getLag(), Period.ofMonths(3)); assertEquals(test1.getIndexCalculationMethod(), MONTHLY); assertEquals(test1.getGearing(), Optional.empty()); assertEquals(test1.getFirstIndexValue(), OptionalDouble.of(123d)); assertEquals(test1.getType(), SwapLegType.INFLATION); InflationRateCalculation test2 = InflationRateCalculation.builder() .index(GB_HICP) .lag(Period.ofMonths(4)) .indexCalculationMethod(INTERPOLATED) .gearing(GEARING) .build(); assertEquals(test2.getIndex(), GB_HICP); assertEquals(test2.getLag(), Period.ofMonths(4)); assertEquals(test2.getIndexCalculationMethod(), INTERPOLATED); assertEquals(test2.getFirstIndexValue(), OptionalDouble.empty()); assertEquals(test2.getGearing().get(), GEARING); assertEquals(test2.getType(), SwapLegType.INFLATION); }
static CapitalIndexedBond sut2() { return CapitalIndexedBond.builder() .securityId(SECURITY_ID2) .notional(5.0e7) .currency(GBP) .dayCount(NL_365) .rateCalculation( InflationRateCalculation.builder() .index(GB_RPI) .lag(Period.ofMonths(2)) .indexCalculationMethod(INTERPOLATED) .firstIndexValue(124.556) .build()) .exCouponPeriod(EX_COUPON) .legalEntityId(LegalEntityId.of("OG-Ticker", "US-Govt-1")) .yieldConvention(GB_IL_FLOAT) .settlementDateOffset(DaysAdjustment.ofBusinessDays(2, GBLO)) .accrualSchedule( PeriodicSchedule.of( START, END, FREQUENCY, BusinessDayAdjustment.of(BusinessDayConventions.FOLLOWING, GBLO), StubConvention.NONE, RollConventions.NONE)) .build(); }
/** * Obtains a rate calculation for the specified price index with known start index value. * <p> * 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 {@linkplain #builder() builder}. * * @param index the price index * @param monthLag the month lag * @param indexCalculationMethod the reference price index calculation method * @param firstIndexValue the first index value * @return the inflation rate calculation */ 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(); }
/** * Obtains a rate calculation for the specified price index. * <p> * The calculation will use the specified month lag. * All 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 {@linkplain #builder() builder}. * * @param index the price index * @param monthLag the month lag * @param indexCalculationMethod the reference price index calculation method * @return the inflation rate calculation */ public static InflationRateCalculation of( PriceIndex index, int monthLag, PriceIndexCalculationMethod indexCalculationMethod) { return InflationRateCalculation.builder() .index(index) .lag(Period.ofMonths(monthLag)) .indexCalculationMethod(indexCalculationMethod) .build(); }
public 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 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 void test_builder_missing_index() { assertThrowsIllegalArg(() -> InflationRateCalculation.builder().build()); }
public 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); }
private static RateCalculation parseInflationRateCalculation(CsvRow row, String leg, PriceIndex priceIndex, Currency currency) { InflationRateCalculation.Builder builder = InflationRateCalculation.builder(); // basics builder.index(priceIndex); builder.lag(parseInflationLag(findValue(row, leg, INFLATION_LAG_FIELD), currency)); builder.indexCalculationMethod(parseInflationMethod(findValue(row, leg, INFLATION_METHOD_FIELD), currency)); // optionals findValue(row, leg, INFLATION_FIRST_INDEX_VALUE_FIELD) .map(s -> LoaderUtils.parseDouble(s)) .ifPresent(v -> builder.firstIndexValue(v)); findValue(row, leg, GEARING_FIELD) .map(s -> LoaderUtils.parseDouble(s)) .ifPresent(v -> builder.gearing(ValueSchedule.of(v))); return builder.build(); }