/** * 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(); }
public void test_of() { OvernightIndexObservation test = OvernightIndexObservation.of(GBP_SONIA, FIXING_DATE, REF_DATA); assertEquals(test.getIndex(), GBP_SONIA); assertEquals(test.getFixingDate(), FIXING_DATE); assertEquals(test.getPublicationDate(), PUBLICATION_DATE); assertEquals(test.getEffectiveDate(), EFFECTIVE_DATE); assertEquals(test.getMaturityDate(), MATURITY_DATE); assertEquals(test.getCurrency(), GBP_SONIA.getCurrency()); assertEquals(test.toString(), "OvernightIndexObservation[GBP-SONIA on 2016-02-22]"); }
@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; }
public void test_rate_onPublication_noFixing() { DiscountOvernightIndexRates test = DiscountOvernightIndexRates.of(GBP_SONIA, DFCURVE, SERIES_EMPTY); LocalDate startDate = GBP_SONIA_VAL.getEffectiveDate(); LocalDate endDate = GBP_SONIA_VAL.getMaturityDate(); double accrualFactor = GBP_SONIA.getDayCount().yearFraction(startDate, endDate); double expected = (DFCURVE.discountFactor(startDate) / DFCURVE.discountFactor(endDate) - 1) / accrualFactor; assertEquals(test.rate(GBP_SONIA_VAL), expected, 1e-4); }
private static double approximatedInterest( OvernightIndexObservation observation, LocalDate endDate, OvernightIndexRates rates) { DayCount dayCount = observation.getIndex().getDayCount(); double remainingFixingAccrualFactor = dayCount.yearFraction(observation.getEffectiveDate(), endDate); double forwardRate = rates.periodRate(observation, endDate); return Math.log(1.0 + forwardRate * remainingFixingAccrualFactor); }
public void test_serialization() { OvernightIndexObservation test = OvernightIndexObservation.of(GBP_SONIA, FIXING_DATE, REF_DATA); assertSerialization(test); }
private double approximatedForwardAccumulation() { int nbPeriodNotCutOff = nbPeriods - cutoffOffset + 1; if (fixedPeriod < nbPeriodNotCutOff) { LocalDate endDateApprox = observations.get(nbPeriodNotCutOff - 1).getMaturityDate(); return approximatedInterest(observations.get(fixedPeriod), endDateApprox, rates); } return 0.0d; }
indexObsList.add(indexObs); currentFixing = computation.getFixingCalendar().next(currentFixing); accrualFactorAccumulated += indexObs.getYearFraction(); OvernightIndexObservation fixingIndexObs = indexObsList.get(nbPeriods - cutoffOffset); OvernightIndexObservation cutoffIndexObs = indexObsList.get(nbPeriods - 1 - i); OvernightIndexObservation updatedIndexObs = cutoffIndexObs.toBuilder() .fixingDate(fixingIndexObs.getFixingDate()) .publicationDate(fixingIndexObs.getPublicationDate()) .build(); indexObsList.set(nbPeriods - 1 - i, updatedIndexObs);
@Override public PointSensitivityBuilder periodRatePointSensitivity( OvernightIndexObservation startDateObservation, LocalDate endDate) { LocalDate startDate = startDateObservation.getEffectiveDate(); ArgChecker.inOrderNotEqual(startDate, endDate, "startDate", "endDate"); return OvernightRateSensitivity.ofPeriod(startDateObservation, endDate, 1d); }
private double historicRate(OvernightIndexObservation observation) { LocalDate fixingDate = observation.getFixingDate(); OptionalDouble fixedRate = fixings.get(fixingDate); if (fixedRate.isPresent()) { return fixedRate.getAsDouble(); } else if (observation.getPublicationDate().isBefore(getValuationDate())) { // the fixing is required if (fixings.isEmpty()) { throw new IllegalArgumentException( Messages.format("Unable to get fixing for {} on date {}, no time-series supplied", index, fixingDate)); } throw new IllegalArgumentException(Messages.format("Unable to get fixing for {} on date {}", index, fixingDate)); } else { return rateIgnoringFixings(observation); } }
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 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 int compareKey(PointSensitivity other) { if (other instanceof OvernightRateSensitivity) { OvernightRateSensitivity otherOn = (OvernightRateSensitivity) other; return ComparisonChain.start() .compare(getIndex().toString(), otherOn.getIndex().toString()) .compare(currency, otherOn.currency) .compare(observation.getFixingDate(), otherOn.observation.getFixingDate()) .compare(endDate, otherOn.endDate) .result(); } return getClass().getSimpleName().compareTo(other.getClass().getSimpleName()); }
/** * Gets the Overnight index that the sensitivity refers to. * * @return the Overnight index */ public OvernightIndex getIndex() { return observation.getIndex(); }
@Override public double rate(OvernightIndexObservation observation) { if (!observation.getPublicationDate().isAfter(getValuationDate())) { return historicRate(observation); } return rateIgnoringFixings(observation); }
/** * Obtains an instance from the observation and sensitivity value. * <p> * The currency is defaulted from the index. * The end date will be the maturity date of the observation. * * @param observation the rate observation, including the fixing date * @param sensitivity the value of the sensitivity * @return the point sensitivity object */ public static OvernightRateSensitivity of(OvernightIndexObservation observation, double sensitivity) { return of(observation, observation.getCurrency(), sensitivity); }
/** * Creates an {@code IborRateObservation} from an index and fixing date. * <p> * The reference data is used to find the maturity date from the fixing date. * * @param index the index * @param fixingDate the fixing date * @param refData the reference data to use when resolving holiday calendars * @return the rate observation */ public static OvernightIndexObservation of(OvernightIndex index, LocalDate fixingDate, ReferenceData refData) { LocalDate publicationDate = index.calculatePublicationFromFixing(fixingDate, refData); LocalDate effectiveDate = index.calculateEffectiveFromFixing(fixingDate, refData); LocalDate maturityDate = index.calculateMaturityFromEffective(effectiveDate, refData); return OvernightIndexObservation.builder() .index(index) .fixingDate(fixingDate) .publicationDate(publicationDate) .effectiveDate(effectiveDate) .maturityDate(maturityDate) .yearFraction(index.getDayCount().yearFraction(effectiveDate, maturityDate)) .build(); }
public void test_rate_afterPublication() { DiscountOvernightIndexRates test = DiscountOvernightIndexRates.of(GBP_SONIA, DFCURVE, SERIES); LocalDate startDate = GBP_SONIA_AFTER.getEffectiveDate(); LocalDate endDate = GBP_SONIA_AFTER.getMaturityDate(); double accrualFactor = GBP_SONIA.getDayCount().yearFraction(startDate, endDate); double expected = (DFCURVE.discountFactor(startDate) / DFCURVE.discountFactor(endDate) - 1) / accrualFactor; assertEquals(test.rate(GBP_SONIA_AFTER), expected, 1e-8); }