/** * 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 build() { return new ResolvedFixedCouponBondTrade( info, product, quantity, settlement); }
/** * Restricted copy constructor. * @param beanToCopy the bean to copy from, not null */ private Builder(ResolvedFixedCouponBondTrade beanToCopy) { this.info = beanToCopy.getInfo(); this.product = beanToCopy.getProduct(); this.quantity = beanToCopy.getQuantity(); this.settlement = beanToCopy.settlement; }
@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(); }
private CurrencyAmount presentValuePayment(ResolvedFixedCouponBondTrade trade, LegalEntityDiscountingProvider provider) { RepoCurveDiscountFactors repoDf = DiscountingFixedCouponBondProductPricer.repoCurveDf(trade.getProduct(), provider); Payment upfrontPayment = upfrontPayment(trade); return paymentPricer.presentValue(upfrontPayment, repoDf.getDiscountFactors()); }
private CurrencyAmount presentValueFromProductPresentValue( ResolvedFixedCouponBondTrade trade, LegalEntityDiscountingProvider provider, CurrencyAmount productPresentValue) { CurrencyAmount pvProduct = productPresentValue.multipliedBy(trade.getQuantity()); CurrencyAmount pvPayment = presentValuePayment(trade, provider); return pvProduct.plus(pvPayment); }
private LocalDate settlementDate(ResolvedFixedCouponBondTrade trade, LocalDate valuationDate) { return trade.getSettlement() .map(settle -> settle.getSettlementDate()) .orElse(valuationDate); }
public void test_resolve() { ResolvedFixedCouponBondTrade expected = ResolvedFixedCouponBondTrade.builder() .info(POSITION_INFO) .product(PRODUCT.resolve(REF_DATA)) .quantity(QUANTITY) .build(); assertEquals(sut().resolve(REF_DATA), expected); }
/** * Calculates the present value of the fixed coupon bond trade. * <p> * The present value of the trade is the value on the valuation date. * The result is expressed using the payment currency of the bond. * <p> * Coupon payments of the underlying product are considered based on the settlement date of the trade. * * @param trade the trade * @param provider the discounting provider * @return the present value of the fixed coupon bond trade */ public CurrencyAmount presentValue(ResolvedFixedCouponBondTrade trade, LegalEntityDiscountingProvider provider) { LocalDate settlementDate = settlementDate(trade, provider.getValuationDate()); CurrencyAmount pvProduct = productPricer.presentValue(trade.getProduct(), provider, settlementDate); return presentValueFromProductPresentValue(trade, provider, pvProduct); }
private PointSensitivityBuilder presentValueSensitivityFromProductPresentValueSensitivity( ResolvedFixedCouponBondTrade trade, LegalEntityDiscountingProvider provider, PointSensitivityBuilder productPresnetValueSensitivity) { PointSensitivityBuilder sensiProduct = productPresnetValueSensitivity.multipliedBy(trade.getQuantity()); PointSensitivityBuilder sensiPayment = presentValueSensitivityPayment(trade, provider); return sensiProduct.combinedWith(sensiPayment); }
public void test_builder() { ResolvedFixedCouponBondTrade test = sut(); assertEquals(test.getSettlement().isPresent(), true); }
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); }
/** * 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; }
private PointSensitivityBuilder presentValueSensitivityPayment( ResolvedFixedCouponBondTrade trade, LegalEntityDiscountingProvider provider) { RepoCurveDiscountFactors repoDf = DiscountingFixedCouponBondProductPricer.repoCurveDf(trade.getProduct(), provider); Payment upfrontPayment = upfrontPayment(trade); PointSensitivityBuilder pt = paymentPricer.presentValueSensitivity( upfrontPayment, repoDf.getDiscountFactors()); if (pt instanceof ZeroRateSensitivity) { return RepoCurveZeroRateSensitivity.of((ZeroRateSensitivity) pt, repoDf.getRepoGroup()); } return pt; // NoPointSensitivity }
@Override protected Object propertyGet(Bean bean, String propertyName, boolean quiet) { switch (propertyName.hashCode()) { case 3237038: // info return ((ResolvedFixedCouponBondTrade) bean).getInfo(); case -309474065: // product return ((ResolvedFixedCouponBondTrade) bean).getProduct(); case -1285004149: // quantity return ((ResolvedFixedCouponBondTrade) bean).getQuantity(); case 73828649: // settlement return ((ResolvedFixedCouponBondTrade) bean).settlement; } return super.propertyGet(bean, propertyName, quiet); }
@Override public ResolvedFixedCouponBondTrade resolve(ReferenceData refData) { ResolvedFixedCouponBond resolved = product.resolve(refData); return new ResolvedFixedCouponBondTrade(info, resolved, getQuantity(), null); }
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_upfrontPayment_position() { Payment payment = TRADE_PRICER.upfrontPayment(POSITION); assertEquals(payment.getCurrency(), EUR); assertEquals(payment.getAmount(), 0, TOL); assertEquals(payment.getDate(), POSITION.getProduct().getStartDate()); }
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); }
/** * Calculates the present value of the fixed coupon bond trade with z-spread. * <p> * The present value of the trade is the value on the valuation date. * The result is expressed using the payment currency of the bond. * <p> * The z-spread is a parallel shift applied to continuously compounded rates or periodic * compounded rates of the discounting curve. * <p> * Coupon payments of the underlying product are considered based on the settlement date of the trade. * * @param trade the trade * @param provider the discounting provider * @param zSpread the z-spread * @param compoundedRateType the compounded rate type * @param periodsPerYear the number of periods per year * @return the present value of the fixed coupon bond trade */ public CurrencyAmount presentValueWithZSpread( ResolvedFixedCouponBondTrade trade, LegalEntityDiscountingProvider provider, double zSpread, CompoundedRateType compoundedRateType, int periodsPerYear) { LocalDate settlementDate = settlementDate(trade, provider.getValuationDate()); CurrencyAmount pvProduct = productPricer.presentValueWithZSpread( trade.getProduct(), provider, zSpread, compoundedRateType, periodsPerYear, settlementDate); return presentValueFromProductPresentValue(trade, provider, pvProduct); }