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_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)); }
public void test_serialization() { IborInterpolatedRateComputation test = IborInterpolatedRateComputation.of(GBP_LIBOR_1M, GBP_LIBOR_3M, FIXING_DATE, REF_DATA); assertSerialization(test); }
public void test_of_sameIndex() { assertThrowsIllegalArg( () -> IborInterpolatedRateComputation.of(GBP_LIBOR_1M, GBP_LIBOR_1M, FIXING_DATE, REF_DATA)); }
public void test_of_differentCurrencies() { assertThrowsIllegalArg( () -> IborInterpolatedRateComputation.of(EUR_EURIBOR_2W, GBP_LIBOR_1M, FIXING_DATE, REF_DATA)); }
public void coverage() { IborInterpolatedRateComputation test = IborInterpolatedRateComputation.of(GBP_LIBOR_1M, GBP_LIBOR_3M, FIXING_DATE, REF_DATA); coverImmutableBean(test); IborInterpolatedRateComputation test2 = IborInterpolatedRateComputation.of(USD_LIBOR_1M, USD_LIBOR_3M, date(2014, 7, 30), REF_DATA); coverBeanEquals(test, test2); }
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); }
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); }
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); }
public void test_of_monthly_reverseOrder() { IborInterpolatedRateComputation test = IborInterpolatedRateComputation.of(GBP_LIBOR_3M, GBP_LIBOR_1M, FIXING_DATE, REF_DATA); assertEquals(test.getShortObservation(), GBP_LIBOR_1M_OBS); assertEquals(test.getLongObservation(), GBP_LIBOR_3M_OBS); assertEquals(test.getFixingDate(), FIXING_DATE); }
public void test_of_weekly_reverseOrder() { IborInterpolatedRateComputation test = IborInterpolatedRateComputation.of(EUR_EURIBOR_2W, EUR_EURIBOR_1W, FIXING_DATE, REF_DATA); assertEquals(test.getShortObservation(), EUR_EURIBOR_1W_OBS); assertEquals(test.getLongObservation(), EUR_EURIBOR_2W_OBS); assertEquals(test.getFixingDate(), FIXING_DATE); }
public void test_of_weekMonthCombination() { IborInterpolatedRateComputation test = IborInterpolatedRateComputation.of(GBP_LIBOR_1W, GBP_LIBOR_1M, FIXING_DATE, REF_DATA); assertEquals(test.getShortObservation(), GBP_LIBOR_1W_OBS); assertEquals(test.getLongObservation(), GBP_LIBOR_1M_OBS); assertEquals(test.getFixingDate(), FIXING_DATE); }
public void test_rate_IborInterpolatedRateComputation() { double mockRate = 0.0123d; RateComputationFn<IborInterpolatedRateComputation> mockIborInt = mock(RateComputationFn.class); IborInterpolatedRateComputation ro = IborInterpolatedRateComputation.of(GBP_LIBOR_3M, GBP_LIBOR_6M, FIXING_DATE, REF_DATA); when(mockIborInt.rate(ro, ACCRUAL_START_DATE, ACCRUAL_END_DATE, MOCK_PROV)) .thenReturn(mockRate); DispatchingRateComputationFn test = new DispatchingRateComputationFn( MOCK_IBOR_EMPTY, mockIborInt, 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, MOCK_INF_BOND_MON_EMPTY, MOCK_INF_BOND_INT_EMPTY); assertEquals(test.rate(ro, ACCRUAL_START_DATE, ACCRUAL_END_DATE, MOCK_PROV), mockRate, 0d); }
when(mockProv.iborIndexRates(GBP_LIBOR_6M)).thenReturn(mockRates6M); IborInterpolatedRateComputation ro = IborInterpolatedRateComputation.of(GBP_LIBOR_3M, GBP_LIBOR_6M, FIXING_DATE, REF_DATA); ForwardIborInterpolatedRateComputationFn obs = ForwardIborInterpolatedRateComputationFn.DEFAULT; LocalDate fixingEndDate3M = GBP_LIBOR_3M_OBS.getMaturityDate();
public void test_rateSensitivity() { RatesProvider mockProv = mock(RatesProvider.class); IborIndexRates mockRates3M = mock(IborIndexRates.class); IborIndexRates mockRates6M = mock(IborIndexRates.class); when(mockProv.iborIndexRates(GBP_LIBOR_3M)).thenReturn(mockRates3M); when(mockProv.iborIndexRates(GBP_LIBOR_6M)).thenReturn(mockRates6M); when(mockRates3M.ratePointSensitivity(GBP_LIBOR_3M_OBS)).thenReturn(SENSITIVITY3); when(mockRates6M.ratePointSensitivity(GBP_LIBOR_6M_OBS)).thenReturn(SENSITIVITY6); IborInterpolatedRateComputation ro = IborInterpolatedRateComputation.of(GBP_LIBOR_3M, GBP_LIBOR_6M, FIXING_DATE, REF_DATA); ForwardIborInterpolatedRateComputationFn obsFn = ForwardIborInterpolatedRateComputationFn.DEFAULT; LocalDate fixingEndDate3M = GBP_LIBOR_3M_OBS.getMaturityDate(); LocalDate fixingEndDate6M = GBP_LIBOR_6M_OBS.getMaturityDate(); double days3M = fixingEndDate3M.toEpochDay() - FIXING_DATE.toEpochDay(); //nb days in 3M fixing period double days6M = fixingEndDate6M.toEpochDay() - FIXING_DATE.toEpochDay(); //nb days in 6M fixing period double daysCpn = ACCRUAL_END_DATE.toEpochDay() - FIXING_DATE.toEpochDay(); double weight3M = (days6M - daysCpn) / (days6M - days3M); double weight6M = (daysCpn - days3M) / (days6M - days3M); IborRateSensitivity sens3 = IborRateSensitivity.of(GBP_LIBOR_3M_OBS, weight3M); IborRateSensitivity sens6 = IborRateSensitivity.of(GBP_LIBOR_6M_OBS, weight6M); PointSensitivities expected = PointSensitivities.of(ImmutableList.of(sens3, sens6)); PointSensitivityBuilder test = obsFn.rateSensitivity(ro, ACCRUAL_START_DATE, ACCRUAL_END_DATE, mockProv); assertEquals(test.build(), expected); }
/** * Creates the {@code RateComputation} for the stub. * * @param fixingDate the fixing date * @param defaultIndex the default index to use if the stub has no rules * @param refData the reference data * @return the rate observation */ RateComputation createRateComputation(LocalDate fixingDate, IborIndex defaultIndex, ReferenceData refData) { if (isInterpolated()) { return IborInterpolatedRateComputation.of(index, indexInterpolated, fixingDate, refData); } else if (isFloatingRate()) { return IborRateComputation.of(index, fixingDate, refData); } else if (isFixedRate()) { return FixedRateComputation.of(fixedRate); } else if (isKnownAmount()) { return KnownAmountRateComputation.of(knownAmount); } else { return IborRateComputation.of(defaultIndex, fixingDate, refData); } }
public void test_expand_singlePeriod_stubCalcsInitialStub_interpolated() { IborRateCalculation test = IborRateCalculation.builder() .dayCount(ACT_365F) .index(GBP_LIBOR_2M) .fixingDateOffset(MINUS_TWO_DAYS) .initialStub(IborRateStubCalculation.ofIborInterpolatedRate(GBP_LIBOR_1W, GBP_LIBOR_1M)) .build(); RateAccrualPeriod rap1 = RateAccrualPeriod.builder(ACCRUAL1STUB) .yearFraction(ACCRUAL1STUB.yearFraction(ACT_365F, ACCRUAL_SCHEDULE_STUBS)) .rateComputation(IborInterpolatedRateComputation.of(GBP_LIBOR_1W, GBP_LIBOR_1M, DATE_01_06, REF_DATA)) .build(); ImmutableList<RateAccrualPeriod> periods = test.createAccrualPeriods(SINGLE_ACCRUAL_SCHEDULE_STUB, SINGLE_ACCRUAL_SCHEDULE_STUB, REF_DATA); assertEquals(periods, ImmutableList.of(rap1)); }
public void test_resolve_IborInterpolated() { Fra fra = Fra.builder() .buySell(SELL) .notional(NOTIONAL_1M) .startDate(date(2015, 6, 12)) .endDate(date(2015, 9, 5)) .businessDayAdjustment(BDA_MOD_FOLLOW) .fixedRate(FIXED_RATE) .index(GBP_LIBOR_3M) .indexInterpolated(GBP_LIBOR_2M) .fixingDateOffset(MINUS_TWO_DAYS) .build(); ResolvedFra test = fra.resolve(REF_DATA); assertEquals(test.getCurrency(), GBP); assertEquals(test.getNotional(), -NOTIONAL_1M, 0d); // sell assertEquals(test.getStartDate(), date(2015, 6, 12)); assertEquals(test.getEndDate(), date(2015, 9, 7)); assertEquals(test.getPaymentDate(), date(2015, 6, 12)); assertEquals(test.getFixedRate(), FIXED_RATE, 0d); assertEquals(test.getFloatingRate(), IborInterpolatedRateComputation.of(GBP_LIBOR_2M, GBP_LIBOR_3M, date(2015, 6, 10), REF_DATA)); assertEquals(test.getYearFraction(), ACT_365F.yearFraction(date(2015, 6, 12), date(2015, 9, 7)), 0d); assertEquals(test.getDiscounting(), ISDA); }
public void test_expand_stubCalcsTwoStubs_interpolated() { IborRateCalculation test = IborRateCalculation.builder() .dayCount(ACT_365F) .index(GBP_LIBOR_1M) .fixingDateOffset(MINUS_TWO_DAYS) .initialStub(IborRateStubCalculation.ofIborInterpolatedRate(GBP_LIBOR_1W, GBP_LIBOR_1M)) .finalStub(IborRateStubCalculation.ofIborInterpolatedRate(GBP_LIBOR_3M, GBP_LIBOR_1M)) .build(); RateAccrualPeriod rap1 = RateAccrualPeriod.builder(ACCRUAL1STUB) .yearFraction(ACCRUAL1STUB.yearFraction(ACT_365F, ACCRUAL_SCHEDULE_STUBS)) .rateComputation(IborInterpolatedRateComputation.of(GBP_LIBOR_1W, GBP_LIBOR_1M, DATE_01_06, REF_DATA)) .build(); RateAccrualPeriod rap2 = RateAccrualPeriod.builder(ACCRUAL2) .yearFraction(ACCRUAL2.yearFraction(ACT_365F, ACCRUAL_SCHEDULE_STUBS)) .rateComputation(IborRateComputation.of(GBP_LIBOR_1M, DATE_02_03, REF_DATA)) .build(); RateAccrualPeriod rap3 = RateAccrualPeriod.builder(ACCRUAL3STUB) .yearFraction(ACCRUAL3STUB.yearFraction(ACT_365F, ACCRUAL_SCHEDULE_STUBS)) .rateComputation(IborInterpolatedRateComputation.of(GBP_LIBOR_1M, GBP_LIBOR_3M, DATE_03_03, REF_DATA)) .build(); ImmutableList<RateAccrualPeriod> periods = test.createAccrualPeriods(ACCRUAL_SCHEDULE_STUBS, ACCRUAL_SCHEDULE_STUBS, REF_DATA); assertEquals(periods, ImmutableList.of(rap1, rap2, rap3)); }
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)); }