static ResolvedFixedCouponBondSettlement sut2() { return ResolvedFixedCouponBondSettlement.of(SETTLE_DATE2, PRICE2); }
public void test_of() { ResolvedFixedCouponBondSettlement test = sut(); assertEquals(test.getSettlementDate(), SETTLE_DATE); assertEquals(test.getPrice(), PRICE); }
/** * Obtains an instance from the settlement date and price. * * @param settlementDate the settlement date * @param price the price at which the trade was agreed * @return the settlement information */ public static ResolvedFixedCouponBondSettlement of(LocalDate settlementDate, double price) { return new ResolvedFixedCouponBondSettlement(settlementDate, price); }
private LocalDate settlementDate(ResolvedFixedCouponBondTrade trade, LocalDate valuationDate) { return trade.getSettlement() .map(settle -> settle.getSettlementDate()) .orElse(valuationDate); }
/** * Calculates the current cash of the fixed coupon bond trade. * * @param trade the trade * @param valuationDate the valuation date * @return the current cash amount */ public CurrencyAmount currentCash(ResolvedFixedCouponBondTrade trade, LocalDate valuationDate) { Payment upfrontPayment = upfrontPayment(trade); Currency currency = upfrontPayment.getCurrency(); // assumes single currency is involved in trade CurrencyAmount currentCash = CurrencyAmount.zero(currency); if (upfrontPayment.getDate().equals(valuationDate)) { currentCash = currentCash.plus(upfrontPayment.getValue()); } if (trade.getSettlement().isPresent()) { LocalDate settlementDate = trade.getSettlement().get().getSettlementDate(); ResolvedFixedCouponBond product = trade.getProduct(); if (!settlementDate.isAfter(valuationDate)) { double cashCoupon = product.hasExCouponPeriod() ? 0d : currentCashCouponPayment(product, valuationDate); Payment payment = product.getNominalPayment(); double cashNominal = payment.getDate().isEqual(valuationDate) ? payment.getAmount() : 0d; currentCash = currentCash.plus(CurrencyAmount.of(currency, (cashCoupon + cashNominal) * trade.getQuantity())); } } return currentCash; }
static ResolvedFixedCouponBondSettlement sut() { return ResolvedFixedCouponBondSettlement.of(SETTLE_DATE, PRICE); }
/** * Calculates the payment that was made for the trade. * <p> * This is the payment that was made on the settlement date, based on the quantity and clean price. * * @param trade the trade * @return the payment that was made */ public Payment upfrontPayment(ResolvedFixedCouponBondTrade trade) { ResolvedFixedCouponBond product = trade.getProduct(); Currency currency = product.getCurrency(); if (!trade.getSettlement().isPresent()) { return Payment.of(CurrencyAmount.zero(currency), product.getStartDate()); // date doesn't matter as it is zero } // payment is based on the dirty price ResolvedFixedCouponBondSettlement settlement = trade.getSettlement().get(); LocalDate settlementDate = settlement.getSettlementDate(); double cleanPrice = settlement.getPrice(); double dirtyPrice = productPricer.dirtyPriceFromCleanPrice(product, settlementDate, cleanPrice); // calculate payment double quantity = trade.getQuantity(); double notional = product.getNotional(); return Payment.of(CurrencyAmount.of(currency, -quantity * notional * dirtyPrice), settlementDate); }
@Override public ResolvedFixedCouponBondTrade resolve(ReferenceData refData) { ResolvedFixedCouponBond resolved = getProduct().resolve(refData); LocalDate settlementDate = calculateSettlementDate(refData); return ResolvedFixedCouponBondTrade.builder() .info(info) .product(resolved) .quantity(quantity) .settlement(ResolvedFixedCouponBondSettlement.of(settlementDate, price)) .build(); }
public void test_resolve() { ResolvedFixedCouponBondTrade expected = ResolvedFixedCouponBondTrade.builder() .info(TRADE_INFO) .product(PRODUCT.resolve(REF_DATA)) .quantity(QUANTITY) .settlement(ResolvedFixedCouponBondSettlement.of(SETTLEMENT_DATE, PRICE)) .build(); assertEquals(sut().resolve(REF_DATA), expected); }
public void test_presentValueSensitivity_dateLogic_pastSettle_noExcoupon() { ResolvedFixedCouponBondTrade tradeAfter = ResolvedFixedCouponBondTrade.builder() .product(PRODUCT_NO_EXCOUPON) .quantity(QUANTITY) .settlement(ResolvedFixedCouponBondSettlement.of(SETTLEMENT, CLEAN_PRICE)) .build(); PointSensitivities computedTradeAfter = TRADE_PRICER_NO_UPFRONT.presentValueSensitivity(tradeAfter, PROVIDER); // settle before coupon date ResolvedFixedCouponBondTrade tradeBefore = ResolvedFixedCouponBondTrade.builder() .product(PRODUCT_NO_EXCOUPON) .quantity(QUANTITY) .settlement(ResolvedFixedCouponBondSettlement.of(SETTLE_BEFORE, CLEAN_PRICE)) .build(); PointSensitivities computedTradeBefore = TRADE_PRICER_NO_UPFRONT.presentValueSensitivity(tradeBefore, PROVIDER); assertTrue(computedTradeBefore.equalWithTolerance(computedTradeAfter, NOTIONAL * QUANTITY * TOL)); // settle on coupon date ResolvedFixedCouponBondTrade tradeOnCoupon = ResolvedFixedCouponBondTrade.builder() .product(PRODUCT_NO_EXCOUPON) .quantity(QUANTITY) .settlement(ResolvedFixedCouponBondSettlement.of(SETTLE_ON_COUPON, CLEAN_PRICE)) .build(); PointSensitivities computedTradeOnCoupon = TRADE_PRICER_NO_UPFRONT.presentValueSensitivity(tradeOnCoupon, PROVIDER); assertTrue(computedTradeOnCoupon.equalWithTolerance(computedTradeAfter, NOTIONAL * QUANTITY * TOL)); }
public void test_presentValue_dateLogic_pastSettle_noExcoupon() { ResolvedFixedCouponBondTrade tradeAfter = ResolvedFixedCouponBondTrade.builder() .product(PRODUCT_NO_EXCOUPON) .quantity(QUANTITY) .settlement(ResolvedFixedCouponBondSettlement.of(SETTLEMENT, CLEAN_PRICE)) .build(); CurrencyAmount computedTradeAfter = TRADE_PRICER_NO_UPFRONT.presentValue(tradeAfter, PROVIDER); // settle before coupon date ResolvedFixedCouponBondTrade tradeBefore = ResolvedFixedCouponBondTrade.builder() .product(PRODUCT_NO_EXCOUPON) .quantity(QUANTITY) .settlement(ResolvedFixedCouponBondSettlement.of(SETTLE_BEFORE, CLEAN_PRICE)) .build(); CurrencyAmount computedTradeBefore = TRADE_PRICER_NO_UPFRONT.presentValue(tradeBefore, PROVIDER); assertEquals(computedTradeBefore.getAmount(), computedTradeAfter.getAmount(), NOTIONAL * QUANTITY * TOL); // settle on coupon date ResolvedFixedCouponBondTrade tradeOnCoupon = ResolvedFixedCouponBondTrade.builder() .product(PRODUCT_NO_EXCOUPON) .quantity(QUANTITY) .settlement(ResolvedFixedCouponBondSettlement.of(SETTLE_ON_COUPON, CLEAN_PRICE)) .build(); CurrencyAmount computedTradeOnCoupon = TRADE_PRICER_NO_UPFRONT.presentValue(tradeOnCoupon, PROVIDER); assertEquals(computedTradeOnCoupon.getAmount(), computedTradeAfter.getAmount(), NOTIONAL * QUANTITY * TOL); }
.product(PRODUCT) .quantity(QUANTITY) .settlement(ResolvedFixedCouponBondSettlement.of(SETTLEMENT, CLEAN_PRICE)) .build(); PointSensitivities computedTradeAfter = TRADE_PRICER_NO_UPFRONT.presentValueSensitivity(tradeAfter, PROVIDER); .product(PRODUCT) .quantity(QUANTITY) .settlement(ResolvedFixedCouponBondSettlement.of(SETTLE_BEFORE, CLEAN_PRICE)) .build(); PointSensitivities computedTradeBefore = TRADE_PRICER_NO_UPFRONT.presentValueSensitivity(tradeBefore, PROVIDER); .product(PRODUCT) .quantity(QUANTITY) .settlement(ResolvedFixedCouponBondSettlement.of(SETTLE_ON_DETACHMENT, CLEAN_PRICE)) .build(); PointSensitivities computedTradeOnDetachment = .product(PRODUCT) .quantity(QUANTITY) .settlement(ResolvedFixedCouponBondSettlement.of(SETTLE_BTWN_DETACHMENT_COUPON, CLEAN_PRICE)) .build(); PointSensitivities computedTradeBtwnDetachmentCoupon =
.product(PRODUCT) .quantity(QUANTITY) .settlement(ResolvedFixedCouponBondSettlement.of(SETTLEMENT, CLEAN_PRICE)) .build(); CurrencyAmount computedTradeAfter = TRADE_PRICER_NO_UPFRONT.presentValue(tradeAfter, PROVIDER); .product(PRODUCT) .quantity(QUANTITY) .settlement(ResolvedFixedCouponBondSettlement.of(SETTLE_BEFORE, CLEAN_PRICE)) .build(); CurrencyAmount computedTradeBefore = TRADE_PRICER_NO_UPFRONT.presentValue(tradeBefore, PROVIDER); .product(PRODUCT) .quantity(QUANTITY) .settlement(ResolvedFixedCouponBondSettlement.of(SETTLE_ON_DETACHMENT, CLEAN_PRICE)) .build(); CurrencyAmount computedTradeOnDetachment = TRADE_PRICER_NO_UPFRONT.presentValue(tradeOnDetachment, PROVIDER); .product(PRODUCT) .quantity(QUANTITY) .settlement(ResolvedFixedCouponBondSettlement.of(SETTLE_BTWN_DETACHMENT_COUPON, CLEAN_PRICE)) .build(); CurrencyAmount computedTradeBtwnDetachmentCoupon =
public void test_presentValue_dateLogic_noExcoupon() { ResolvedFixedCouponBondTrade tradeAfter = ResolvedFixedCouponBondTrade.builder() .product(PRODUCT_NO_EXCOUPON) .quantity(QUANTITY) .settlement(ResolvedFixedCouponBondSettlement.of(SETTLEMENT, CLEAN_PRICE)) .build(); CurrencyAmount computedTradeAfter = TRADE_PRICER_NO_UPFRONT.presentValue(tradeAfter, PROVIDER_BEFORE); // settle before coupon date ResolvedFixedCouponBondTrade tradeBefore = ResolvedFixedCouponBondTrade.builder() .product(PRODUCT_NO_EXCOUPON) .quantity(QUANTITY) .settlement(ResolvedFixedCouponBondSettlement.of(SETTLE_BEFORE, CLEAN_PRICE)) .build(); CurrencyAmount computedTradeBefore = TRADE_PRICER_NO_UPFRONT.presentValue(tradeBefore, PROVIDER_BEFORE); FixedCouponBondPaymentPeriod periodExtra = findPeriod(PRODUCT_NO_EXCOUPON, SETTLE_BEFORE, SETTLEMENT); double pvExtra = COUPON_PRICER.presentValue(periodExtra, PROVIDER_BEFORE.issuerCurveDiscountFactors(ISSUER_ID, EUR)); assertEquals(computedTradeBefore.getAmount(), computedTradeAfter.plus(pvExtra * QUANTITY).getAmount(), NOTIONAL * QUANTITY * TOL); // settle on coupon date ResolvedFixedCouponBondTrade tradeOnCoupon = ResolvedFixedCouponBondTrade.builder() .product(PRODUCT_NO_EXCOUPON) .quantity(QUANTITY) .settlement(ResolvedFixedCouponBondSettlement.of(SETTLE_ON_COUPON, CLEAN_PRICE)) .build(); CurrencyAmount computedTradeOnCoupon = TRADE_PRICER_NO_UPFRONT.presentValue(tradeOnCoupon, PROVIDER_BEFORE); assertEquals(computedTradeOnCoupon.getAmount(), computedTradeAfter.getAmount(), NOTIONAL * QUANTITY * TOL); }
.product(PRODUCT) .quantity(QUANTITY) .settlement(ResolvedFixedCouponBondSettlement.of(SETTLEMENT, CLEAN_PRICE)) .build(); CurrencyAmount computedTradeAfter = TRADE_PRICER_NO_UPFRONT.presentValue(tradeAfter, PROVIDER_BEFORE); .product(PRODUCT) .quantity(QUANTITY) .settlement(ResolvedFixedCouponBondSettlement.of(SETTLE_BEFORE, CLEAN_PRICE)) .build(); CurrencyAmount computedTradeBefore = TRADE_PRICER_NO_UPFRONT.presentValue(tradeBefore, PROVIDER_BEFORE); .product(PRODUCT) .quantity(QUANTITY) .settlement(ResolvedFixedCouponBondSettlement.of(SETTLE_ON_DETACHMENT, CLEAN_PRICE)) .build(); CurrencyAmount computedTradeOnDetachment = TRADE_PRICER_NO_UPFRONT.presentValue(tradeOnDetachment, PROVIDER_BEFORE); .product(PRODUCT) .quantity(QUANTITY) .settlement(ResolvedFixedCouponBondSettlement.of(SETTLE_BTWN_DETACHMENT_COUPON, CLEAN_PRICE)) .build(); CurrencyAmount computedTradeBtwnDetachmentCoupon =
public void test_presentValueSensitivity_dateLogic_noExcoupon() { ResolvedFixedCouponBondTrade tradeAfter = ResolvedFixedCouponBondTrade.builder() .product(PRODUCT_NO_EXCOUPON) .quantity(QUANTITY) .settlement(ResolvedFixedCouponBondSettlement.of(SETTLEMENT, CLEAN_PRICE)) .build(); PointSensitivities computedTradeAfter = TRADE_PRICER_NO_UPFRONT.presentValueSensitivity(tradeAfter, PROVIDER_BEFORE); // settle before coupon date ResolvedFixedCouponBondTrade tradeBefore = ResolvedFixedCouponBondTrade.builder() .product(PRODUCT_NO_EXCOUPON) .quantity(QUANTITY) .settlement(ResolvedFixedCouponBondSettlement.of(SETTLE_BEFORE, CLEAN_PRICE)) .build(); PointSensitivities computedTradeBefore = TRADE_PRICER_NO_UPFRONT.presentValueSensitivity(tradeBefore, PROVIDER_BEFORE); FixedCouponBondPaymentPeriod periodExtra = findPeriod(PRODUCT_NO_EXCOUPON, SETTLE_BEFORE, SETTLEMENT); PointSensitivities sensiExtra = COUPON_PRICER .presentValueSensitivity(periodExtra, PROVIDER_BEFORE.issuerCurveDiscountFactors(ISSUER_ID, EUR)).build(); assertTrue(computedTradeBefore.normalized().equalWithTolerance( computedTradeAfter.combinedWith(sensiExtra.multipliedBy(QUANTITY)).normalized(), NOTIONAL * QUANTITY * TOL)); // settle on coupon date ResolvedFixedCouponBondTrade tradeOnCoupon = ResolvedFixedCouponBondTrade.builder() .product(PRODUCT_NO_EXCOUPON) .quantity(QUANTITY) .settlement(ResolvedFixedCouponBondSettlement.of(SETTLE_ON_COUPON, CLEAN_PRICE)) .build(); PointSensitivities computedTradeOnCoupon = TRADE_PRICER_NO_UPFRONT.presentValueSensitivity(tradeOnCoupon, PROVIDER_BEFORE); assertTrue(computedTradeOnCoupon.equalWithTolerance(computedTradeAfter, NOTIONAL * QUANTITY * TOL)); }
.product(PRODUCT) .quantity(QUANTITY) .settlement(ResolvedFixedCouponBondSettlement.of(SETTLEMENT, CLEAN_PRICE)) .build(); PointSensitivities computedTradeAfter = TRADE_PRICER_NO_UPFRONT.presentValueSensitivity(tradeAfter, PROVIDER_BEFORE); .product(PRODUCT) .quantity(QUANTITY) .settlement(ResolvedFixedCouponBondSettlement.of(SETTLE_BEFORE, CLEAN_PRICE)) .build(); PointSensitivities computedTradeBefore = .product(PRODUCT) .quantity(QUANTITY) .settlement(ResolvedFixedCouponBondSettlement.of(SETTLE_ON_DETACHMENT, CLEAN_PRICE)) .build(); PointSensitivities computedTradeOnDetachment = .product(PRODUCT) .quantity(QUANTITY) .settlement(ResolvedFixedCouponBondSettlement.of(SETTLE_BTWN_DETACHMENT_COUPON, CLEAN_PRICE)) .build(); PointSensitivities computedTradeBtwnDetachmentCoupon =
.product(PRODUCT_NO_EXCOUPON) .quantity(QUANTITY) .settlement(ResolvedFixedCouponBondSettlement.of(valuation1, CLEAN_PRICE)) .build(); LegalEntityDiscountingProvider provider1 = createRatesProvider(valuation1); .product(PRODUCT_NO_EXCOUPON) .quantity(QUANTITY) .settlement(ResolvedFixedCouponBondSettlement.of(settlement2, CLEAN_PRICE)) .build(); CurrencyAmount computed2 = TRADE_PRICER_NO_UPFRONT.presentValueFromCleanPrice(trade2, provider1, REF_DATA, cleanPrice); .product(PRODUCT_NO_EXCOUPON) .quantity(QUANTITY) .settlement(ResolvedFixedCouponBondSettlement.of(settlement3, CLEAN_PRICE)) .build(); CurrencyAmount computed3 = TRADE_PRICER_NO_UPFRONT.presentValueFromCleanPrice(trade3, provider1, REF_DATA, cleanPrice); .product(PRODUCT_NO_EXCOUPON) .quantity(QUANTITY) .settlement(ResolvedFixedCouponBondSettlement.of(settlement4, CLEAN_PRICE)) .build(); LocalDate standardSettlement4 = PRODUCT_NO_EXCOUPON.getSettlementDateOffset().adjust(TRADE_BEFORE, REF_DATA); .product(PRODUCT_NO_EXCOUPON) .quantity(QUANTITY) .settlement(ResolvedFixedCouponBondSettlement.of(settlement5, CLEAN_PRICE)) .build(); CurrencyAmount computed5 = TRADE_PRICER_NO_UPFRONT.presentValueFromCleanPrice(trade5, PROVIDER_BEFORE, REF_DATA, cleanPrice);
.product(PRODUCT) .quantity(QUANTITY) .settlement(ResolvedFixedCouponBondSettlement.of(valuation1, CLEAN_PRICE)) .build(); LegalEntityDiscountingProvider provider1 = createRatesProvider(valuation1); .product(PRODUCT) .quantity(QUANTITY) .settlement(ResolvedFixedCouponBondSettlement.of(SETTLE_ON_DETACHMENT.plusDays(2), CLEAN_PRICE)) .build(); CurrencyAmount computed2 = TRADE_PRICER_NO_UPFRONT.presentValueFromCleanPrice(trade2, provider1, REF_DATA, cleanPrice); .product(PRODUCT) .quantity(QUANTITY) .settlement(ResolvedFixedCouponBondSettlement.of(SETTLE_ON_DETACHMENT.plusDays(7), CLEAN_PRICE)) .build(); CurrencyAmount computed3 = TRADE_PRICER_NO_UPFRONT.presentValueFromCleanPrice(trade3, provider1, REF_DATA, cleanPrice); .product(PRODUCT) .quantity(QUANTITY) .settlement(ResolvedFixedCouponBondSettlement.of(settlement4, CLEAN_PRICE)) .build(); LocalDate standardSettlement4 = PRODUCT.getSettlementDateOffset().adjust(TRADE_BEFORE, REF_DATA); .product(PRODUCT) .quantity(QUANTITY) .settlement(ResolvedFixedCouponBondSettlement.of(settlement5, CLEAN_PRICE)) .build(); CurrencyAmount computed5 = TRADE_PRICER_NO_UPFRONT.presentValueFromCleanPrice(trade5, PROVIDER_BEFORE, REF_DATA, cleanPrice);