private double accrueCompounded(RatePaymentPeriod paymentPeriod, double notional, RatesProvider provider) { switch (paymentPeriod.getCompoundingMethod()) { case STRAIGHT: return compoundedStraight(paymentPeriod, notional, provider); case FLAT: return compoundedFlat(paymentPeriod, notional, provider); case SPREAD_EXCLUSIVE: return compoundedSpreadExclusive(paymentPeriod, notional, provider); case NONE: default: return compoundingNone(paymentPeriod, notional, provider); } }
private PointSensitivityBuilder accrueCompoundedSensitivity( RatePaymentPeriod paymentPeriod, RatesProvider provider) { switch (paymentPeriod.getCompoundingMethod()) { case STRAIGHT: return compoundedStraightSensitivity(paymentPeriod, provider); case FLAT: return compoundedFlatSensitivity(paymentPeriod, provider); case SPREAD_EXCLUSIVE: return compoundedSpreadExclusiveSensitivity(paymentPeriod, provider); default: return unitNotionalSensitivityNoCompounding(paymentPeriod, provider); } }
@Override public double pvbp(RatePaymentPeriod paymentPeriod, RatesProvider provider) { ArgChecker.isTrue(!paymentPeriod.getFxReset().isPresent(), "FX reset is not supported"); int accPeriodCount = paymentPeriod.getAccrualPeriods().size(); ArgChecker.isTrue(accPeriodCount == 1 || paymentPeriod.getCompoundingMethod().equals(CompoundingMethod.FLAT), "Only one accrued period or Flat compounding supported"); // no compounding if (accPeriodCount == 1) { RateAccrualPeriod accrualPeriod = paymentPeriod.getAccrualPeriods().get(0); double df = provider.discountFactor(paymentPeriod.getCurrency(), paymentPeriod.getPaymentDate()); return df * accrualPeriod.getYearFraction() * paymentPeriod.getNotional(); } else { // Flat compounding switch (paymentPeriod.getCompoundingMethod()) { case FLAT: return pvbpCompoundedFlat(paymentPeriod, provider); default: throw new UnsupportedOperationException("PVBP not implemented yet for non FLAT compounding"); } } }
/** * Restricted copy constructor. * @param beanToCopy the bean to copy from, not null */ private Builder(RatePaymentPeriod beanToCopy) { this.paymentDate = beanToCopy.getPaymentDate(); this.accrualPeriods = beanToCopy.getAccrualPeriods(); this.dayCount = beanToCopy.getDayCount(); this.currency = beanToCopy.getCurrency(); this.fxReset = beanToCopy.fxReset; this.notional = beanToCopy.getNotional(); this.compoundingMethod = beanToCopy.getCompoundingMethod(); }
@Override public PointSensitivityBuilder pvbpSensitivity(RatePaymentPeriod paymentPeriod, RatesProvider provider) { ArgChecker.isTrue(!paymentPeriod.getFxReset().isPresent(), "FX reset is not supported"); int accPeriodCount = paymentPeriod.getAccrualPeriods().size(); ArgChecker.isTrue(accPeriodCount == 1 || paymentPeriod.getCompoundingMethod().equals(CompoundingMethod.FLAT), "Only one accrued period or Flat compounding supported"); // no compounding if (accPeriodCount == 1) { RateAccrualPeriod accrualPeriod = paymentPeriod.getAccrualPeriods().get(0); DiscountFactors discountFactors = provider.discountFactors(paymentPeriod.getCurrency()); return discountFactors.zeroRatePointSensitivity(paymentPeriod.getPaymentDate()) .multipliedBy(accrualPeriod.getYearFraction() * paymentPeriod.getNotional()); } else { // Flat compounding switch (paymentPeriod.getCompoundingMethod()) { case FLAT: return pvbpSensitivtyCompoundedFlat(paymentPeriod, provider); default: throw new UnsupportedOperationException("PVBP not implemented yet for non FLAT compounding"); } } }
@Override protected Object propertyGet(Bean bean, String propertyName, boolean quiet) { switch (propertyName.hashCode()) { case -1540873516: // paymentDate return ((RatePaymentPeriod) bean).getPaymentDate(); case -92208605: // accrualPeriods return ((RatePaymentPeriod) bean).getAccrualPeriods(); case 1905311443: // dayCount return ((RatePaymentPeriod) bean).getDayCount(); case 575402001: // currency return ((RatePaymentPeriod) bean).getCurrency(); case -449555555: // fxReset return ((RatePaymentPeriod) bean).fxReset; case 1585636160: // notional return ((RatePaymentPeriod) bean).getNotional(); case -1376171496: // compoundingMethod return ((RatePaymentPeriod) bean).getCompoundingMethod(); } return super.propertyGet(bean, propertyName, quiet); }
if (ratePaymentPeriod.getCompoundingMethod() == CompoundingMethod.NONE) { return Triple.of(false, 0, 0.0d); // Should be compounded
public void test_builder_twoAccrualPeriods() { RatePaymentPeriod test = RatePaymentPeriod.builder() .paymentDate(DATE_2014_10_01) .accrualPeriods(RAP1, RAP2) .dayCount(ACT_365F) .currency(GBP) .notional(1000d) .compoundingMethod(CompoundingMethod.STRAIGHT) .build(); assertEquals(test.getStartDate(), DATE_2014_03_30); assertEquals(test.getEndDate(), DATE_2014_09_30); assertEquals(test.getPaymentDate(), DATE_2014_10_01); assertEquals(test.getAccrualPeriods(), ImmutableList.of(RAP1, RAP2)); assertEquals(test.getCurrency(), GBP); assertEquals(test.getFxReset(), Optional.empty()); assertEquals(test.getNotional(), 1000d, 0d); assertEquals(test.getCompoundingMethod(), CompoundingMethod.STRAIGHT); assertEquals(test.isCompoundingApplicable(), true); }
public void test_builder_oneAccrualPeriod() { RatePaymentPeriod test = RatePaymentPeriod.builder() .paymentDate(DATE_2014_10_01) .accrualPeriods(RAP2) .dayCount(ACT_365F) .currency(GBP) .notional(1000d) .compoundingMethod(CompoundingMethod.STRAIGHT) .build(); assertEquals(test.getStartDate(), DATE_2014_06_30); assertEquals(test.getEndDate(), DATE_2014_09_30); assertEquals(test.getPaymentDate(), DATE_2014_10_01); assertEquals(test.getAccrualPeriods(), ImmutableList.of(RAP2)); assertEquals(test.getCurrency(), GBP); assertEquals(test.getFxReset(), Optional.empty()); assertEquals(test.getNotional(), 1000d, 0d); assertEquals(test.getNotionalAmount(), CurrencyAmount.of(GBP, 1000d)); assertEquals(test.getCompoundingMethod(), CompoundingMethod.STRAIGHT); assertEquals(test.isCompoundingApplicable(), false); }
assertEquals(explain.get(ExplainKey.TRADE_NOTIONAL).get().getCurrency(), currency); assertEquals(explain.get(ExplainKey.TRADE_NOTIONAL).get().getAmount(), NOTIONAL_100, TOLERANCE_PV); assertEquals(explain.get(ExplainKey.COMPOUNDING).get(), PAYMENT_PERIOD_1.getCompoundingMethod()); assertEquals(explain.get(ExplainKey.DISCOUNT_FACTOR).get(), DISCOUNT_FACTOR, TOLERANCE_PV); assertEquals(explain.get(ExplainKey.FORECAST_VALUE).get().getCurrency(), currency);
assertEquals(explain.get(ExplainKey.TRADE_NOTIONAL).get().getCurrency(), currency); assertEquals(explain.get(ExplainKey.TRADE_NOTIONAL).get().getAmount(), NOTIONAL_100, TOLERANCE_PV); assertEquals(explain.get(ExplainKey.COMPOUNDING).get(), PAYMENT_PERIOD_1_GS.getCompoundingMethod()); assertEquals(explain.get(ExplainKey.DISCOUNT_FACTOR).get(), DISCOUNT_FACTOR, TOLERANCE_PV); assertEquals(explain.get(ExplainKey.FORECAST_VALUE).get().getCurrency(), currency);
assertEquals(explain.get(ExplainKey.TRADE_NOTIONAL).get().getCurrency(), referenceCurrency); assertEquals(explain.get(ExplainKey.TRADE_NOTIONAL).get().getAmount(), NOTIONAL_100, TOLERANCE_PV); assertEquals(explain.get(ExplainKey.COMPOUNDING).get(), PAYMENT_PERIOD_1_FX.getCompoundingMethod()); assertEquals(explain.get(ExplainKey.DISCOUNT_FACTOR).get(), DISCOUNT_FACTOR, TOLERANCE_PV); assertEquals(explain.get(ExplainKey.FORECAST_VALUE).get().getCurrency(), currency);
child -> explainPresentValue(accrualPeriod, paymentPeriod.getDayCount(), currency, notional, provider, child)); builder.put(ExplainKey.COMPOUNDING, paymentPeriod.getCompoundingMethod()); builder.put(ExplainKey.DISCOUNT_FACTOR, provider.discountFactor(currency, paymentDate)); builder.put(ExplainKey.FORECAST_VALUE, CurrencyAmount.of(currency, forecastValue(paymentPeriod, provider)));