@Override protected Object propertyGet(Bean bean, String propertyName, boolean quiet) { switch (propertyName.hashCode()) { case -1098347926: // startObservation return ((InflationMonthlyRateComputation) bean).getStartObservation(); case 82210897: // endObservation return ((InflationMonthlyRateComputation) bean).getEndObservation(); } return super.propertyGet(bean, propertyName, quiet); }
@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; }