private ObservationDetails(OvernightCompoundedAnnualRateComputation computation, OvernightIndexRates rates) { this.computation = computation; this.rates = rates; this.indexFixingDateSeries = rates.getFixings(); this.dayCount = computation.getIndex().getDayCount(); this.firstFixing = computation.getStartDate(); this.lastFixingP1 = computation.getEndDate(); this.lastFixing = computation.getFixingCalendar().previous(lastFixingP1); 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.isAfter(lastFixing)) && rates.getValuationDate().isAfter(currentPublication)) { LocalDate effectiveDate = computation.calculateEffectiveFromFixing(currentFixing); LocalDate maturityDate = computation.calculateMaturityFromEffective(effectiveDate); double accrualFactor = dayCount.yearFraction(effectiveDate, maturityDate); double rate = checkedFixing(currentFixing, indexFixingDateSeries, computation.getIndex()); compositionFactor *= Math.pow(1.0d + rate, accrualFactor); currentFixing = computation.getFixingCalendar().next(currentFixing); currentPublication = computation.calculatePublicationFromFixing(currentFixing); } nextFixing = currentFixing; return compositionFactor; }
private double futureCompositionFactor() { if (!nextFixing.isAfter(lastFixing)) { OvernightIndexObservation obs = computation.observeOn(nextFixing); LocalDate startDate = obs.getEffectiveDate(); LocalDate endDate = computation.getEndDate(); double accrualFactor = dayCount.yearFraction(startDate, endDate); double rate = rates.periodRate(obs, endDate); return 1.0d + accrualFactor * rate; } return 1.0d; }
/** * Restricted copy constructor. * @param beanToCopy the bean to copy from, not null */ private Builder(OvernightCompoundedAnnualRateComputation beanToCopy) { this.index = beanToCopy.getIndex(); this.fixingCalendar = beanToCopy.getFixingCalendar(); this.startDate = beanToCopy.getStartDate(); this.endDate = beanToCopy.getEndDate(); }
return OvernightCompoundedRateComputation.of(index, startDate, endDate, rateCutOffDays, referenceData); case OVERNIGHT_COMPOUNDED_ANNUAL_RATE: return OvernightCompoundedAnnualRateComputation.of(index, startDate, endDate, referenceData); case AVERAGED: return OvernightAveragedRateComputation.of(index, startDate, endDate, rateCutOffDays, referenceData);
public void test_calculate() { OvernightCompoundedAnnualRateComputation test = sut(); assertEquals( test.calculateEffectiveFromFixing(date(2016, 2, 24)), BRL_CDI.calculateEffectiveFromFixing(date(2016, 2, 24), REF_DATA)); assertEquals( test.calculateFixingFromEffective(date(2016, 2, 24)), BRL_CDI.calculateFixingFromEffective(date(2016, 2, 24), REF_DATA)); assertEquals( test.calculatePublicationFromFixing(date(2016, 2, 24)), BRL_CDI.calculatePublicationFromFixing(date(2016, 2, 24), REF_DATA)); assertEquals( test.calculateMaturityFromFixing(date(2016, 2, 24)), BRL_CDI.calculateMaturityFromFixing(date(2016, 2, 24), REF_DATA)); assertEquals( test.calculateMaturityFromEffective(date(2016, 2, 24)), BRL_CDI.calculateMaturityFromEffective(date(2016, 2, 24), REF_DATA)); }
private PointSensitivityBuilder calculateRateSensitivity() { double factor = pastCompositionFactor() * valuationCompositionFactor() / accrualFactorTotal; if (!nextFixing.isAfter(lastFixing)) { OvernightIndexObservation obs = computation.observeOn(nextFixing); LocalDate startDate = obs.getEffectiveDate(); LocalDate endDate = computation.calculateMaturityFromFixing(lastFixing); double accrualFactor = dayCount.yearFraction(startDate, endDate); PointSensitivityBuilder rateSensitivity = rates.periodRatePointSensitivity(obs, endDate); return rateSensitivity.multipliedBy(factor * accrualFactor); } return PointSensitivityBuilder.none(); } }
@Override public double rate( OvernightCompoundedAnnualRateComputation computation, LocalDate startDate, LocalDate endDate, RatesProvider provider) { OvernightIndexRates rates = provider.overnightIndexRates(computation.getIndex()); ForwardOvernightCompoundedAnnualRateComputationFn.ObservationDetails details = new ForwardOvernightCompoundedAnnualRateComputationFn.ObservationDetails(computation, rates); return details.calculateRate(); }
public void test_observeOn() { OvernightCompoundedAnnualRateComputation test = sut(); assertEquals(test.observeOn(date(2016, 2, 24)), OvernightIndexObservation.of(BRL_CDI, date(2016, 2, 24), REF_DATA)); }
@Override protected Object propertyGet(Bean bean, String propertyName, boolean quiet) { switch (propertyName.hashCode()) { case 100346066: // index return ((OvernightCompoundedAnnualRateComputation) bean).getIndex(); case 394230283: // fixingCalendar return ((OvernightCompoundedAnnualRateComputation) bean).getFixingCalendar(); case -2129778896: // startDate return ((OvernightCompoundedAnnualRateComputation) bean).getStartDate(); case -1607727319: // endDate return ((OvernightCompoundedAnnualRateComputation) bean).getEndDate(); } return super.propertyGet(bean, propertyName, quiet); }
private OvernightCompoundedAnnualRateComputation sut() { return OvernightCompoundedAnnualRateComputation.of(BRL_CDI, date(2016, 2, 24), date(2016, 3, 24), REF_DATA); }
@Override public PointSensitivityBuilder rateSensitivity( OvernightCompoundedAnnualRateComputation computation, LocalDate startDate, LocalDate endDate, RatesProvider provider) { OvernightIndexRates rates = provider.overnightIndexRates(computation.getIndex()); ForwardOvernightCompoundedAnnualRateComputationFn.ObservationDetails details = new ForwardOvernightCompoundedAnnualRateComputationFn.ObservationDetails(computation, rates); return details.calculateRateSensitivity(); }
public void test_of() { OvernightCompoundedAnnualRateComputation test = sut(); assertEquals(test.getStartDate(), date(2016, 2, 24)); assertEquals(test.getEndDate(), date(2016, 3, 24)); assertEquals(test.getIndex(), BRL_CDI); assertEquals(test.getFixingCalendar(), BRL_CDI.getFixingCalendar().resolve(REF_DATA)); }
private double valuationCompositionFactor() { LocalDate currentFixing = nextFixing; LocalDate currentPublication = computation.calculatePublicationFromFixing(currentFixing); if (rates.getValuationDate().equals(currentPublication) && !(currentFixing.isAfter(lastFixing))) { 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); return Math.pow(1.0d + fixedRate.getAsDouble(), accrualFactor); } } return 1.0d; }
private OvernightCompoundedAnnualRateComputation sut2() { return OvernightCompoundedAnnualRateComputation.of(USD_FED_FUND, date(2014, 6, 3), date(2014, 7, 3), REF_DATA); }
public void test_rate_overnightCompoundedAnnualRateComputation() { double mockRate = 0.0123d; RateComputationFn<OvernightCompoundedAnnualRateComputation> mockOnBrlCpd = mock(RateComputationFn.class); OvernightCompoundedAnnualRateComputation ro = OvernightCompoundedAnnualRateComputation.of(USD_FED_FUND, ACCRUAL_START_DATE, ACCRUAL_END_DATE, REF_DATA); when(mockOnBrlCpd.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, mockOnBrlCpd, 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_badDateOrder() { assertThrowsIllegalArg(() -> OvernightCompoundedAnnualRateComputation.of( BRL_CDI, date(2016, 2, 24), date(2016, 2, 24), REF_DATA)); assertThrowsIllegalArg(() -> OvernightCompoundedAnnualRateComputation.of( BRL_CDI, date(2016, 2, 25), date(2016, 2, 24), REF_DATA)); }
public void test_rateForward() { LocalDate[] valuationDate = {date(2015, 1, 1), date(2015, 1, 8)}; OvernightCompoundedAnnualRateComputation ro = OvernightCompoundedAnnualRateComputation.of(BRL_CDI, FIXING_START_DATE, FIXING_END_DATE, REF_DATA); OvernightIndexRates mockRates = mock(OvernightIndexRates.class); when(mockRates.getIndex()).thenReturn(BRL_CDI); SimpleRatesProvider simpleProv = new SimpleRatesProvider(mockRates); double rateCmp = 0.0123; when(mockRates.periodRate(BRL_OBS[1], FIXING_END_DATE)).thenReturn(rateCmp); double rateExpected = rateCmp; for (int loopvaldate = 0; loopvaldate < 2; loopvaldate++) { when(mockRates.getValuationDate()).thenReturn(valuationDate[loopvaldate]); double rateComputed = OBS_BRL_FWD_ONCMP.rate(ro, DUMMY_ACCRUAL_START_DATE, DUMMY_ACCRUAL_END_DATE, simpleProv); assertEquals(rateExpected, rateComputed, TOLERANCE_RATE); } // explain ExplainMapBuilder builder = ExplainMap.builder(); double explainedRate = OBS_BRL_FWD_ONCMP.explainRate( ro, DUMMY_ACCRUAL_START_DATE, DUMMY_ACCRUAL_END_DATE, simpleProv, builder); assertEquals(explainedRate, rateExpected, TOLERANCE_RATE); ExplainMap built = builder.build(); assertEquals(built.get(ExplainKey.OBSERVATIONS).isPresent(), false); assertEquals(built.get(ExplainKey.COMBINED_RATE).get().doubleValue(), rateExpected, TOLERANCE_RATE); }
public void test_rateAllFixedSensitivity() { LocalDate[] valuationDate = {date(2015, 1, 16), date(2015, 1, 17)}; OvernightCompoundedAnnualRateComputation ro = OvernightCompoundedAnnualRateComputation.of(BRL_CDI, FIXING_START_DATE, FIXING_END_DATE, REF_DATA); OvernightIndexRates mockRates = mock(OvernightIndexRates.class); when(mockRates.getIndex()).thenReturn(BRL_CDI); SimpleRatesProvider simpleProv = new SimpleRatesProvider(mockRates); LocalDateDoubleTimeSeriesBuilder tsb = LocalDateDoubleTimeSeries.builder(); int lastFixing = 7; for (int i = 0; i < lastFixing; i++) { tsb.put(FIXING_DATES[i], FIXING_RATES[i]); } when(mockRates.getFixings()).thenReturn(tsb.build()); for (int loopvaldate = 0; loopvaldate < valuationDate.length; loopvaldate++) { when(mockRates.getValuationDate()).thenReturn(valuationDate[loopvaldate]); PointSensitivityBuilder sensitivityComputed = OBS_BRL_FWD_ONCMP.rateSensitivity(ro, DUMMY_ACCRUAL_START_DATE, DUMMY_ACCRUAL_END_DATE, simpleProv); assertEquals(sensitivityComputed, PointSensitivityBuilder.none()); } }
public void test_rateAndSensitivityMissingFixing() { LocalDate valuationDate = date(2015, 1, 13); OvernightCompoundedAnnualRateComputation ro = OvernightCompoundedAnnualRateComputation.of(BRL_CDI, FIXING_START_DATE, FIXING_END_DATE, REF_DATA); OvernightIndexRates mockRates = mock(OvernightIndexRates.class); when(mockRates.getIndex()).thenReturn(BRL_CDI); SimpleRatesProvider simpleProv = new SimpleRatesProvider(valuationDate, mockRates); when(mockRates.getValuationDate()).thenReturn(valuationDate); LocalDateDoubleTimeSeriesBuilder tsb = LocalDateDoubleTimeSeries.builder(); int lastFixing = 2; for (int i = 0; i < lastFixing; i++) { tsb.put(FIXING_DATES[i], FIXING_RATES[i]); } when(mockRates.getFixings()).thenReturn(tsb.build()); for (int i = 0; i < lastFixing; i++) { when(mockRates.rate(BRL_OBS[i])).thenReturn(FIXING_RATES[i]); } for (int i = lastFixing; i < BRL_OBS.length; i++) { when(mockRates.rate(BRL_OBS[i])).thenReturn(FORWARD_RATES[i]); } assertThrows( () -> OBS_BRL_FWD_ONCMP.rate(ro, DUMMY_ACCRUAL_START_DATE, DUMMY_ACCRUAL_END_DATE, simpleProv), PricingException.class); assertThrows( () -> OBS_BRL_FWD_ONCMP.rateSensitivity(ro, DUMMY_ACCRUAL_START_DATE, DUMMY_ACCRUAL_END_DATE, simpleProv), PricingException.class); }