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; }
@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); }
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); }
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); }
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."); }
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);