public void test_of_monthly() { IborInterpolatedRateComputation test = IborInterpolatedRateComputation.of(GBP_LIBOR_1M, GBP_LIBOR_3M, FIXING_DATE, REF_DATA); assertEquals(test.getShortObservation(), GBP_LIBOR_1M_OBS); assertEquals(test.getLongObservation(), GBP_LIBOR_3M_OBS); assertEquals(test.getFixingDate(), FIXING_DATE); }
/** * Creates an instance from two indices and fixing date. * <p> * The indices may be passed in any order. * * @param index1 the first index * @param index2 the second index * @param fixingDate the fixing date * @param refData the reference data to use when resolving holiday calendars * @return the interpolated rate computation */ public static IborInterpolatedRateComputation of( IborIndex index1, IborIndex index2, LocalDate fixingDate, ReferenceData refData) { boolean inOrder = indicesInOrder(index1, index2, fixingDate); IborIndexObservation obs1 = IborIndexObservation.of(index1, fixingDate, refData); IborIndexObservation obs2 = IborIndexObservation.of(index2, fixingDate, refData); return new IborInterpolatedRateComputation(inOrder ? obs1 : obs2, inOrder ? obs2 : obs1); }
public void test_collectIndices() { IborInterpolatedRateComputation test = IborInterpolatedRateComputation.of(GBP_LIBOR_1M, GBP_LIBOR_3M, FIXING_DATE, REF_DATA); ImmutableSet.Builder<Index> builder = ImmutableSet.builder(); test.collectIndices(builder); assertEquals(builder.build(), ImmutableSet.of(GBP_LIBOR_1M, GBP_LIBOR_3M)); }
@Override protected Object propertyGet(Bean bean, String propertyName, boolean quiet) { switch (propertyName.hashCode()) { case -496986608: // shortObservation return ((IborInterpolatedRateComputation) bean).getShortObservation(); case -684321776: // longObservation return ((IborInterpolatedRateComputation) bean).getLongObservation(); } return super.propertyGet(bean, propertyName, quiet); }
private RateComputation createRateComputation(ReferenceData refData) { LocalDate fixingDate = fixingDateOffset.adjust(startDate, refData); if (indexInterpolated != null) { return IborInterpolatedRateComputation.of(index, indexInterpolated, fixingDate, refData); } else { return IborRateComputation.of(index, fixingDate, refData); } }
public void test_builder_indexOrder() { assertThrowsIllegalArg(() -> IborInterpolatedRateComputation.meta().builder() .set(IborInterpolatedRateComputation.meta().shortObservation(), GBP_LIBOR_3M_OBS) .set(IborInterpolatedRateComputation.meta().longObservation(), GBP_LIBOR_1M_OBS) .build()); assertThrowsIllegalArg(() -> IborInterpolatedRateComputation.meta().builder() .set(IborInterpolatedRateComputation.meta().shortObservation(), EUR_EURIBOR_2W_OBS) .set(IborInterpolatedRateComputation.meta().longObservation(), EUR_EURIBOR_1W_OBS) .build()); assertThrowsIllegalArg(() -> IborInterpolatedRateComputation.of(EUR_EURIBOR_2W_OBS, EUR_EURIBOR_1W_OBS)); }
private void assertIborPaymentPeriod( ResolvedSwapLeg expandedPayLeg, int index, String paymentDateStr, String startDateStr, String endDateStr, double notional, String fixingDateStr) { RatePaymentPeriod pp = (RatePaymentPeriod) expandedPayLeg.getPaymentPeriods().get(index); assertEquals(pp.getPaymentDate().toString(), paymentDateStr); assertEquals(Math.abs(pp.getNotional()), notional); assertEquals(pp.getAccrualPeriods().size(), 1); RateAccrualPeriod ap = pp.getAccrualPeriods().get(0); assertEquals(ap.getStartDate().toString(), startDateStr); assertEquals(ap.getEndDate().toString(), endDateStr); if (ap.getRateComputation() instanceof IborInterpolatedRateComputation) { assertEquals(((IborInterpolatedRateComputation) ap.getRateComputation()).getFixingDate().toString(), fixingDateStr); } else if (ap.getRateComputation() instanceof IborRateComputation) { assertEquals(((IborRateComputation) ap.getRateComputation()).getFixingDate().toString(), fixingDateStr); } else { fail(); } }
@Override public IborInterpolatedRateComputation build() { return new IborInterpolatedRateComputation( shortObservation, longObservation); }
private IborInterpolatedRateComputation( IborIndexObservation shortObservation, IborIndexObservation longObservation) { JodaBeanUtils.notNull(shortObservation, "shortObservation"); JodaBeanUtils.notNull(longObservation, "longObservation"); this.shortObservation = shortObservation; this.longObservation = longObservation; validate(); }
@ImmutableValidator private void validate() { IborIndex shortIndex = shortObservation.getIndex(); IborIndex longIndex = longObservation.getIndex(); if (!shortIndex.getCurrency().equals(longIndex.getCurrency())) { throw new IllegalArgumentException("Interpolation requires two indices in the same currency"); } if (shortIndex.equals(longIndex)) { throw new IllegalArgumentException("Interpolation requires two different indices"); } if (!shortObservation.getFixingDate().equals(longObservation.getFixingDate())) { throw new IllegalArgumentException("Interpolation requires observations with same fixing date"); } if (!indicesInOrder(shortIndex, longIndex, shortObservation.getFixingDate())) { throw new IllegalArgumentException(Messages.format( "Interpolation indices passed in wrong order: {} {}", shortIndex, longIndex)); } }
@Override public double rate( IborInterpolatedRateComputation computation, LocalDate startDate, LocalDate endDate, RatesProvider provider) { IborIndexObservation obs1 = computation.getShortObservation(); IborIndexObservation obs2 = computation.getLongObservation(); IborIndexRates rates1 = provider.iborIndexRates(obs1.getIndex()); IborIndexRates rates2 = provider.iborIndexRates(obs2.getIndex()); double rate1 = rates1.rate(obs1); double rate2 = rates2.rate(obs2); DoublesPair weights = weights(obs1, obs2, endDate); return ((rate1 * weights.getFirst()) + (rate2 * weights.getSecond())) / (weights.getFirst() + weights.getSecond()); }
public void test_serialization() { IborInterpolatedRateComputation test = IborInterpolatedRateComputation.of(GBP_LIBOR_1M, GBP_LIBOR_3M, FIXING_DATE, REF_DATA); assertSerialization(test); }
private void assertIborPaymentPeriodCpd( ResolvedSwapLeg expandedPayLeg, int paymentIndex, int accrualIndex, String paymentDateStr, String startDateStr, String endDateStr, double notional, String fixingDateStr) { RatePaymentPeriod pp = (RatePaymentPeriod) expandedPayLeg.getPaymentPeriods().get(paymentIndex); assertEquals(pp.getPaymentDate().toString(), paymentDateStr); assertEquals(Math.abs(pp.getNotional()), notional); assertEquals(pp.getAccrualPeriods().size(), 2); RateAccrualPeriod ap = pp.getAccrualPeriods().get(accrualIndex); assertEquals(ap.getStartDate().toString(), startDateStr); assertEquals(ap.getEndDate().toString(), endDateStr); if (ap.getRateComputation() instanceof IborInterpolatedRateComputation) { assertEquals(((IborInterpolatedRateComputation) ap.getRateComputation()).getFixingDate().toString(), fixingDateStr); } else if (ap.getRateComputation() instanceof IborRateComputation) { assertEquals(((IborRateComputation) ap.getRateComputation()).getFixingDate().toString(), fixingDateStr); } else { fail(); } }
/** * Creates an instance from the two underlying index observations. * <p> * The two observations must be for two different indexes in the same currency on the same fixing date. * The index with the shorter tenor must be passed as the first argument. * * @param shortObservation the short underlying index observation * @param longObservation the long underlying index observation * @return the rate computation * @throws IllegalArgumentException if the indices are not short, then long */ public static IborInterpolatedRateComputation of( IborIndexObservation shortObservation, IborIndexObservation longObservation) { return new IborInterpolatedRateComputation(shortObservation, longObservation); }
public void test_of_weekly() { IborInterpolatedRateComputation test = IborInterpolatedRateComputation.of(EUR_EURIBOR_1W, EUR_EURIBOR_2W, FIXING_DATE, REF_DATA); assertEquals(test.getShortObservation(), EUR_EURIBOR_1W_OBS); assertEquals(test.getLongObservation(), EUR_EURIBOR_2W_OBS); assertEquals(test.getFixingDate(), FIXING_DATE); }
@Override public double explainRate( IborInterpolatedRateComputation computation, LocalDate startDate, LocalDate endDate, RatesProvider provider, ExplainMapBuilder builder) { IborIndexObservation obs1 = computation.getShortObservation(); IborIndexObservation obs2 = computation.getLongObservation(); DoublesPair weights = weights(obs1, obs2, endDate); IborIndexRates rates1 = provider.iborIndexRates(obs1.getIndex()); IborIndexRates rates2 = provider.iborIndexRates(obs2.getIndex()); rates1.explainRate(obs1, builder, child -> child.put(ExplainKey.WEIGHT, weights.getFirst())); rates2.explainRate(obs2, builder, child -> child.put(ExplainKey.WEIGHT, weights.getSecond())); double rate = rate(computation, startDate, endDate, provider); builder.put(ExplainKey.COMBINED_RATE, rate); return rate; }
public void test_of_sameIndex() { assertThrowsIllegalArg( () -> IborInterpolatedRateComputation.of(GBP_LIBOR_1M, GBP_LIBOR_1M, FIXING_DATE, REF_DATA)); }
public void test_of_monthly_byObs() { IborInterpolatedRateComputation test = IborInterpolatedRateComputation.of(GBP_LIBOR_1M_OBS, GBP_LIBOR_3M_OBS); assertEquals(test.getShortObservation(), GBP_LIBOR_1M_OBS); assertEquals(test.getLongObservation(), GBP_LIBOR_3M_OBS); assertEquals(test.getFixingDate(), FIXING_DATE); }
@Override public PointSensitivityBuilder rateSensitivity( IborInterpolatedRateComputation computation, LocalDate startDate, LocalDate endDate, RatesProvider provider) { // computes the dates related to the underlying deposits associated to the indices IborIndexObservation obs1 = computation.getShortObservation(); IborIndexObservation obs2 = computation.getLongObservation(); DoublesPair weights = weights(obs1, obs2, endDate); double totalWeight = weights.getFirst() + weights.getSecond(); IborIndexRates ratesIndex1 = provider.iborIndexRates(obs1.getIndex()); PointSensitivityBuilder sens1 = ratesIndex1.ratePointSensitivity(obs1) .multipliedBy(weights.getFirst() / totalWeight); IborIndexRates ratesIndex2 = provider.iborIndexRates(obs2.getIndex()); PointSensitivityBuilder sens2 = ratesIndex2.ratePointSensitivity(obs2) .multipliedBy(weights.getSecond() / totalWeight); return sens1.combinedWith(sens2); }