@Override public void collectIndices(ImmutableSet.Builder<Index> builder) { builder.add(getIndex()); }
public void test_of() { InflationMonthlyRateComputation test = InflationMonthlyRateComputation.of(GB_HICP, START_MONTH, END_MONTH); assertEquals(test.getIndex(), GB_HICP); }
@Override public double rate( InflationMonthlyRateComputation computation, LocalDate startDate, LocalDate endDate, RatesProvider provider) { PriceIndex index = computation.getIndex(); PriceIndexValues values = provider.priceIndexValues(index); double indexStart = values.value(computation.getStartObservation()); double indexEnd = values.value(computation.getEndObservation()); return indexEnd / indexStart - 1d; }
@Override public PointSensitivityBuilder rateSensitivity( InflationMonthlyRateComputation computation, LocalDate startDate, LocalDate endDate, RatesProvider provider) { PriceIndex index = computation.getIndex(); PriceIndexValues values = provider.priceIndexValues(index); double indexStart = values.value(computation.getStartObservation()); double indexEnd = values.value(computation.getEndObservation()); double indexStartInv = 1d / indexStart; PointSensitivityBuilder sensi1 = values.valuePointSensitivity(computation.getStartObservation()) .multipliedBy(-indexEnd * indexStartInv * indexStartInv); PointSensitivityBuilder sensi2 = values.valuePointSensitivity(computation.getEndObservation()) .multipliedBy(indexStartInv); return sensi1.combinedWith(sensi2); }
@Override public double explainRate( InflationMonthlyRateComputation computation, LocalDate startDate, LocalDate endDate, RatesProvider provider, ExplainMapBuilder builder) { PriceIndex index = computation.getIndex(); PriceIndexValues values = provider.priceIndexValues(index); double indexStart = values.value(computation.getStartObservation()); double indexEnd = values.value(computation.getEndObservation()); builder.addListEntry(ExplainKey.OBSERVATIONS, child -> child .put(ExplainKey.ENTRY_TYPE, "InflationObservation") .put(ExplainKey.FIXING_DATE, computation.getStartObservation().getFixingMonth().atEndOfMonth()) .put(ExplainKey.INDEX, index) .put(ExplainKey.INDEX_VALUE, indexStart)); builder.addListEntry(ExplainKey.OBSERVATIONS, child -> child .put(ExplainKey.ENTRY_TYPE, "InflationObservation") .put(ExplainKey.FIXING_DATE, computation.getEndObservation().getFixingMonth().atEndOfMonth()) .put(ExplainKey.INDEX, index) .put(ExplainKey.INDEX_VALUE, indexEnd)); double rate = rate(computation, startDate, endDate, provider); builder.put(ExplainKey.COMBINED_RATE, rate); return rate; }