/** * Creates a {@code IborAveragedFixing} from the fixing date with a weight of 1. * * @param observation the Ibor observation * @return the unweighted fixing information */ public static IborAveragedFixing of(IborIndexObservation observation) { return of(observation, null); }
private double weightedRate(IborAveragedFixing fixing, IborIndexRates rates) { double rate = fixing.getFixedRate().orElse(rates.rate(fixing.getObservation())); return rate * fixing.getWeight(); }
/** * 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 * @return the weighted fixing information */ public static IborAveragedFixing ofDaysInResetPeriod( IborIndexObservation observation, LocalDate startDate, LocalDate endDate) { return ofDaysInResetPeriod(observation, startDate, endDate, null); }
/** * Restricted copy constructor. * @param beanToCopy the bean to copy from, not null */ private Builder(IborAveragedFixing beanToCopy) { this.observation = beanToCopy.getObservation(); this.fixedRate = beanToCopy.fixedRate; this.weight = beanToCopy.getWeight(); }
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_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)); }
/** * 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(); }
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); }
/** * Gets the Ibor index. * <p> * The rate to be paid is based on this index * It will be a well known market index such as 'GBP-LIBOR-3M'. * * @return the Ibor index */ public IborIndex getIndex() { return fixings.get(0).getObservation().getIndex(); }
@Override public PointSensitivityBuilder rateSensitivity( IborAveragedRateComputation computation, LocalDate startDate, LocalDate endDate, RatesProvider provider) { IborIndexRates rates = provider.iborIndexRates(computation.getIndex()); // combine the weighted sensitivity to each fixing // omit fixed rates as they have no sensitivity to a curve return computation.getFixings().stream() .filter(fixing -> !fixing.getFixedRate().isPresent()) .map(fixing -> weightedSensitivity(fixing, computation.getTotalWeight(), rates)) .reduce(PointSensitivityBuilder.none(), PointSensitivityBuilder::combinedWith); }
@Override public IborAveragedFixing build() { return new IborAveragedFixing( observation, fixedRate, weight); }
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)); }
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()); }
@Override protected Object propertyGet(Bean bean, String propertyName, boolean quiet) { switch (propertyName.hashCode()) { case 122345516: // observation return ((IborAveragedFixing) bean).getObservation(); case 747425396: // fixedRate return ((IborAveragedFixing) bean).fixedRate; case -791592328: // weight return ((IborAveragedFixing) bean).getWeight(); } return super.propertyGet(bean, propertyName, quiet); }
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); }
private PointSensitivityBuilder weightedSensitivity( IborAveragedFixing fixing, double totalWeight, IborIndexRates rates) { return rates.ratePointSensitivity(fixing.getObservation()) .multipliedBy(fixing.getWeight() / totalWeight); }
for (int i = 0; i < nDates; i++) { IborIndexObservation obs = OBSERVATIONS[i]; IborAveragedFixing fixing = IborAveragedFixing.builder() .observation(obs) .weight(WEIGHTS[i])
public void test_ofDaysInResetPeriod_null() { assertThrowsIllegalArg(() -> IborAveragedFixing.ofDaysInResetPeriod(null, date(2014, 7, 2), date(2014, 8, 2))); assertThrowsIllegalArg(() -> IborAveragedFixing.ofDaysInResetPeriod(GBP_LIBOR_3M_OBS, null, date(2014, 8, 2))); assertThrowsIllegalArg(() -> IborAveragedFixing.ofDaysInResetPeriod(GBP_LIBOR_3M_OBS, date(2014, 7, 2), null)); assertThrowsIllegalArg(() -> IborAveragedFixing.ofDaysInResetPeriod(null, null, null)); assertThrowsIllegalArg(() -> IborAveragedFixing.ofDaysInResetPeriod(null, date(2014, 7, 2), date(2014, 8, 2), 0.05)); assertThrowsIllegalArg(() -> IborAveragedFixing.ofDaysInResetPeriod(GBP_LIBOR_3M_OBS, null, date(2014, 8, 2), 0.05)); assertThrowsIllegalArg(() -> IborAveragedFixing.ofDaysInResetPeriod(GBP_LIBOR_3M_OBS, date(2014, 7, 2), null, 0.05)); assertThrowsIllegalArg(() -> IborAveragedFixing.ofDaysInResetPeriod(null, null, null, null)); }