IborIndexObservation obs = OBSERVATIONS[i]; IborAveragedFixing fixing = IborAveragedFixing.builder() .observation(obs) .weight(WEIGHTS[i]) .build(); fixings.add(fixing); totalWeightedRate += FIXING_VALUES[i] * WEIGHTS[i];
private RateComputation createRateComputationWithResetPeriods( Schedule resetSchedule, DateAdjuster fixingDateAdjuster, Function<LocalDate, IborIndexObservation> iborObservationFn, int scheduleIndex, Double overrideFirstRate, ReferenceData refData) { List<IborAveragedFixing> fixings = new ArrayList<>(); for (int i = 0; i < resetSchedule.size(); i++) { SchedulePeriod resetPeriod = resetSchedule.getPeriod(i); LocalDate fixingDate = fixingDateAdjuster.adjust(fixingRelativeTo.selectBaseDate(resetPeriod)); if (scheduleIndex == 0 && i == 0 && firstFixingDateOffset != null) { fixingDate = firstFixingDateOffset.resolve(refData).adjust(fixingRelativeTo.selectBaseDate(resetPeriod)); } fixings.add(IborAveragedFixing.builder() .observation(iborObservationFn.apply(fixingDate)) .fixedRate(overrideFirstRate != null && i == 0 ? overrideFirstRate : null) .weight(resetPeriods.getResetMethod() == UNWEIGHTED ? 1 : resetPeriod.lengthInDays()) .build()); } return IborAveragedRateComputation.of(fixings); }
IborIndexObservation obs = OBSERVATIONS[i]; IborAveragedFixing fixing = IborAveragedFixing.builder() .observation(obs) .weight(WEIGHTS[i]) .build(); fixings.add(fixing); when(mockIbor.ratePointSensitivity(obs)).thenReturn(SENSITIVITIES[i]);
for (int i = 0; i < fixingDates.length; i++) { IborAveragedFixing fixing = IborAveragedFixing.builder() .observation(IborIndexObservation.of(GBP_LIBOR_3M, fixingDates[i], REF_DATA)) .weight(weights[i]) .build(); fixings.add(fixing);
public void test_rateSensitivity() { IborIndexRates mockIbor = mock(IborIndexRates.class); SimpleRatesProvider prov = new SimpleRatesProvider(); prov.setIborRates(mockIbor); List<IborAveragedFixing> fixings = new ArrayList<>(); double totalWeight = 0.0d; for (int i = 0; i < OBSERVATIONS.length; i++) { IborIndexObservation obs = OBSERVATIONS[i]; IborAveragedFixing fixing = IborAveragedFixing.builder() .observation(obs) .weight(WEIGHTS[i]) .build(); fixings.add(fixing); totalWeight += WEIGHTS[i]; when(mockIbor.ratePointSensitivity(obs)).thenReturn(SENSITIVITIES[i]); } PointSensitivities expected = PointSensitivities.of(ImmutableList.of( IborRateSensitivity.of(OBSERVATIONS[0], WEIGHTS[0] / totalWeight), IborRateSensitivity.of(OBSERVATIONS[1], WEIGHTS[1] / totalWeight), IborRateSensitivity.of(OBSERVATIONS[2], WEIGHTS[2] / totalWeight), IborRateSensitivity.of(OBSERVATIONS[3], WEIGHTS[3] / totalWeight))); IborAveragedRateComputation ro = IborAveragedRateComputation.of(fixings); ForwardIborAveragedRateComputationFn obsFn = ForwardIborAveragedRateComputationFn.DEFAULT; PointSensitivityBuilder test = obsFn.rateSensitivity(ro, ACCRUAL_START_DATE, ACCRUAL_END_DATE, prov); assertEquals(test.build(), expected); }
/** * Creates a {@code IborAveragedFixing} from the fixing date, calculating the weight * from the number of days in the reset period. * <p> * This implements the standard approach to average weights, which is to set each * weight to the actual number of days between the start and end of the reset period. * * @param observation the Ibor observation * @param startDate the start date of the reset period * @param endDate the end date of the reset period * @param fixedRate the fixed rate for the fixing date, optional, may be null * @return the weighted fixing information */ public static IborAveragedFixing ofDaysInResetPeriod( IborIndexObservation observation, LocalDate startDate, LocalDate endDate, Double fixedRate) { ArgChecker.notNull(observation, "observation"); ArgChecker.notNull(startDate, "startDate"); ArgChecker.notNull(endDate, "endDate"); return IborAveragedFixing.builder() .observation(observation) .fixedRate(fixedRate) .weight(endDate.toEpochDay() - startDate.toEpochDay()) .build(); }
@ImmutableDefaults private static void applyDefaults(Builder builder) { builder.weight(1d); }
/** * Creates a {@code IborAveragedFixing} from the fixing date with a weight of 1. * * @param observation the Ibor observation * @param fixedRate the fixed rate for the fixing date, optional, may be null * @return the unweighted fixing information */ public static IborAveragedFixing of(IborIndexObservation observation, Double fixedRate) { return IborAveragedFixing.builder() .observation(observation) .fixedRate(fixedRate) .build(); }
/** * Returns a builder used to create an instance of the bean. * @return the builder, not null */ public static IborAveragedFixing.Builder builder() { return new IborAveragedFixing.Builder(); }
@Override public IborAveragedFixing.Builder builder() { return new IborAveragedFixing.Builder(); }
public void test_ofDaysInResetPeriod() { IborAveragedFixing test = IborAveragedFixing.ofDaysInResetPeriod( GBP_LIBOR_3M_OBS, date(2014, 7, 2), date(2014, 8, 2)); IborAveragedFixing expected = IborAveragedFixing.builder() .observation(GBP_LIBOR_3M_OBS) .fixedRate(null) .weight(31) .build(); assertEquals(test, expected); }
public void test_of_date_fixedRate() { IborAveragedFixing test = IborAveragedFixing.of(GBP_LIBOR_3M_OBS, 0.05); IborAveragedFixing expected = IborAveragedFixing.builder() .observation(GBP_LIBOR_3M_OBS) .fixedRate(0.05) .weight(1) .build(); assertEquals(test, expected); assertEquals(test.getFixedRate(), OptionalDouble.of(0.05)); }
/** * Returns a builder that allows this bean to be mutated. * @return the mutable builder, not null */ public Builder toBuilder() { return new Builder(this); }
public void test_ofDaysInResetPeriod_fixedRate_null() { IborAveragedFixing test = IborAveragedFixing.ofDaysInResetPeriod( GBP_LIBOR_3M_OBS, date(2014, 7, 2), date(2014, 9, 2), null); IborAveragedFixing expected = IborAveragedFixing.builder() .observation(GBP_LIBOR_3M_OBS) .fixedRate(null) .weight(62) .build(); assertEquals(test, expected); assertEquals(test.getFixedRate(), OptionalDouble.empty()); }
public void test_of_date_fixedRate_null() { IborAveragedFixing test = IborAveragedFixing.of(GBP_LIBOR_3M_OBS, null); IborAveragedFixing expected = IborAveragedFixing.builder() .observation(GBP_LIBOR_3M_OBS) .fixedRate(null) .weight(1) .build(); assertEquals(test, expected); assertEquals(test.getFixedRate(), OptionalDouble.empty()); }
public void test_of_date() { IborAveragedFixing test = IborAveragedFixing.of(GBP_LIBOR_3M_OBS); IborAveragedFixing expected = IborAveragedFixing.builder() .observation(GBP_LIBOR_3M_OBS) .fixedRate(null) .weight(1) .build(); assertEquals(test, expected); }
public void test_ofDaysInResetPeriod_fixedRate() { IborAveragedFixing test = IborAveragedFixing.ofDaysInResetPeriod( GBP_LIBOR_3M_OBS, date(2014, 7, 2), date(2014, 9, 2), 0.06); IborAveragedFixing expected = IborAveragedFixing.builder() .observation(GBP_LIBOR_3M_OBS) .fixedRate(0.06) .weight(62) .build(); assertEquals(test, expected); assertEquals(test.getFixedRate(), OptionalDouble.of(0.06)); }