private double cutOffAccumulation() { double accumulatedInterest = 0.0d; int nbPeriodNotCutOff = nbPeriods - cutoffOffset + 1; for (int i = Math.max(fixedPeriod, nbPeriodNotCutOff); i < nbPeriods; i++) { OvernightIndexObservation obs = observations.get(i); double forwardRate = rates.rate(obs); accumulatedInterest += obs.getYearFraction() * forwardRate; } return accumulatedInterest; }
private PointSensitivityBuilder cutOffAccumulationSensitivity() { PointSensitivityBuilder combinedPointSensitivityBuilder = PointSensitivityBuilder.none(); int nbPeriodNotCutOff = nbPeriods - cutoffOffset + 1; for (int i = Math.max(fixedPeriod, nbPeriodNotCutOff); i < nbPeriods; i++) { OvernightIndexObservation obs = observations.get(i); PointSensitivityBuilder forwardRateSensitivity = rates.ratePointSensitivity(obs) .multipliedBy(obs.getYearFraction()); combinedPointSensitivityBuilder = combinedPointSensitivityBuilder.combinedWith(forwardRateSensitivity); } return combinedPointSensitivityBuilder; }
@Override public double rateIgnoringFixings(OvernightIndexObservation observation) { LocalDate effectiveDate = observation.getEffectiveDate(); LocalDate maturityDate = observation.getMaturityDate(); double accrualFactor = observation.getYearFraction(); return simplyCompoundForwardRate(effectiveDate, maturityDate, accrualFactor); }
private double pastAccumulation() { double accumulatedInterest = 0.0d; LocalDateDoubleTimeSeries indexFixingDateSeries = rates.getFixings(); while ((fixedPeriod < nbPeriods) && rates.getValuationDate().isAfter(observations.get(fixedPeriod).getPublicationDate())) { OvernightIndexObservation obs = observations.get(fixedPeriod); accumulatedInterest += obs.getYearFraction() * checkedFixing(obs.getFixingDate(), indexFixingDateSeries, index); fixedPeriod++; } return accumulatedInterest; }
private double valuationDateAccumulation() { double accumulatedInterest = 0.0d; LocalDateDoubleTimeSeries indexFixingDateSeries = rates.getFixings(); boolean ratePresent = true; while (ratePresent && fixedPeriod < nbPeriods && rates.getValuationDate().isEqual(observations.get(fixedPeriod).getPublicationDate())) { OvernightIndexObservation obs = observations.get(fixedPeriod); OptionalDouble fixedRate = indexFixingDateSeries.get(obs.getFixingDate()); if (fixedRate.isPresent()) { accumulatedInterest += obs.getYearFraction() * fixedRate.getAsDouble(); fixedPeriod++; } else { ratePresent = false; } } return accumulatedInterest; }
/** * Restricted copy constructor. * @param beanToCopy the bean to copy from, not null */ private Builder(OvernightIndexObservation beanToCopy) { this.index = beanToCopy.getIndex(); this.fixingDate = beanToCopy.getFixingDate(); this.publicationDate = beanToCopy.getPublicationDate(); this.effectiveDate = beanToCopy.getEffectiveDate(); this.maturityDate = beanToCopy.getMaturityDate(); this.yearFraction = beanToCopy.getYearFraction(); }
@Override protected Object propertyGet(Bean bean, String propertyName, boolean quiet) { switch (propertyName.hashCode()) { case 100346066: // index return ((OvernightIndexObservation) bean).getIndex(); case 1255202043: // fixingDate return ((OvernightIndexObservation) bean).getFixingDate(); case 1470566394: // publicationDate return ((OvernightIndexObservation) bean).getPublicationDate(); case -930389515: // effectiveDate return ((OvernightIndexObservation) bean).getEffectiveDate(); case -414641441: // maturityDate return ((OvernightIndexObservation) bean).getMaturityDate(); case -1731780257: // yearFraction return ((OvernightIndexObservation) bean).getYearFraction(); } return super.propertyGet(bean, propertyName, quiet); }
indexObsList.add(indexObs); currentFixing = computation.getFixingCalendar().next(currentFixing); accrualFactorAccumulated += indexObs.getYearFraction();
lastNonCutoffFixing = computation.getFixingCalendar().previous(lastNonCutoffFixing); lastIndexObs = computation.observeOn(lastNonCutoffFixing); accrualFactorTotal += lastIndexObs.getYearFraction(); cutoffAccrualFactor += lastIndexObs.getYearFraction(); accrualFactorTotal += indexObs.getYearFraction(); accumulatedInterest += indexObs.getYearFraction() * forwardRate; currentFixingNonCutoff = computation.getFixingCalendar().next(currentFixingNonCutoff);
lastNonCutoffFixing = computation.getFixingCalendar().previous(lastNonCutoffFixing); lastIndexObs = computation.observeOn(lastNonCutoffFixing); accrualFactorTotal += lastIndexObs.getYearFraction(); cutoffAccrualFactor += lastIndexObs.getYearFraction(); .multipliedBy(indexObs.getYearFraction()); combinedPointSensitivityBuilder = combinedPointSensitivityBuilder.combinedWith(forwardRateSensitivity); accrualFactorTotal += indexObs.getYearFraction(); currentFixingNonCutoff = computation.getFixingCalendar().next(currentFixingNonCutoff);
/** No cutoff period and the period entirely forward. Test the approximation part only. */ public void rateFedFundNoCutOffForward() { // publication=1, cutoff=0, effective offset=0, Forward LocalDate[] valuationDate = {date(2015, 1, 1), date(2015, 1, 8)}; OvernightAveragedRateComputation ro = OvernightAveragedRateComputation.of(USD_FED_FUND, FIXING_START_DATE, FIXING_END_DATE, 0, REF_DATA); OvernightIndexRates mockRates = mock(OvernightIndexRates.class); when(mockRates.getIndex()).thenReturn(USD_FED_FUND); SimpleRatesProvider simpleProv = new SimpleRatesProvider(mockRates); for (int i = 0; i < USD_OBS.length; i++) { when(mockRates.rate(USD_OBS[i])).thenReturn(FORWARD_RATES[i]); } double investmentFactor = 1.0; double totalAf = 0.0; for (int i = 1; i < 6; i++) { double af = USD_OBS[i].getYearFraction(); totalAf += af; investmentFactor *= 1.0d + af * FORWARD_RATES[i]; } double rateCmp = (investmentFactor - 1.0d) / totalAf; when(mockRates.periodRate(USD_OBS[1], FIXING_END_DATE)).thenReturn(rateCmp); double rateExpected = Math.log(1.0 + rateCmp * totalAf) / totalAf; for (int loopvaldate = 0; loopvaldate < 2; loopvaldate++) { when(mockRates.getValuationDate()).thenReturn(valuationDate[loopvaldate]); double rateComputed = OBS_FN_APPROX_FWD.rate(ro, DUMMY_ACCRUAL_START_DATE, DUMMY_ACCRUAL_END_DATE, simpleProv); assertEquals(rateComputed, rateExpected, TOLERANCE_RATE); } }
public void test_rateIgnoringFixings_onValuation_fixing() { DiscountOvernightIndexRates test = DiscountOvernightIndexRates.of(GBP_SONIA, DFCURVE, SERIES); LocalDate startDate = GBP_SONIA_VAL.getEffectiveDate(); LocalDate endDate = GBP_SONIA_VAL.getMaturityDate(); double accrualFactor = GBP_SONIA_VAL.getYearFraction(); double expected = (DFCURVE.discountFactor(startDate) / DFCURVE.discountFactor(endDate) - 1) / accrualFactor; assertEquals(test.rateIgnoringFixings(GBP_SONIA_VAL), expected, 1e-8); }
double totalAf = 0.0; for (int i = 1; i < 6; i++) { double af = USD_OBS[i].getYearFraction(); totalAf += af; investmentFactor *= 1.0d + af * FORWARD_RATES[i];
double afApprox = 0.0; for (int i = 1; i < 5; i++) { double af = USD_OBS[i].getYearFraction(); afApprox += af; investmentFactor *= 1.0d + af * FORWARD_RATES[i];
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; }