/** * Creates an instance from an index and period dates * <p> * No rate cut-off applies. * * @param index the index * @param startDate the first date of the accrual period * @param endDate the last date of the accrual period * @param refData the reference data to use when resolving holiday calendars * @return the rate computation */ public static OvernightCompoundedRateComputation of( OvernightIndex index, LocalDate startDate, LocalDate endDate, ReferenceData refData) { return of(index, startDate, endDate, 0, refData); }
private ObservationDetails(OvernightCompoundedRateComputation computation, OvernightIndexRates rates) { this.computation = computation; this.rates = rates; this.indexFixingDateSeries = rates.getFixings(); this.dayCount = computation.getIndex().getDayCount(); // Details of the cutoff period this.firstFixing = computation.getStartDate(); this.lastFixingP1 = computation.getEndDate(); this.lastFixing = computation.getFixingCalendar().previous(lastFixingP1); this.cutoffOffset = Math.max(computation.getRateCutOffDays(), 1); this.accrualFactorCutoff = new double[cutoffOffset - 1]; LocalDate currentFixing = lastFixing; for (int i = 0; i < cutoffOffset - 1; i++) { currentFixing = computation.getFixingCalendar().previous(currentFixing); LocalDate effectiveDate = computation.calculateEffectiveFromFixing(currentFixing); LocalDate maturityDate = computation.calculateMaturityFromEffective(effectiveDate); accrualFactorCutoff[i] = dayCount.yearFraction(effectiveDate, maturityDate); } this.lastFixingNonCutoff = currentFixing; LocalDate startUnderlyingPeriod = computation.calculateEffectiveFromFixing(firstFixing); LocalDate endUnderlyingPeriod = computation.calculateMaturityFromFixing(lastFixing); this.accrualFactorTotal = dayCount.yearFraction(startUnderlyingPeriod, endUnderlyingPeriod); }
private double pastCompositionFactor() { double compositionFactor = 1.0d; LocalDate currentFixing = firstFixing; LocalDate currentPublication = computation.calculatePublicationFromFixing(currentFixing); while ((currentFixing.isBefore(lastFixingNonCutoff)) && // fixing in the non-cutoff period rates.getValuationDate().isAfter(currentPublication)) { // publication before valuation LocalDate effectiveDate = computation.calculateEffectiveFromFixing(currentFixing); LocalDate maturityDate = computation.calculateMaturityFromEffective(effectiveDate); double accrualFactor = dayCount.yearFraction(effectiveDate, maturityDate); compositionFactor *= 1.0d + accrualFactor * checkedFixing(currentFixing, indexFixingDateSeries, computation.getIndex()); currentFixing = computation.getFixingCalendar().next(currentFixing); currentPublication = computation.calculatePublicationFromFixing(currentFixing); } if (currentFixing.equals(lastFixingNonCutoff) && // fixing is on the last non-cutoff date, cutoff period known rates.getValuationDate().isAfter(currentPublication)) { // publication before valuation double rate = checkedFixing(currentFixing, indexFixingDateSeries, computation.getIndex()); LocalDate effectiveDate = computation.calculateEffectiveFromFixing(currentFixing); LocalDate maturityDate = computation.calculateMaturityFromEffective(effectiveDate); double accrualFactor = dayCount.yearFraction(effectiveDate, maturityDate); compositionFactor *= 1.0d + accrualFactor * rate; for (int i = 0; i < cutoffOffset - 1; i++) { compositionFactor *= 1.0d + accrualFactorCutoff[i] * rate; } currentFixing = computation.getFixingCalendar().next(currentFixing); } nextFixing = currentFixing; return compositionFactor; }
/** * Restricted copy constructor. * @param beanToCopy the bean to copy from, not null */ private Builder(OvernightCompoundedRateComputation beanToCopy) { this.index = beanToCopy.getIndex(); this.fixingCalendar = beanToCopy.getFixingCalendar(); this.startDate = beanToCopy.getStartDate(); this.endDate = beanToCopy.getEndDate(); this.rateCutOffDays = beanToCopy.getRateCutOffDays(); }
public void test_calculate() { OvernightCompoundedRateComputation test = OvernightCompoundedRateComputation.of(USD_FED_FUND, date(2016, 2, 24), date(2016, 3, 24), REF_DATA); assertEquals( test.calculateEffectiveFromFixing(date(2016, 2, 24)), USD_FED_FUND.calculateEffectiveFromFixing(date(2016, 2, 24), REF_DATA)); assertEquals( test.calculateFixingFromEffective(date(2016, 2, 24)), USD_FED_FUND.calculateFixingFromEffective(date(2016, 2, 24), REF_DATA)); assertEquals( test.calculatePublicationFromFixing(date(2016, 2, 24)), USD_FED_FUND.calculatePublicationFromFixing(date(2016, 2, 24), REF_DATA)); assertEquals( test.calculateMaturityFromFixing(date(2016, 2, 24)), USD_FED_FUND.calculateMaturityFromFixing(date(2016, 2, 24), REF_DATA)); assertEquals( test.calculateMaturityFromEffective(date(2016, 2, 24)), USD_FED_FUND.calculateMaturityFromEffective(date(2016, 2, 24), REF_DATA)); }
public void test_of_noRateCutoff_tomNext() { OvernightCompoundedRateComputation test = OvernightCompoundedRateComputation.of(CHF_TOIS, date(2016, 2, 24), date(2016, 3, 24), 0, REF_DATA); OvernightCompoundedRateComputation expected = OvernightCompoundedRateComputation.builder() .index(CHF_TOIS) .fixingCalendar(CHF_TOIS.getFixingCalendar().resolve(REF_DATA)) .startDate(date(2016, 2, 23)) .endDate(date(2016, 3, 23)) .rateCutOffDays(0) .build(); assertEquals(test, expected); }
private double compositionFactorNonCutoff() { if (!nextFixing.isAfter(lastFixingNonCutoff)) { OvernightIndexObservation obs = computation.observeOn(nextFixing); LocalDate startDate = obs.getEffectiveDate(); LocalDate endDate = computation.calculateMaturityFromFixing(lastFixingNonCutoff); double accrualFactor = dayCount.yearFraction(startDate, endDate); double rate = rates.periodRate(obs, endDate); return 1.0d + accrualFactor * rate; } return 1.0d; }
public void test_collectIndices() { OvernightCompoundedRateComputation test = OvernightCompoundedRateComputation.of(USD_FED_FUND, date(2016, 2, 24), date(2016, 3, 24), REF_DATA); ImmutableSet.Builder<Index> builder = ImmutableSet.builder(); test.collectIndices(builder); assertEquals(builder.build(), ImmutableSet.of(USD_FED_FUND)); }
@Override public double rate( OvernightCompoundedRateComputation computation, LocalDate startDate, LocalDate endDate, RatesProvider provider) { OvernightIndexRates rates = provider.overnightIndexRates(computation.getIndex()); ObservationDetails details = new ObservationDetails(computation, rates); return details.calculateRate(); }
/** * Creates an instance from an index, period dates and rate cut-off. * <p> * Rate cut-off applies if the cut-off is 2 or greater. * A value of 0 or 1 should be used if no cut-off applies. * * @param index the index * @param startDate the first date of the accrual period * @param endDate the last date of the accrual period * @param rateCutOffDays the rate cut-off days offset, not negative * @param refData the reference data to use when resolving holiday calendars * @return the rate computation */ public static OvernightCompoundedRateComputation of( OvernightIndex index, LocalDate startDate, LocalDate endDate, int rateCutOffDays, ReferenceData refData) { return OvernightCompoundedRateComputation.builder() .index(index) .fixingCalendar(index.getFixingCalendar().resolve(refData)) .startDate(index.calculateFixingFromEffective(startDate, refData)) .endDate(index.calculateFixingFromEffective(endDate, refData)) .rateCutOffDays(rateCutOffDays) .build(); }
@Override protected Object propertyGet(Bean bean, String propertyName, boolean quiet) { switch (propertyName.hashCode()) { case 100346066: // index return ((OvernightCompoundedRateComputation) bean).getIndex(); case 394230283: // fixingCalendar return ((OvernightCompoundedRateComputation) bean).getFixingCalendar(); case -2129778896: // startDate return ((OvernightCompoundedRateComputation) bean).getStartDate(); case -1607727319: // endDate return ((OvernightCompoundedRateComputation) bean).getEndDate(); case -92095804: // rateCutOffDays return ((OvernightCompoundedRateComputation) bean).getRateCutOffDays(); } return super.propertyGet(bean, propertyName, quiet); }
public void test_of_rateCutoff_0() { OvernightCompoundedRateComputation test = OvernightCompoundedRateComputation.of(USD_FED_FUND, date(2016, 2, 24), date(2016, 3, 24), 0, REF_DATA); OvernightCompoundedRateComputation expected = OvernightCompoundedRateComputation.builder() .index(USD_FED_FUND) .fixingCalendar(USD_FED_FUND.getFixingCalendar().resolve(REF_DATA)) .startDate(date(2016, 2, 24)) .endDate(date(2016, 3, 24)) .rateCutOffDays(0) .build(); assertEquals(test, expected); }
private ObjDoublePair<PointSensitivityBuilder> compositionFactorAndSensitivityNonCutoff() { if (!nextFixing.isAfter(lastFixingNonCutoff)) { OvernightIndexObservation obs = computation.observeOn(nextFixing); LocalDate startDate = obs.getEffectiveDate(); LocalDate endDate = computation.calculateMaturityFromFixing(lastFixingNonCutoff); double accrualFactor = dayCount.yearFraction(startDate, endDate); double rate = rates.periodRate(obs, endDate); PointSensitivityBuilder rateSensitivity = rates.periodRatePointSensitivity(obs, endDate); rateSensitivity = rateSensitivity.multipliedBy(accrualFactor); return ObjDoublePair.of(rateSensitivity, 1.0d + accrualFactor * rate); } return ObjDoublePair.of(PointSensitivityBuilder.none(), 1.0d); }
@Override public PointSensitivityBuilder rateSensitivity( OvernightCompoundedRateComputation computation, LocalDate startDate, LocalDate endDate, RatesProvider provider) { OvernightIndexRates rates = provider.overnightIndexRates(computation.getIndex()); ObservationDetails details = new ObservationDetails(computation, rates); return details.calculateRateSensitivity(); }
return OvernightCompoundedRateComputation.of(index, startDate, endDate, rateCutOffDays, referenceData); case OVERNIGHT_COMPOUNDED_ANNUAL_RATE: return OvernightCompoundedAnnualRateComputation.of(index, startDate, endDate, referenceData);
private double valuationCompositionFactor() { LocalDate currentFixing = nextFixing; LocalDate currentPublication = computation.calculatePublicationFromFixing(currentFixing); if (rates.getValuationDate().equals(currentPublication) && !(currentFixing.isAfter(lastFixingNonCutoff))) { // If currentFixing > lastFixingNonCutoff, everything fixed OptionalDouble fixedRate = indexFixingDateSeries.get(currentFixing); if (fixedRate.isPresent()) { nextFixing = computation.getFixingCalendar().next(nextFixing); LocalDate effectiveDate = computation.calculateEffectiveFromFixing(currentFixing); LocalDate maturityDate = computation.calculateMaturityFromEffective(effectiveDate); double accrualFactor = dayCount.yearFraction(effectiveDate, maturityDate); if (currentFixing.isBefore(lastFixingNonCutoff)) { return 1.0d + accrualFactor * fixedRate.getAsDouble(); } double compositionFactor = 1.0d + accrualFactor * fixedRate.getAsDouble(); for (int i = 0; i < cutoffOffset - 1; i++) { compositionFactor *= 1.0d + accrualFactorCutoff[i] * fixedRate.getAsDouble(); } return compositionFactor; } } return 1.0d; }
public void test_of_rateCutoff_2() { OvernightCompoundedRateComputation test = OvernightCompoundedRateComputation.of(USD_FED_FUND, date(2016, 2, 24), date(2016, 3, 24), 2, REF_DATA); OvernightCompoundedRateComputation expected = OvernightCompoundedRateComputation.builder() .index(USD_FED_FUND) .fixingCalendar(USD_FED_FUND.getFixingCalendar().resolve(REF_DATA)) .startDate(date(2016, 2, 24)) .endDate(date(2016, 3, 24)) .rateCutOffDays(2) .build(); assertEquals(test, expected); }
public void test_rate_OvernightCompoundedRateComputation() { double mockRate = 0.0123d; RateComputationFn<OvernightCompoundedRateComputation> mockOnCpd = mock(RateComputationFn.class); OvernightCompoundedRateComputation ro = OvernightCompoundedRateComputation.of(USD_FED_FUND, ACCRUAL_START_DATE, ACCRUAL_END_DATE, 0, REF_DATA); when(mockOnCpd.rate(ro, ACCRUAL_START_DATE, ACCRUAL_END_DATE, MOCK_PROV)) .thenReturn(mockRate); DispatchingRateComputationFn test = new DispatchingRateComputationFn( MOCK_IBOR_EMPTY, MOCK_IBOR_INT_EMPTY, MOCK_IBOR_AVE_EMPTY, mockOnCpd, 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, TOLERANCE_RATE); }
public void test_of_noRateCutoff() { OvernightCompoundedRateComputation test = OvernightCompoundedRateComputation.of(USD_FED_FUND, date(2016, 2, 24), date(2016, 3, 24), REF_DATA); OvernightCompoundedRateComputation expected = OvernightCompoundedRateComputation.builder() .index(USD_FED_FUND) .fixingCalendar(USD_FED_FUND.getFixingCalendar().resolve(REF_DATA)) .startDate(date(2016, 2, 24)) .endDate(date(2016, 3, 24)) .rateCutOffDays(0) .build(); assertEquals(test, expected); }