public void test_of() { SchedulePeriod sched = SchedulePeriod.of(DATE_2014_03_30, DATE_2014_09_30); KnownAmountBondPaymentPeriod test = KnownAmountBondPaymentPeriod.of(PAYMENT_2014_10_03, sched); assertEquals(test.getPayment(), PAYMENT_2014_10_03); assertEquals(test.getStartDate(), DATE_2014_03_30); assertEquals(test.getUnadjustedStartDate(), DATE_2014_03_30); assertEquals(test.getEndDate(), DATE_2014_09_30); assertEquals(test.getUnadjustedEndDate(), DATE_2014_09_30); assertEquals(test.getPaymentDate(), DATE_2014_10_03); assertEquals(test.getCurrency(), GBP); }
public void test_builder_defaultDates() { KnownAmountBondPaymentPeriod test = KnownAmountBondPaymentPeriod.builder() .payment(PAYMENT_2014_10_03) .startDate(DATE_2014_03_30) .endDate(DATE_2014_10_01) .build(); assertEquals(test.getPayment(), PAYMENT_2014_10_03); assertEquals(test.getStartDate(), DATE_2014_03_30); assertEquals(test.getUnadjustedStartDate(), DATE_2014_03_30); assertEquals(test.getEndDate(), DATE_2014_10_01); assertEquals(test.getUnadjustedEndDate(), DATE_2014_10_01); assertEquals(test.getPaymentDate(), DATE_2014_10_03); assertEquals(test.getCurrency(), GBP); }
/** * Restricted copy constructor. * @param beanToCopy the bean to copy from, not null */ private Builder(KnownAmountBondPaymentPeriod beanToCopy) { this.payment = beanToCopy.getPayment(); this.startDate = beanToCopy.getStartDate(); this.endDate = beanToCopy.getEndDate(); this.unadjustedStartDate = beanToCopy.getUnadjustedStartDate(); this.unadjustedEndDate = beanToCopy.getUnadjustedEndDate(); }
public void test_netAmountfixed() { CurrencyAmount computed = PRICER.netAmount(TRADE_ILF_STANDARD, RATES_PROVIDER); double expected = PAYMENT_PRICER.forecastValueAmount(SETTLE_PERIOD_ILF.getPayment(), RATES_PROVIDER); assertEquals(computed.getAmount(), expected, QUANTITY * NOTIONAL * TOL); }
public void test_builder_invalid() { assertThrowsIllegalArg(() -> KnownAmountBondPaymentPeriod.builder() .payment(PAYMENT_2014_10_03) .endDate(DATE_2014_10_01) .build()); assertThrowsIllegalArg(() -> KnownAmountBondPaymentPeriod.builder() .payment(PAYMENT_2014_10_03) .startDate(DATE_2014_10_01) .build()); assertThrowsIllegalArg(() -> KnownAmountBondPaymentPeriod.builder() .payment(PAYMENT_2014_10_03) .startDate(DATE_2014_10_01) .endDate(DATE_2014_10_01) .build()); }
public void test_collectIndices_simple() { KnownAmountBondPaymentPeriod test = KnownAmountBondPaymentPeriod.builder() .payment(PAYMENT_2014_10_03) .startDate(DATE_2014_03_30) .unadjustedStartDate(DATE_2014_03_30) .endDate(DATE_2014_10_01) .unadjustedEndDate(DATE_2014_09_30) .build(); ImmutableSet.Builder<Index> builder = ImmutableSet.builder(); test.collectIndices(builder); assertEquals(builder.build(), ImmutableSet.of()); }
public void test_adjustPaymentDate() { KnownAmountBondPaymentPeriod test = KnownAmountBondPaymentPeriod.builder() .payment(PAYMENT_2014_10_01) .startDate(DATE_2014_03_30) .unadjustedStartDate(DATE_2014_03_30) .endDate(DATE_2014_10_01) .unadjustedEndDate(DATE_2014_09_30) .build(); KnownAmountBondPaymentPeriod expected = KnownAmountBondPaymentPeriod.builder() .payment(PAYMENT_2014_10_03) .startDate(DATE_2014_03_30) .unadjustedStartDate(DATE_2014_03_30) .endDate(DATE_2014_10_01) .unadjustedEndDate(DATE_2014_09_30) .build(); assertEquals(test.adjustPaymentDate(TemporalAdjusters.ofDateAdjuster(d -> d.plusDays(0))), test); assertEquals(test.adjustPaymentDate(TemporalAdjusters.ofDateAdjuster(d -> d.plusDays(2))), expected); }
settlePeriod = KnownAmountBondPaymentPeriod.of( Payment.of(product.getCurrency(), -product.getNotional() * quantity * (price + accruedInterest), settlementDate),
@Override protected Object propertyGet(Bean bean, String propertyName, boolean quiet) { switch (propertyName.hashCode()) { case -786681338: // payment return ((KnownAmountBondPaymentPeriod) bean).getPayment(); case -2129778896: // startDate return ((KnownAmountBondPaymentPeriod) bean).getStartDate(); case -1607727319: // endDate return ((KnownAmountBondPaymentPeriod) bean).getEndDate(); case 1457691881: // unadjustedStartDate return ((KnownAmountBondPaymentPeriod) bean).getUnadjustedStartDate(); case 31758114: // unadjustedEndDate return ((KnownAmountBondPaymentPeriod) bean).getUnadjustedEndDate(); } return super.propertyGet(bean, propertyName, quiet); }
/** * Calculates the net amount of the settlement of the bond trade. * <p> * Since the sign of the settlement notional is opposite to that of the product, negative amount will be returned * for positive quantity of trade. * * @param trade the trade * @param ratesProvider the rates provider, used to determine price index values * @return the net amount */ public CurrencyAmount netAmount( ResolvedCapitalIndexedBondTrade trade, RatesProvider ratesProvider) { if (!trade.getSettlement().isPresent()) { // position has no settlement, thus it has no value return CurrencyAmount.zero(trade.getProduct().getCurrency()); } BondPaymentPeriod settlePeriod = trade.getSettlement().get().getPayment(); if (settlePeriod instanceof KnownAmountBondPaymentPeriod) { Payment payment = ((KnownAmountBondPaymentPeriod) settlePeriod).getPayment(); return payment.getValue(); } else if (settlePeriod instanceof CapitalIndexedBondPaymentPeriod) { CapitalIndexedBondPaymentPeriod casted = (CapitalIndexedBondPaymentPeriod) settlePeriod; double netAmount = productPricer.getPeriodPricer().forecastValue(casted, ratesProvider); return CurrencyAmount.of(casted.getCurrency(), netAmount); } throw new UnsupportedOperationException("unsupported settlement type"); }
/** * Obtains an instance based on a payment and schedule period. * * @param payment the payment * @param period the schedule period * @return the period */ public static KnownAmountBondPaymentPeriod of(Payment payment, SchedulePeriod period) { return KnownAmountBondPaymentPeriod.builder() .payment(payment) .startDate(period.getStartDate()) .endDate(period.getEndDate()) .unadjustedStartDate(period.getUnadjustedStartDate()) .unadjustedEndDate(period.getUnadjustedEndDate()) .build(); }
public void test_presentValue_fixed() { CurrencyAmount computed = PRICER.presentValue(TRADE_ILF_STANDARD, RATES_PROVIDER, ISSUER_RATES_PROVIDER); double expected1 = PRODUCT_PRICER.presentValue( RPRODUCT_ILF, RATES_PROVIDER, ISSUER_RATES_PROVIDER, SETTLEMENT_STANDARD).getAmount() * QUANTITY; double df = ISSUER_RATES_PROVIDER.repoCurveDiscountFactors(SECURITY_ID, LEGAL_ENTITY, USD) .discountFactor(SETTLEMENT_STANDARD); double expected2 = df * PAYMENT_PRICER.forecastValueAmount(SETTLE_PERIOD_ILF.getPayment(), RATES_PROVIDER); assertEquals(computed.getAmount(), expected1 + expected2, NOTIONAL * QUANTITY * TOL); }
public void test_serialization() { KnownAmountBondPaymentPeriod test = KnownAmountBondPaymentPeriod.builder() .payment(PAYMENT_2014_10_03) .startDate(DATE_2014_03_30) .unadjustedStartDate(DATE_2014_03_30) .endDate(DATE_2014_10_01) .unadjustedEndDate(DATE_2014_09_30) .build(); assertSerialization(test); }
public void coverage() { KnownAmountBondPaymentPeriod test = KnownAmountBondPaymentPeriod.builder() .payment(PAYMENT_2014_10_03) .startDate(DATE_2014_03_30) .unadjustedStartDate(DATE_2014_03_30) .endDate(DATE_2014_10_01) .unadjustedEndDate(DATE_2014_09_30) .build(); coverImmutableBean(test); KnownAmountBondPaymentPeriod test2 = KnownAmountBondPaymentPeriod.builder() .payment(PAYMENT_2014_10_03.negated()) .startDate(DATE_2014_06_30) .endDate(DATE_2014_09_30) .build(); coverBeanEquals(test, test2); }