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); }
@Override public ImmutableList<RateAccrualPeriod> createAccrualPeriods( Schedule accrualSchedule, Schedule paymentSchedule, ReferenceData refData) { // resolve data by schedule DoubleArray resolvedGearings = firstNonNull(gearing, ALWAYS_1).resolveValues(accrualSchedule); // build accrual periods ImmutableList.Builder<RateAccrualPeriod> accrualPeriods = ImmutableList.builder(); for (int i = 0; i < accrualSchedule.size(); i++) { SchedulePeriod period = accrualSchedule.getPeriod(i); // inflation does not use a day count, so year fraction is 1d accrualPeriods.add(new RateAccrualPeriod( period, 1d, createRateComputation(period, i), resolvedGearings.get(i), 0d, NegativeRateMethod.ALLOW_NEGATIVE)); } return accrualPeriods.build(); }
/** * Restricted copy constructor. * @param beanToCopy the bean to copy from, not null */ private Builder(InflationRateCalculation beanToCopy) { this.index = beanToCopy.getIndex(); this.lag = beanToCopy.getLag(); this.indexCalculationMethod = beanToCopy.getIndexCalculationMethod(); this.firstIndexValue = beanToCopy.firstIndexValue; this.gearing = beanToCopy.gearing; }
public void test_of() { InflationRateCalculation test1 = InflationRateCalculation.of(CH_CPI, 3, MONTHLY); assertEquals(test1.getIndex(), CH_CPI); assertEquals(test1.getLag(), Period.ofMonths(3)); assertEquals(test1.getIndexCalculationMethod(), MONTHLY); assertEquals(test1.getFirstIndexValue(), OptionalDouble.empty()); assertEquals(test1.getGearing(), Optional.empty()); assertEquals(test1.getType(), SwapLegType.INFLATION); }
public 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 void test_builder_missing_index() { assertThrowsIllegalArg(() -> InflationRateCalculation.builder().build()); }
public 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), IllegalStateException.class); }
public void test_createAccrualPeriods_Monthly_firstKnown() { InflationRateCalculation test = InflationRateCalculation.builder() .index(GB_HICP) .lag(Period.ofMonths(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));
DateAdjuster exCouponPeriodAdjuster = exCouponPeriod.resolve(refData); DoubleArray resolvedGearings = rateCalculation.getGearing().orElse(ALWAYS_1).resolveValues(adjustedSchedule); ImmutableList.Builder<CapitalIndexedBondPaymentPeriod> bondPeriodsBuilder = ImmutableList.builder(); .notional(notional) .currency(currency) .rateComputation(rateCalculation.createRateComputation(period.getEndDate())) .realCoupon(resolvedGearings.get(i)) .build());
String gearing = calc.getGearing().map(g -> " * " + SummarizerUtils.value(g.getInitialValue())).orElse(""); return calc.getIndex().getName() + gearing;
/** * Gets the first index value * <p> * This is the price index value at the start of the bond. * * @return the first index value */ public double getFirstIndexValue() { return rateCalculation.getFirstIndexValue().getAsDouble(); // validated in constructor }
if (yieldConvention.equals(CapitalIndexedBondYieldConvention.GB_IL_FLOAT)) { RateComputation obs = period.getRateComputation(); LocalDateDoubleTimeSeries ts = ratesProvider.priceIndexValues(bond.getRateCalculation().getIndex()).getFixings(); YearMonth lastKnownFixingMonth = YearMonth.from(ts.getLatestDate()); double indexRatio = ts.getLatestValue() / bond.getFirstIndexValue();
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(); }
public void test_of_firstIndexValue() { InflationRateCalculation test1 = InflationRateCalculation.of(CH_CPI, 3, MONTHLY, 123d); assertEquals(test1.getIndex(), CH_CPI); assertEquals(test1.getLag(), Period.ofMonths(3)); assertEquals(test1.getIndexCalculationMethod(), MONTHLY); assertEquals(test1.getFirstIndexValue(), OptionalDouble.of(123d)); assertEquals(test1.getGearing(), Optional.empty()); assertEquals(test1.getType(), SwapLegType.INFLATION); }
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_createAccrualPeriods_Monthly() { InflationRateCalculation test = InflationRateCalculation.builder() .index(GB_HICP) .lag(Period.ofMonths(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));
@Override protected Object propertyGet(Bean bean, String propertyName, boolean quiet) { switch (propertyName.hashCode()) { case 100346066: // index return ((InflationRateCalculation) bean).getIndex(); case 106898: // lag return ((InflationRateCalculation) bean).getLag(); case -1409010088: // indexCalculationMethod return ((InflationRateCalculation) bean).getIndexCalculationMethod(); case 922631823: // firstIndexValue return ((InflationRateCalculation) bean).firstIndexValue; case -91774989: // gearing return ((InflationRateCalculation) bean).gearing; } return super.propertyGet(bean, propertyName, quiet); }
/** * Gets the first index value * <p> * This is the price index value at the start of the bond. * * @return the first index value */ public double getFirstIndexValue() { return rateCalculation.getFirstIndexValue().getAsDouble(); // validated in constructor }
/** * 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_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); }