public void test_of() { InflationEndInterpolatedRateComputation test = InflationEndInterpolatedRateComputation.of( GB_HICP, START_INDEX, END_MONTH_FIRST, WEIGHT); assertEquals(test.getIndex(), GB_HICP); assertEquals(test.getEndObservation().getFixingMonth(), END_MONTH_FIRST); assertEquals(test.getEndSecondObservation().getFixingMonth(), END_MONTH_SECOND); assertEquals(test.getStartIndexValue(), START_INDEX); assertEquals(test.getWeight(), WEIGHT, 1.0e-14); }
@Override public InflationEndInterpolatedRateComputation build() { return new InflationEndInterpolatedRateComputation( startIndexValue, endObservation, endSecondObservation, weight); }
@Override protected Object propertyGet(Bean bean, String propertyName, boolean quiet) { switch (propertyName.hashCode()) { case -1656407615: // startIndexValue return ((InflationEndInterpolatedRateComputation) bean).getStartIndexValue(); case 82210897: // endObservation return ((InflationEndInterpolatedRateComputation) bean).getEndObservation(); case 1209389949: // endSecondObservation return ((InflationEndInterpolatedRateComputation) bean).getEndSecondObservation(); case -791592328: // weight return ((InflationEndInterpolatedRateComputation) bean).getWeight(); } return super.propertyGet(bean, propertyName, quiet); }
private double interpolateEnd(InflationEndInterpolatedRateComputation computation, PriceIndexValues values) { double weight = computation.getWeight(); double indexValue1 = values.value(computation.getEndObservation()); double indexValue2 = values.value(computation.getEndSecondObservation()); return weight * indexValue1 + (1d - weight) * indexValue2; }
@Override public double rate( InflationEndInterpolatedRateComputation computation, LocalDate startDate, LocalDate endDate, RatesProvider provider) { PriceIndexValues values = provider.priceIndexValues(computation.getIndex()); double indexStart = computation.getStartIndexValue(); double indexEnd = interpolateEnd(computation, values); return indexEnd / indexStart - 1d; }
@Override public double explainRate( InflationEndInterpolatedRateComputation computation, LocalDate startDate, LocalDate endDate, RatesProvider provider, ExplainMapBuilder builder) { PriceIndexValues values = provider.priceIndexValues(computation.getIndex()); double w1 = computation.getWeight(); double w2 = 1d - w1; builder.addListEntry(ExplainKey.OBSERVATIONS, child -> child .put(ExplainKey.ENTRY_TYPE, "InflationObservation") .put(ExplainKey.FIXING_DATE, computation.getEndObservation().getFixingMonth().atEndOfMonth()) .put(ExplainKey.INDEX, computation.getIndex()) .put(ExplainKey.INDEX_VALUE, values.value(computation.getEndObservation())) .put(ExplainKey.WEIGHT, w1)); builder.addListEntry(ExplainKey.OBSERVATIONS, child -> child .put(ExplainKey.ENTRY_TYPE, "InflationObservation") .put(ExplainKey.FIXING_DATE, computation.getEndSecondObservation().getFixingMonth().atEndOfMonth()) .put(ExplainKey.INDEX, computation.getIndex()) .put(ExplainKey.INDEX_VALUE, values.value(computation.getEndSecondObservation())) .put(ExplainKey.WEIGHT, w2)); double rate = rate(computation, startDate, endDate, provider); builder.put(ExplainKey.COMBINED_RATE, rate); return rate; }
public void test_serialization() { InflationEndInterpolatedRateComputation test = InflationEndInterpolatedRateComputation.of( GB_HICP, START_INDEX, END_MONTH_FIRST, WEIGHT); assertSerialization(test); }
YearMonth endFixingMonth = null; if (obs instanceof InflationEndInterpolatedRateComputation) { endFixingMonth = ((InflationEndInterpolatedRateComputation) obs).getEndSecondObservation().getFixingMonth(); } else if (obs instanceof InflationEndMonthRateComputation) { endFixingMonth = ((InflationEndMonthRateComputation) obs).getEndObservation().getFixingMonth();
public void test_collectIndices() { InflationEndInterpolatedRateComputation test = InflationEndInterpolatedRateComputation.of( GB_HICP, START_INDEX, END_MONTH_FIRST, WEIGHT); ImmutableSet.Builder<Index> builder = ImmutableSet.builder(); test.collectIndices(builder); assertEquals(builder.build(), ImmutableSet.of(GB_HICP)); }
@Override public void collectIndices(ImmutableSet.Builder<Index> builder) { builder.add(getIndex()); }
private PointSensitivityBuilder endSensitivity(InflationEndInterpolatedRateComputation computation, PriceIndexValues values) { double weight = computation.getWeight(); PointSensitivityBuilder sensi1 = values.valuePointSensitivity(computation.getEndObservation()) .multipliedBy(weight); PointSensitivityBuilder sensi2 = values.valuePointSensitivity(computation.getEndSecondObservation()) .multipliedBy(1d - weight); return sensi1.combinedWith(sensi2); }
public void coverage() { InflationEndInterpolatedRateComputation test1 = InflationEndInterpolatedRateComputation.of( GB_HICP, START_INDEX, END_MONTH_FIRST, WEIGHT); coverImmutableBean(test1); InflationEndInterpolatedRateComputation test2 = InflationEndInterpolatedRateComputation.of( CH_CPI, 334d, YearMonth.of(2010, 7), WEIGHT + 1); coverBeanEquals(test1, test2); }
@Override public PointSensitivityBuilder rateSensitivity( InflationEndInterpolatedRateComputation computation, LocalDate startDate, LocalDate endDate, RatesProvider provider) { PriceIndexValues values = provider.priceIndexValues(computation.getIndex()); PointSensitivityBuilder sensi = endSensitivity(computation, values); return sensi.multipliedBy(1d / computation.getStartIndexValue()); }
private LocalDate calculateLastFixingDate(LocalDate valuationDate, ReferenceData refData) { SwapTrade trade = template.createTrade(valuationDate, BuySell.BUY, 1, 1, refData); SwapLeg inflationLeg = trade.getProduct().getLegs(SwapLegType.INFLATION).get(0); ResolvedSwapLeg inflationLegExpanded = inflationLeg.resolve(refData); List<SwapPaymentPeriod> periods = inflationLegExpanded.getPaymentPeriods(); int nbPeriods = periods.size(); RatePaymentPeriod lastPeriod = (RatePaymentPeriod) periods.get(nbPeriods - 1); List<RateAccrualPeriod> accruals = lastPeriod.getAccrualPeriods(); int nbAccruals = accruals.size(); RateAccrualPeriod lastAccrual = accruals.get(nbAccruals - 1); if (lastAccrual.getRateComputation() instanceof InflationMonthlyRateComputation) { return ((InflationMonthlyRateComputation) lastAccrual.getRateComputation()) .getEndObservation().getFixingMonth().atEndOfMonth(); } if (lastAccrual.getRateComputation() instanceof InflationInterpolatedRateComputation) { return ((InflationInterpolatedRateComputation) lastAccrual.getRateComputation()) .getEndSecondObservation().getFixingMonth().atEndOfMonth(); } if (lastAccrual.getRateComputation() instanceof InflationEndMonthRateComputation) { return ((InflationEndMonthRateComputation) lastAccrual.getRateComputation()) .getEndObservation().getFixingMonth().atEndOfMonth(); } if (lastAccrual.getRateComputation() instanceof InflationEndInterpolatedRateComputation) { return ((InflationEndInterpolatedRateComputation) lastAccrual.getRateComputation()) .getEndSecondObservation().getFixingMonth().atEndOfMonth(); } throw new IllegalArgumentException("Rate computation type not supported for last fixing date of an inflation swap."); }
public void test_rate_InflationEndInterpolatedRateComputation() { double mockRate = 223.0d; RateComputationFn<InflationEndInterpolatedRateComputation> mockInfInt = mock(RateComputationFn.class); InflationEndInterpolatedRateComputation ro = InflationEndInterpolatedRateComputation.of(US_CPI_U, 234d, ACCRUAL_END_MONTH, 0.3); when(mockInfInt.rate(ro, ACCRUAL_START_DATE, ACCRUAL_END_DATE, MOCK_PROV)) .thenReturn(mockRate); DispatchingRateComputationFn test = new DispatchingRateComputationFn( MOCK_IBOR_EMPTY, MOCK_IBOR_INT_EMPTY, MOCK_IBOR_AVE_EMPTY, MOCK_ON_CPD_EMPTY, MOCK_BRL_ON_CPD_EMPTY, MOCK_ON_AVE_EMPTY, MOCK_ON_AVE_DLY_EMPTY, MOCK_INF_MON_EMPTY, MOCK_INF_INT_EMPTY, MOCK_INF_BOND_MON_EMPTY, mockInfInt); assertEquals(test.rate(ro, ACCRUAL_START_DATE, ACCRUAL_END_DATE, MOCK_PROV), mockRate, TOLERANCE_RATE); }
/** * Creates an instance from an index, start index value and reference end month. * <p> * The second end observations will be one month later than the end month. * * @param index the index * @param startIndexValue the start index value * @param referenceEndMonth the reference end month * @param weight the weight * @return the inflation rate computation */ public static InflationEndInterpolatedRateComputation of( PriceIndex index, double startIndexValue, YearMonth referenceEndMonth, double weight) { return new InflationEndInterpolatedRateComputation( startIndexValue, PriceIndexObservation.of(index, referenceEndMonth), PriceIndexObservation.of(index, referenceEndMonth.plusMonths(1)), weight); }
public void test_rate() { ImmutableRatesProvider prov = createProvider(RATE_END, RATE_END_INTERP); InflationEndInterpolatedRateComputation ro = InflationEndInterpolatedRateComputation.of(GB_RPIX, START_INDEX_VALUE, REF_END_MONTH, WEIGHT); ForwardInflationEndInterpolatedRateComputationFn obsFn = ForwardInflationEndInterpolatedRateComputationFn.DEFAULT; // rate double rateExpected = (WEIGHT * RATE_END + (1.0 - WEIGHT) * RATE_END_INTERP) / START_INDEX_VALUE - 1; assertEquals(obsFn.rate(ro, DUMMY_ACCRUAL_START_DATE, DUMMY_ACCRUAL_END_DATE, prov), rateExpected, EPS); // explain ExplainMapBuilder builder = ExplainMap.builder(); assertEquals(obsFn.explainRate(ro, DUMMY_ACCRUAL_START_DATE, DUMMY_ACCRUAL_END_DATE, prov, builder), rateExpected, EPS); ExplainMap built = builder.build(); assertEquals(built.get(ExplainKey.OBSERVATIONS).isPresent(), true); assertEquals(built.get(ExplainKey.OBSERVATIONS).get().size(), 2); ExplainMap explain0 = built.get(ExplainKey.OBSERVATIONS).get().get(0); assertEquals(explain0.get(ExplainKey.FIXING_DATE), Optional.of(REF_END_MONTH.atEndOfMonth())); assertEquals(explain0.get(ExplainKey.INDEX), Optional.of(GB_RPIX)); assertEquals(explain0.get(ExplainKey.INDEX_VALUE), Optional.of(RATE_END)); assertEquals(explain0.get(ExplainKey.WEIGHT), Optional.of(WEIGHT)); ExplainMap explain1 = built.get(ExplainKey.OBSERVATIONS).get().get(1); assertEquals(explain1.get(ExplainKey.FIXING_DATE), Optional.of(REF_END_MONTH_INTERP.atEndOfMonth())); assertEquals(explain1.get(ExplainKey.INDEX), Optional.of(GB_RPIX)); assertEquals(explain1.get(ExplainKey.INDEX_VALUE), Optional.of(RATE_END_INTERP)); assertEquals(explain1.get(ExplainKey.WEIGHT), Optional.of(1d - WEIGHT)); assertEquals(built.get(ExplainKey.COMBINED_RATE).get().doubleValue(), rateExpected, EPS); }
return InflationEndInterpolatedRateComputation.of(index, firstIndexValue, referenceEndMonth, weight); } else if (indexCalculationMethod.equals(PriceIndexCalculationMethod.MONTHLY)) { referenceEndMonth = referenceEndMonth.minusMonths(1); return InflationEndInterpolatedRateComputation.of(index, firstIndexValue, referenceEndMonth, weight); } else { throw new IllegalArgumentException(
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_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); }