@Override public double rate( InflationEndMonthRateComputation computation, LocalDate startDate, LocalDate endDate, RatesProvider provider) { PriceIndexValues values = provider.priceIndexValues(computation.getIndex()); double indexStart = computation.getStartIndexValue(); double indexEnd = values.value(computation.getEndObservation()); return indexEnd / indexStart - 1; }
@Override public InflationEndMonthRateComputation build() { return new InflationEndMonthRateComputation( startIndexValue, endObservation); }
@Override protected Object propertyGet(Bean bean, String propertyName, boolean quiet) { switch (propertyName.hashCode()) { case -1656407615: // startIndexValue return ((InflationEndMonthRateComputation) bean).getStartIndexValue(); case 82210897: // endObservation return ((InflationEndMonthRateComputation) bean).getEndObservation(); } return super.propertyGet(bean, propertyName, quiet); }
public void test_serialization() { InflationEndMonthRateComputation test = InflationEndMonthRateComputation.of(GB_HICP, START_INDEX, END_MONTH); assertSerialization(test); }
@Override public double explainRate( InflationEndMonthRateComputation computation, LocalDate startDate, LocalDate endDate, RatesProvider provider, ExplainMapBuilder builder) { PriceIndexValues values = provider.priceIndexValues(computation.getIndex()); double indexEnd = values.value(computation.getEndObservation()); 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, indexEnd)); double rate = rate(computation, startDate, endDate, provider); builder.put(ExplainKey.COMBINED_RATE, rate); return rate; }
public void test_collectIndices() { InflationEndMonthRateComputation test = InflationEndMonthRateComputation.of(GB_HICP, START_INDEX, END_MONTH); 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."); }
@Override public void collectIndices(ImmutableSet.Builder<Index> builder) { builder.add(getIndex()); }
public void coverage() { InflationEndMonthRateComputation test1 = InflationEndMonthRateComputation.of(GB_HICP, START_INDEX, END_MONTH); coverImmutableBean(test1); InflationEndMonthRateComputation test2 = InflationEndMonthRateComputation.of(CH_CPI, 2324d, YearMonth.of(2015, 4)); coverBeanEquals(test1, test2); }
endFixingMonth = ((InflationEndInterpolatedRateComputation) obs).getEndSecondObservation().getFixingMonth(); } else if (obs instanceof InflationEndMonthRateComputation) { endFixingMonth = ((InflationEndMonthRateComputation) obs).getEndObservation().getFixingMonth(); } else { throw new IllegalArgumentException("The rate observation " + obs.toString() + " is not supported.");
@Override public PointSensitivityBuilder rateSensitivity( InflationEndMonthRateComputation computation, LocalDate startDate, LocalDate endDate, RatesProvider provider) { PriceIndexValues values = provider.priceIndexValues(computation.getIndex()); return values.valuePointSensitivity(computation.getEndObservation()) .multipliedBy(1d / computation.getStartIndexValue()); }
public void test_rate_InflationEndMonthRateComputation() { double mockRate = 223.0d; RateComputationFn<InflationEndMonthRateComputation> mockInfMon = mock(RateComputationFn.class); InflationEndMonthRateComputation ro = InflationEndMonthRateComputation.of(US_CPI_U, 123d, ACCRUAL_END_MONTH); when(mockInfMon.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, mockInfMon, MOCK_INF_BOND_INT_EMPTY); 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. * * @param index the index * @param startIndexValue the start index value * @param referenceEndMonth the reference end month * @return the inflation rate computation */ public static InflationEndMonthRateComputation of( PriceIndex index, double startIndexValue, YearMonth referenceEndMonth) { return new InflationEndMonthRateComputation(startIndexValue, PriceIndexObservation.of(index, referenceEndMonth)); }
public void test_rate() { ImmutableRatesProvider prov = createProvider(RATE_END); InflationEndMonthRateComputation ro = InflationEndMonthRateComputation.of(GB_RPIX, START_INDEX_VALUE, REFERENCE_END_MONTH); ForwardInflationEndMonthRateComputationFn obsFn = ForwardInflationEndMonthRateComputationFn.DEFAULT; double rateExpected = RATE_END / 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(), 1); ExplainMap explain0 = built.get(ExplainKey.OBSERVATIONS).get().get(0); assertEquals(explain0.get(ExplainKey.FIXING_DATE), Optional.of(REFERENCE_END_MONTH.atEndOfMonth())); assertEquals(explain0.get(ExplainKey.INDEX), Optional.of(GB_RPIX)); assertEquals(explain0.get(ExplainKey.INDEX_VALUE), Optional.of(RATE_END)); assertEquals(built.get(ExplainKey.COMBINED_RATE).get().doubleValue(), rateExpected, EPS); }
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); }
} else if (indexCalculationMethod.equals(PriceIndexCalculationMethod.MONTHLY)) { return InflationEndMonthRateComputation.of(index, firstIndexValue, referenceEndMonth); } else if (indexCalculationMethod.equals(PriceIndexCalculationMethod.INTERPOLATED_JAPAN)) {
public void test_rateSensitivity() { ImmutableRatesProvider prov = createProvider(RATE_END); ImmutableRatesProvider provEndUp = createProvider(RATE_END + EPS_FD); ImmutableRatesProvider provEndDw = createProvider(RATE_END - EPS_FD); InflationEndMonthRateComputation ro = InflationEndMonthRateComputation.of(GB_RPIX, START_INDEX_VALUE, REFERENCE_END_MONTH); ForwardInflationEndMonthRateComputationFn obsFn = ForwardInflationEndMonthRateComputationFn.DEFAULT; double rateEndUp = obsFn.rate(ro, DUMMY_ACCRUAL_START_DATE, DUMMY_ACCRUAL_END_DATE, provEndUp); double rateEndDw = obsFn.rate(ro, DUMMY_ACCRUAL_START_DATE, DUMMY_ACCRUAL_END_DATE, provEndDw); PointSensitivityBuilder sensiExpected = InflationRateSensitivity.of( PriceIndexObservation.of(GB_RPIX, REFERENCE_END_MONTH), 0.5 * (rateEndUp - rateEndDw) / EPS_FD); PointSensitivityBuilder sensiComputed = obsFn.rateSensitivity(ro, DUMMY_ACCRUAL_START_DATE, DUMMY_ACCRUAL_END_DATE, prov); assertTrue(sensiComputed.build().normalized().equalWithTolerance(sensiExpected.build().normalized(), EPS_FD)); }
public void coverage() { CapitalIndexedBondPaymentPeriod test1 = CapitalIndexedBondPaymentPeriod.builder() .currency(USD) .notional(NOTIONAL) .detachmentDate(DETACHMENT) .startDate(START) .endDate(END) .unadjustedStartDate(START_UNADJ) .unadjustedEndDate(END_UNADJ) .rateComputation(COMPUTE_INTERP) .realCoupon(REAL_COUPON) .build(); coverImmutableBean(test1); CapitalIndexedBondPaymentPeriod test2 = CapitalIndexedBondPaymentPeriod.builder() .currency(GBP) .notional(5.0e6) .startDate(LocalDate.of(2008, 1, 15)) .endDate(LocalDate.of(2008, 7, 15)) .rateComputation(InflationEndMonthRateComputation.of(GB_RPI, 155.32, REF_END)) .realCoupon(1d) .build(); coverBeanEquals(test1, test2); }
.yearFraction(1.0) .rateComputation( InflationEndMonthRateComputation.of( GB_HICP, 123d,