/** * Creates an instance from an index and accrual period dates * <p> * The dates represent the accrual period. * <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 OvernightAveragedRateComputation of( OvernightIndex index, LocalDate startDate, LocalDate endDate, ReferenceData refData) { return of(index, startDate, endDate, 0, refData); }
private double rateForward(OvernightAveragedRateComputation computation, OvernightIndexRates rates) { OvernightIndex index = computation.getIndex(); HolidayCalendar calendar = computation.getFixingCalendar(); LocalDate startFixingDate = computation.getStartDate(); LocalDate endFixingDateP1 = computation.getEndDate(); LocalDate endFixingDate = calendar.previous(endFixingDateP1); LocalDate onRateEndDate = computation.calculateMaturityFromFixing(endFixingDate); LocalDate onRateStartDate = computation.calculateEffectiveFromFixing(startFixingDate); LocalDate onRateNoCutOffEndDate = onRateEndDate; int cutoffOffset = computation.getRateCutOffDays() > 1 ? computation.getRateCutOffDays() : 1; double accumulatedInterest = 0.0d; double accrualFactorTotal = index.getDayCount().yearFraction(onRateStartDate, onRateEndDate); if (cutoffOffset > 1) { // Cut-off period LocalDate currentFixingDate = endFixingDate; OvernightIndexObservation lastIndexObs = null; double cutOffAccrualFactorTotal = 0d; for (int i = 1; i < cutoffOffset; i++) { currentFixingDate = calendar.previous(currentFixingDate); lastIndexObs = computation.observeOn(currentFixingDate); onRateNoCutOffEndDate = lastIndexObs.getMaturityDate(); cutOffAccrualFactorTotal += lastIndexObs.getYearFraction(); } double forwardRateCutOff = rates.rate(lastIndexObs); accumulatedInterest += cutOffAccrualFactorTotal * forwardRateCutOff; } // Approximated part accumulatedInterest += approximatedInterest(computation.observeOn(onRateStartDate), onRateNoCutOffEndDate, rates); // final rate return accumulatedInterest / accrualFactorTotal; }
@Override public PointSensitivityBuilder rateSensitivity( OvernightAveragedRateComputation computation, LocalDate startDate, LocalDate endDate, RatesProvider provider) { OvernightIndexRates rates = provider.overnightIndexRates(computation.getIndex()); LocalDate valuationDate = rates.getValuationDate(); LocalDate startFixingDate = computation.getStartDate(); LocalDate startPublicationDate = computation.calculatePublicationFromFixing(startFixingDate); // No fixing to analyze. Go directly to approximation and cut-off. if (valuationDate.isBefore(startPublicationDate)) { return rateForwardSensitivity(computation, rates); } ObservationDetails details = new ObservationDetails(computation, rates); return details.calculateRateSensitivity(); }
/** * Restricted copy constructor. * @param beanToCopy the bean to copy from, not null */ private Builder(OvernightAveragedRateComputation 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() { OvernightAveragedRateComputation test = OvernightAveragedRateComputation.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_rateCutoff_2() { OvernightAveragedRateComputation test = OvernightAveragedRateComputation.of(USD_FED_FUND, date(2016, 2, 24), date(2016, 3, 24), 2, REF_DATA); OvernightAveragedRateComputation expected = OvernightAveragedRateComputation.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_collectIndices() { OvernightAveragedRateComputation test = OvernightAveragedRateComputation.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)); }
/** * Creates an instance from an index, accrual 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 or zero * @param refData the reference data to use when resolving holiday calendars * @return the rate computation */ public static OvernightAveragedRateComputation of( OvernightIndex index, LocalDate startDate, LocalDate endDate, int rateCutOffDays, ReferenceData refData) { return OvernightAveragedRateComputation.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 ((OvernightAveragedRateComputation) bean).getIndex(); case 394230283: // fixingCalendar return ((OvernightAveragedRateComputation) bean).getFixingCalendar(); case -2129778896: // startDate return ((OvernightAveragedRateComputation) bean).getStartDate(); case -1607727319: // endDate return ((OvernightAveragedRateComputation) bean).getEndDate(); case -92095804: // rateCutOffDays return ((OvernightAveragedRateComputation) bean).getRateCutOffDays(); } return super.propertyGet(bean, propertyName, quiet); }
public void test_of_noRateCutoff() { OvernightAveragedRateComputation test = OvernightAveragedRateComputation.of(USD_FED_FUND, date(2016, 2, 24), date(2016, 3, 24), REF_DATA); OvernightAveragedRateComputation expected = OvernightAveragedRateComputation.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 ObservationDetails(OvernightAveragedRateComputation computation, OvernightIndexRates rates) { this.index = computation.getIndex(); this.rates = rates; LocalDate startFixingDate = computation.getStartDate(); LocalDate endFixingDateP1 = computation.getEndDate(); this.cutoffOffset = computation.getRateCutOffDays() > 1 ? computation.getRateCutOffDays() : 1; double accrualFactorAccumulated = 0d; List<OvernightIndexObservation> indexObsList = new ArrayList<>(); while (currentFixing.isBefore(endFixingDateP1)) { OvernightIndexObservation indexObs = computation.observeOn(currentFixing); indexObsList.add(indexObs); currentFixing = computation.getFixingCalendar().next(currentFixing); accrualFactorAccumulated += indexObs.getYearFraction();
OvernightIndexRates rates) { OvernightIndex index = computation.getIndex(); HolidayCalendar calendar = computation.getFixingCalendar(); LocalDate startFixingDate = computation.getStartDate(); LocalDate endFixingDateP1 = computation.getEndDate(); LocalDate endFixingDate = calendar.previous(endFixingDateP1); LocalDate onRateEndDate = computation.calculateMaturityFromFixing(endFixingDate); LocalDate onRateStartDate = computation.calculateEffectiveFromFixing(startFixingDate); LocalDate lastNonCutOffMatDate = onRateEndDate; int cutoffOffset = computation.getRateCutOffDays() > 1 ? computation.getRateCutOffDays() : 1; PointSensitivityBuilder combinedPointSensitivityBuilder = PointSensitivityBuilder.none(); double accrualFactorTotal = index.getDayCount().yearFraction(onRateStartDate, onRateEndDate); for (int i = 0; i < cutoffOffset; i++) { currentFixingDate = calendar.previous(currentFixingDate); cutOffEffectiveDate = computation.calculateEffectiveFromFixing(currentFixingDate); lastNonCutOffMatDate = computation.calculateMaturityFromEffective(cutOffEffectiveDate); double accrualFactor = index.getDayCount().yearFraction(cutOffEffectiveDate, lastNonCutOffMatDate); noCutOffAccrualFactorList.add(accrualFactor); OvernightIndexObservation lastIndexObs = computation.observeOn(currentFixingDate); PointSensitivityBuilder forwardRateCutOffSensitivity = rates.ratePointSensitivity(lastIndexObs); double totalAccrualFactor = 0.0; OvernightIndexObservation indexObs = computation.observeOn(onRateStartDate); PointSensitivityBuilder approximatedInterestAndSensitivity = approximatedInterestSensitivity(indexObs, lastNonCutOffMatDate, rates);
return OvernightCompoundedAnnualRateComputation.of(index, startDate, endDate, referenceData); case AVERAGED: return OvernightAveragedRateComputation.of(index, startDate, endDate, rateCutOffDays, referenceData); case AVERAGED_DAILY: return OvernightAveragedDailyRateComputation.of(index, startDate, endDate, referenceData);
public void test_of_rateCutoff_0() { OvernightAveragedRateComputation test = OvernightAveragedRateComputation.of(USD_FED_FUND, date(2016, 2, 24), date(2016, 3, 24), 0, REF_DATA); OvernightAveragedRateComputation expected = OvernightAveragedRateComputation.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); }
@Override public double rate( OvernightAveragedRateComputation computation, LocalDate startDate, LocalDate endDate, RatesProvider provider) { OvernightIndexRates rates = provider.overnightIndexRates(computation.getIndex()); LocalDate valuationDate = rates.getValuationDate(); LocalDate startFixingDate = computation.getStartDate(); LocalDate startPublicationDate = computation.calculatePublicationFromFixing(startFixingDate); // No fixing to analyze. Go directly to approximation and cut-off. if (valuationDate.isBefore(startPublicationDate)) { return rateForward(computation, rates); } ObservationDetails details = new ObservationDetails(computation, rates); return details.calculateRate(); }
RatesProvider provider) { OvernightIndex index = computation.getIndex(); OvernightIndexRates rates = provider.overnightIndexRates(index); LocalDate lastNonCutoffFixing = computation.getEndDate(); int cutoffOffset = computation.getRateCutOffDays() > 1 ? computation.getRateCutOffDays() : 1; double accumulatedInterest = 0.0d; double accrualFactorTotal = 0.0d; lastNonCutoffFixing = computation.getFixingCalendar().previous(lastNonCutoffFixing); lastIndexObs = computation.observeOn(lastNonCutoffFixing); accrualFactorTotal += lastIndexObs.getYearFraction(); cutoffAccrualFactor += lastIndexObs.getYearFraction(); LocalDate currentFixingNonCutoff = computation.getStartDate(); while (currentFixingNonCutoff.isBefore(lastNonCutoffFixing)) { OvernightIndexObservation indexObs = computation.observeOn(currentFixingNonCutoff); double forwardRate = rates.rate(indexObs); accrualFactorTotal += indexObs.getYearFraction(); accumulatedInterest += indexObs.getYearFraction() * forwardRate; currentFixingNonCutoff = computation.getFixingCalendar().next(currentFixingNonCutoff);
public void test_rate_OvernightAveragedRateComputation() { double mockRate = 0.0123d; RateComputationFn<OvernightAveragedRateComputation> mockOnAve = mock(RateComputationFn.class); OvernightAveragedRateComputation ro = OvernightAveragedRateComputation.of(USD_FED_FUND, ACCRUAL_START_DATE, ACCRUAL_END_DATE, 0, REF_DATA); when(mockOnAve.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, MOCK_ON_CPD_EMPTY, MOCK_BRL_ON_CPD_EMPTY, mockOnAve, 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_tomNext() { OvernightAveragedRateComputation test = OvernightAveragedRateComputation.of(CHF_TOIS, date(2016, 2, 24), date(2016, 3, 24), REF_DATA); OvernightAveragedRateComputation expected = OvernightAveragedRateComputation.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); }
RatesProvider provider) { OvernightIndex index = computation.getIndex(); OvernightIndexRates rates = provider.overnightIndexRates(index); LocalDate lastNonCutoffFixing = computation.getEndDate(); int cutoffOffset = computation.getRateCutOffDays() > 1 ? computation.getRateCutOffDays() : 1; double accrualFactorTotal = 0.0d; lastNonCutoffFixing = computation.getFixingCalendar().previous(lastNonCutoffFixing); lastIndexObs = computation.observeOn(lastNonCutoffFixing); accrualFactorTotal += lastIndexObs.getYearFraction(); cutoffAccrualFactor += lastIndexObs.getYearFraction(); .multipliedBy(cutoffAccrualFactor); LocalDate currentFixingNonCutoff = computation.getStartDate(); while (currentFixingNonCutoff.isBefore(lastNonCutoffFixing)) { OvernightIndexObservation indexObs = computation.observeOn(currentFixingNonCutoff); PointSensitivityBuilder forwardRateSensitivity = rates.ratePointSensitivity(indexObs) .multipliedBy(indexObs.getYearFraction()); combinedPointSensitivityBuilder = combinedPointSensitivityBuilder.combinedWith(forwardRateSensitivity); accrualFactorTotal += indexObs.getYearFraction(); currentFixingNonCutoff = computation.getFixingCalendar().next(currentFixingNonCutoff);