@Override public ImmutableList<RateAccrualPeriod> createAccrualPeriods( Schedule accrualSchedule, Schedule paymentSchedule, ReferenceData refData) { // resolve data by schedule DoubleArray resolvedGearings = firstNonNull(gearing, ALWAYS_1).resolveValues(accrualSchedule); // build accrual periods ImmutableList.Builder<RateAccrualPeriod> accrualPeriods = ImmutableList.builder(); for (int i = 0; i < accrualSchedule.size(); i++) { SchedulePeriod period = accrualSchedule.getPeriod(i); // inflation does not use a day count, so year fraction is 1d accrualPeriods.add(new RateAccrualPeriod( period, 1d, createRateComputation(period, i), resolvedGearings.get(i), 0d, NegativeRateMethod.ALLOW_NEGATIVE)); } return accrualPeriods.build(); }
public void test_realPrice_nominalPrice_settleBefore() { double realPrice = 1.055; LocalDate refDate = LocalDate.of(2014, 6, 10); double nominalPrice = PRICER.nominalPriceFromRealPrice(PRODUCT, RATES_PROVIDER_ON_PAY, refDate, realPrice); RateComputation obs = RATE_CALC.createRateComputation(refDate); double refRate = RateComputationFn.standard().rate(obs, null, null, RATES_PROVIDER_ON_PAY); double expected = realPrice * (refRate + 1d); assertEquals(nominalPrice, expected, TOL); assertEquals(PRICER.realPriceFromNominalPrice(PRODUCT, RATES_PROVIDER_ON_PAY, refDate, nominalPrice), realPrice, TOL); }
public void test_realPrice_nominalPrice_settleAfter() { double realPrice = 1.055; LocalDate refDate = LocalDate.of(2014, 6, 10); double nominalPrice = PRICER.nominalPriceFromRealPrice(PRODUCT, RATES_PROVIDER, refDate, realPrice); RateComputation obs = RATE_CALC.createRateComputation(VALUATION); double refRate = RateComputationFn.standard().rate(obs, null, null, RATES_PROVIDER); double expected = realPrice * (refRate + 1d); assertEquals(nominalPrice, expected, TOL); assertEquals(PRICER.realPriceFromNominalPrice(PRODUCT, RATES_PROVIDER, refDate, nominalPrice), realPrice, TOL); }
public void test_cleanNominalPrice_dirtyNominalPrice() { double dirtyNominalPrice = 1.055; LocalDate refDate = LocalDate.of(2014, 6, 10); double cleanNominalPrice = PRICER.cleanNominalPriceFromDirtyNominalPrice(PRODUCT, RATES_PROVIDER, refDate, dirtyNominalPrice); RateComputation obs = RATE_CALC.createRateComputation(VALUATION); double refRate = RateComputationFn.standard().rate(obs, null, null, RATES_PROVIDER); double expected = dirtyNominalPrice - PRODUCT.accruedInterest(refDate) * (refRate + 1d) / NOTIONAL; assertEquals(cleanNominalPrice, expected, TOL); assertEquals(PRICER.dirtyNominalPriceFromCleanNominalPrice(PRODUCT, RATES_PROVIDER, refDate, cleanNominalPrice), dirtyNominalPrice, TOL); }
double indexRatio(ResolvedCapitalIndexedBond bond, RatesProvider ratesProvider, LocalDate settlementDate) { LocalDate endReferenceDate = settlementDate.isBefore(ratesProvider.getValuationDate()) ? ratesProvider.getValuationDate() : settlementDate; RateComputation modifiedComputation = bond.getRateCalculation().createRateComputation(endReferenceDate); return 1d + periodPricer.getRateComputationFn().rate( modifiedComputation, bond.getUnadjustedStartDate(), // dates not used bond.getUnadjustedEndDate(), ratesProvider); }
PointSensitivityBuilder indexRatioSensitivity( ResolvedCapitalIndexedBond bond, RatesProvider ratesProvider, LocalDate settlementDate) { LocalDate endReferenceDate = settlementDate.isBefore(ratesProvider.getValuationDate()) ? ratesProvider.getValuationDate() : settlementDate; RateComputation modifiedComputation = bond.getRateCalculation().createRateComputation(endReferenceDate); return periodPricer.getRateComputationFn().rateSensitivity( modifiedComputation, bond.getUnadjustedStartDate(), // dates not used bond.getUnadjustedEndDate(), ratesProvider); }
public void test_createRateComputation_InterpolatedJapan() { LocalDate date1 = LocalDate.of(2013, 3, 9); LocalDate date2 = LocalDate.of(2013, 3, 10); LocalDate date3 = LocalDate.of(2013, 3, 11); InflationRateCalculation test = InflationRateCalculation.builder() .index(JP_CPI_EXF) .lag(Period.ofMonths(3)) .indexCalculationMethod(INTERPOLATED_JAPAN) .firstIndexValue(START_INDEX) .build(); double weight1 = 1.0 - (9.0 + 28.0 - 10.0) / 28.0; double weight2 = 1.0; double weight3 = 1.0 - 1.0 / 31.0; InflationEndInterpolatedRateComputation obs1 = InflationEndInterpolatedRateComputation.of( JP_CPI_EXF, START_INDEX, YearMonth.from(date1).minusMonths(4), weight1); InflationEndInterpolatedRateComputation obs2 = InflationEndInterpolatedRateComputation.of( JP_CPI_EXF, START_INDEX, YearMonth.from(date2).minusMonths(3), weight2); InflationEndInterpolatedRateComputation obs3 = InflationEndInterpolatedRateComputation.of( JP_CPI_EXF, START_INDEX, YearMonth.from(date3).minusMonths(3), weight3); assertEquals(test.createRateComputation(date1), obs1); assertEquals(test.createRateComputation(date2), obs2); assertEquals(test.createRateComputation(date3), obs3); }
public void test_createRateComputation_Interpolated() { InflationRateCalculation test = InflationRateCalculation.builder() .index(CH_CPI) .lag(Period.ofMonths(3)) .indexCalculationMethod(INTERPOLATED) .firstIndexValue(START_INDEX) .build(); double weight1 = 1.0 - 4.0 / 28.0; double weight2 = 1.0 - 6.0 / 31.0; double weight3 = 1.0 - 4.0 / 30.0; InflationEndInterpolatedRateComputation obs1 = InflationEndInterpolatedRateComputation.of( CH_CPI, START_INDEX, YearMonth.from(DATE_2015_02_05).minusMonths(3), weight1); InflationEndInterpolatedRateComputation obs2 = InflationEndInterpolatedRateComputation.of( CH_CPI, START_INDEX, YearMonth.from(DATE_2015_03_07).minusMonths(3), weight2); InflationEndInterpolatedRateComputation obs3 = InflationEndInterpolatedRateComputation.of( CH_CPI, START_INDEX, YearMonth.from(DATE_2015_04_05).minusMonths(3), weight3); assertEquals(test.createRateComputation(DATE_2015_02_05), obs1); assertEquals(test.createRateComputation(DATE_2015_03_07), obs2); assertEquals(test.createRateComputation(DATE_2015_04_05), obs3); }
public void test_createRateComputation_Monthly() { InflationRateCalculation test = InflationRateCalculation.builder() .index(GB_HICP) .lag(Period.ofMonths(3)) .indexCalculationMethod(MONTHLY) .firstIndexValue(START_INDEX) .build(); InflationEndMonthRateComputation obs1 = InflationEndMonthRateComputation.of( GB_HICP, START_INDEX, YearMonth.from(DATE_2015_02_05).minusMonths(3)); InflationEndMonthRateComputation obs2 = InflationEndMonthRateComputation.of( GB_HICP, START_INDEX, YearMonth.from(DATE_2015_03_07).minusMonths(3)); InflationEndMonthRateComputation obs3 = InflationEndMonthRateComputation.of( GB_HICP, START_INDEX, YearMonth.from(DATE_2015_04_05).minusMonths(3)); assertEquals(test.createRateComputation(DATE_2015_02_05), obs1); assertEquals(test.createRateComputation(DATE_2015_03_07), obs2); assertEquals(test.createRateComputation(DATE_2015_04_05), obs3); }
private RateComputation createRateComputation(SchedulePeriod period, int scheduleIndex) { // handle where index value at start date is known LocalDate endDate = period.getEndDate(); if (firstIndexValue != null && scheduleIndex == 0) { return createRateComputation(endDate); } YearMonth referenceStartMonth = YearMonth.from(period.getStartDate().minus(lag)); YearMonth referenceEndMonth = YearMonth.from(endDate.minus(lag)); if (indexCalculationMethod.equals(PriceIndexCalculationMethod.INTERPOLATED)) { // interpolate between data from two different months double weight = 1d - (endDate.getDayOfMonth() - 1d) / endDate.lengthOfMonth(); return InflationInterpolatedRateComputation.of(index, referenceStartMonth, referenceEndMonth, weight); } else if (indexCalculationMethod.equals(PriceIndexCalculationMethod.MONTHLY)) { // no interpolation return InflationMonthlyRateComputation.of(index, referenceStartMonth, referenceEndMonth); } else { throw new IllegalArgumentException( "PriceIndexCalculationMethod " + indexCalculationMethod.toString() + " is not supported"); } }
.notional(notional) .currency(currency) .rateComputation(rateCalculation.createRateComputation(period.getEndDate())) .realCoupon(resolvedGearings.get(i)) .build());
public void test_createRateComputation_noFirstIndexValue() { InflationRateCalculation test = InflationRateCalculation.builder() .index(CH_CPI) .lag(Period.ofMonths(3)) .indexCalculationMethod(INTERPOLATED) .build(); assertThrows(() -> test.createRateComputation(DATE_2015_04_05), IllegalStateException.class); }
LocalDate end = SCHEDULE_ADJ.adjust(unAdjDates[i + 1], REF_DATA); LocalDate detachment = EX_COUPON.adjust(end, REF_DATA); RateComputation comp = RATE_CALC.createRateComputation(end); periodic[i] = CapitalIndexedBondPaymentPeriod.builder() .currency(USD)
settlementDate)); } else { RateComputation rateComputation = product.getRateCalculation().createRateComputation(settlementDate); settlePeriod = CapitalIndexedBondPaymentPeriod.builder() .startDate(resolvedProduct.getStartDate())