@Override protected Object propertyGet(Bean bean, String propertyName, boolean quiet) { switch (propertyName.hashCode()) { case -1098347926: // startObservation return ((InflationInterpolatedRateComputation) bean).getStartObservation(); case 1287141078: // startSecondObservation return ((InflationInterpolatedRateComputation) bean).getStartSecondObservation(); case 82210897: // endObservation return ((InflationInterpolatedRateComputation) bean).getEndObservation(); case 1209389949: // endSecondObservation return ((InflationInterpolatedRateComputation) bean).getEndSecondObservation(); case -791592328: // weight return ((InflationInterpolatedRateComputation) bean).getWeight(); } return super.propertyGet(bean, propertyName, quiet); }
@Override public void collectIndices(ImmutableSet.Builder<Index> builder) { builder.add(getIndex()); }
public void test_serialization() { InflationInterpolatedRateComputation test = InflationInterpolatedRateComputation.of( GB_HICP, START_MONTH_FIRST, END_MONTH_FIRST, WEIGHT); assertSerialization(test); }
private double interpolateEnd(InflationInterpolatedRateComputation 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; }
private double interpolateStart(InflationInterpolatedRateComputation computation, PriceIndexValues values) { double weight = computation.getWeight(); double indexValue1 = values.value(computation.getStartObservation()); double indexValue2 = values.value(computation.getStartSecondObservation()); return weight * indexValue1 + (1d - weight) * indexValue2; }
public void test_collectIndices() { InflationInterpolatedRateComputation test = InflationInterpolatedRateComputation.of( GB_HICP, START_MONTH_FIRST, END_MONTH_FIRST, WEIGHT); ImmutableSet.Builder<Index> builder = ImmutableSet.builder(); test.collectIndices(builder); assertEquals(builder.build(), ImmutableSet.of(GB_HICP)); }
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_wrongMonthOrder() { assertThrowsIllegalArg(() -> InflationInterpolatedRateComputation.of( GB_HICP, END_MONTH_FIRST, START_MONTH_FIRST, WEIGHT)); assertThrowsIllegalArg(() -> InflationInterpolatedRateComputation.meta().builder() .set(InflationInterpolatedRateComputation.meta().startObservation(), PriceIndexObservation.of(GB_HICP, YearMonth.of(2010, 1))) .set(InflationInterpolatedRateComputation.meta().startSecondObservation(), PriceIndexObservation.of(GB_HICP, YearMonth.of(2010, 1))) .set(InflationInterpolatedRateComputation.meta().endObservation(), PriceIndexObservation.of(GB_HICP, YearMonth.of(2010, 7))) .set(InflationInterpolatedRateComputation.meta().endSecondObservation(), PriceIndexObservation.of(GB_HICP, YearMonth.of(2010, 8))) .set(InflationInterpolatedRateComputation.meta().weight(), WEIGHT) .build()); assertThrowsIllegalArg(() -> InflationInterpolatedRateComputation.meta().builder() .set(InflationInterpolatedRateComputation.meta().startObservation(), PriceIndexObservation.of(GB_HICP, YearMonth.of(2010, 1))) .set(InflationInterpolatedRateComputation.meta().startSecondObservation(), PriceIndexObservation.of(GB_HICP, YearMonth.of(2010, 2))) .set(InflationInterpolatedRateComputation.meta().endObservation(), PriceIndexObservation.of(GB_HICP, YearMonth.of(2010, 7))) .set(InflationInterpolatedRateComputation.meta().endSecondObservation(), PriceIndexObservation.of(GB_HICP, YearMonth.of(2010, 7))) .set(InflationInterpolatedRateComputation.meta().weight(), WEIGHT) .build()); assertThrowsIllegalArg(() -> InflationInterpolatedRateComputation.meta().builder() .set(InflationInterpolatedRateComputation.meta().startObservation(), PriceIndexObservation.of(GB_HICP, YearMonth.of(2010, 8))) .set(InflationInterpolatedRateComputation.meta().startSecondObservation(), PriceIndexObservation.of(GB_HICP, YearMonth.of(2010, 9)))
private PointSensitivityBuilder endSensitivity(InflationInterpolatedRateComputation 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); }
private PointSensitivityBuilder startSensitivity(InflationInterpolatedRateComputation computation, PriceIndexValues values) { double weight = computation.getWeight(); PointSensitivityBuilder sensi1 = values.valuePointSensitivity(computation.getStartObservation()) .multipliedBy(weight); PointSensitivityBuilder sensi2 = values.valuePointSensitivity(computation.getStartSecondObservation()) .multipliedBy(1d - weight); return sensi1.combinedWith(sensi2); }
public void test_of() { InflationInterpolatedRateComputation test = InflationInterpolatedRateComputation.of( GB_HICP, START_MONTH_FIRST, END_MONTH_FIRST, WEIGHT); assertEquals(test.getIndex(), GB_HICP); assertEquals(test.getStartObservation().getFixingMonth(), START_MONTH_FIRST); assertEquals(test.getStartSecondObservation().getFixingMonth(), START_MONTH_SECOND); assertEquals(test.getEndObservation().getFixingMonth(), END_MONTH_FIRST); assertEquals(test.getEndSecondObservation().getFixingMonth(), END_MONTH_SECOND); assertEquals(test.getWeight(), WEIGHT, 1.0e-14); }
public void coverage() { InflationInterpolatedRateComputation test1 = InflationInterpolatedRateComputation.of( GB_HICP, START_MONTH_FIRST, END_MONTH_FIRST, WEIGHT); coverImmutableBean(test1); InflationInterpolatedRateComputation test2 = InflationInterpolatedRateComputation.of( CH_CPI, YearMonth.of(2010, 1), YearMonth.of(2010, 7), WEIGHT + 0.1d); coverBeanEquals(test1, test2); }
@Override public double rate( InflationInterpolatedRateComputation computation, LocalDate startDate, LocalDate endDate, RatesProvider provider) { PriceIndexValues values = provider.priceIndexValues(computation.getIndex()); double indexStart = interpolateStart(computation, values); double indexEnd = interpolateEnd(computation, values); return indexEnd / indexStart - 1d; }
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.getStartObservation().getFixingMonth().atEndOfMonth()) .put(ExplainKey.INDEX, computation.getIndex()) .put(ExplainKey.INDEX_VALUE, values.value(computation.getStartObservation())) .put(ExplainKey.WEIGHT, w1)); builder.addListEntry(ExplainKey.OBSERVATIONS, child -> child .put(ExplainKey.ENTRY_TYPE, "InflationObservation") .put(ExplainKey.FIXING_DATE, computation.getStartSecondObservation().getFixingMonth().atEndOfMonth()) .put(ExplainKey.INDEX, computation.getIndex()) .put(ExplainKey.INDEX_VALUE, values.value(computation.getStartSecondObservation())) .put(ExplainKey.WEIGHT, w2)); 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);
public void test_rate_InflationInterpolatedRateComputation() { double mockRate = 223.0d; RateComputationFn<InflationInterpolatedRateComputation> mockInfInt = mock(RateComputationFn.class); InflationInterpolatedRateComputation ro = InflationInterpolatedRateComputation.of(US_CPI_U, ACCRUAL_START_MONTH, 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, mockInfInt, MOCK_INF_BOND_MON_EMPTY, MOCK_INF_BOND_INT_EMPTY); assertEquals(test.rate(ro, ACCRUAL_START_DATE, ACCRUAL_END_DATE, MOCK_PROV), mockRate, TOLERANCE_RATE); }
@Override public PointSensitivityBuilder rateSensitivity( InflationInterpolatedRateComputation computation, LocalDate startDate, LocalDate endDate, RatesProvider provider) { PriceIndexValues values = provider.priceIndexValues(computation.getIndex()); double indexStart = interpolateStart(computation, values); double indexEnd = interpolateEnd(computation, values); double indexStartInv = 1d / indexStart; PointSensitivityBuilder sensi1 = startSensitivity(computation, values) .multipliedBy(-indexEnd * indexStartInv * indexStartInv); PointSensitivityBuilder sensi2 = endSensitivity(computation, values) .multipliedBy(indexStartInv); return sensi1.combinedWith(sensi2); }
InflationInterpolatedRateComputation.of(GB_RPIX, REF_START_MONTH, REF_END_MONTH, WEIGHT); ForwardInflationInterpolatedRateComputationFn obsFn = ForwardInflationInterpolatedRateComputationFn.DEFAULT;
private RateComputation createRateComputation(SchedulePeriod period, int scheduleIndex) { // handle where index value at start date is known LocalDate endDate = period.getEndDate(); if (firstIndexValue != null && scheduleIndex == 0) { return createRateComputation(endDate); } YearMonth referenceStartMonth = YearMonth.from(period.getStartDate().minus(lag)); YearMonth referenceEndMonth = YearMonth.from(endDate.minus(lag)); if (indexCalculationMethod.equals(PriceIndexCalculationMethod.INTERPOLATED)) { // interpolate between data from two different months double weight = 1d - (endDate.getDayOfMonth() - 1d) / endDate.lengthOfMonth(); return InflationInterpolatedRateComputation.of(index, referenceStartMonth, referenceEndMonth, weight); } else if (indexCalculationMethod.equals(PriceIndexCalculationMethod.MONTHLY)) { // no interpolation return InflationMonthlyRateComputation.of(index, referenceStartMonth, referenceEndMonth); } else { throw new IllegalArgumentException( "PriceIndexCalculationMethod " + indexCalculationMethod.toString() + " is not supported"); } }
.builder(ACCRUAL1) .yearFraction(1.0) .rateComputation(InflationInterpolatedRateComputation.of( CH_CPI, YearMonth.from(DATE_2015_01_05).minusMonths(3), .builder(ACCRUAL2) .yearFraction(1.0) .rateComputation(InflationInterpolatedRateComputation.of( CH_CPI, YearMonth.from(DATE_2015_02_05).minusMonths(3), .builder(ACCRUAL3) .yearFraction(1.0) .rateComputation(InflationInterpolatedRateComputation.of( CH_CPI, YearMonth.from(DATE_2015_03_07).minusMonths(3),
.yearFraction(1.0) .rateComputation( InflationInterpolatedRateComputation.of( GB_RPI, YearMonth.from(bda.adjust(DATE_14_06_09, REF_DATA)).minusMonths(3),