public void test_getter() { assertEquals(PRICER.getPeriodPricer(), PERIOD_PRICER); }
private PointSensitivityBuilder netAmountSensitivity( ResolvedCapitalIndexedBondSettlement settlement, RatesProvider ratesProvider) { BondPaymentPeriod settlePeriod = settlement.getPayment(); if (settlePeriod instanceof KnownAmountBondPaymentPeriod) { return PointSensitivityBuilder.none(); } else if (settlePeriod instanceof CapitalIndexedBondPaymentPeriod) { CapitalIndexedBondPaymentPeriod casted = (CapitalIndexedBondPaymentPeriod) settlePeriod; return productPricer.getPeriodPricer().forecastValueSensitivity(casted, ratesProvider); } throw new UnsupportedOperationException("unsupported settlement type"); }
/** * 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"); }