public void test_netAmount_standard() { CurrencyAmount computed = PRICER.netAmount(TRADE_STANDARD, RATES_PROVIDER); double expected = PERIOD_PRICER.forecastValue(SETTLE_PERIOD_STANDARD, RATES_PROVIDER); assertEquals(computed.getAmount(), expected, QUANTITY * NOTIONAL * TOL); }
private PointSensitivityBuilder presentValueSensitivitySettlement( ResolvedCapitalIndexedBondTrade trade, RatesProvider ratesProvider, LegalEntityDiscountingProvider discountingProvider) { if (!trade.getSettlement().isPresent()) { // position has no settlement, thus it has no sensitivity return PointSensitivityBuilder.none(); } ResolvedCapitalIndexedBondSettlement settlement = trade.getSettlement().get(); BondPaymentPeriod settlePeriod = settlement.getPayment(); ResolvedCapitalIndexedBond product = trade.getProduct(); RepoCurveDiscountFactors repoDf = DiscountingCapitalIndexedBondProductPricer.repoCurveDf(product, discountingProvider); double df = repoDf.discountFactor(settlePeriod.getPaymentDate()); double netAmount = netAmount(trade, ratesProvider).getAmount(); PointSensitivityBuilder dfSensi = repoDf.zeroRatePointSensitivity(settlePeriod.getPaymentDate()).multipliedBy(netAmount); PointSensitivityBuilder naSensi = netAmountSensitivity(settlement, ratesProvider).multipliedBy(df); return dfSensi.combinedWith(naSensi); }
public void test_netAmount_late() { CurrencyAmount computed = PRICER.netAmount(TRADE_LATE, RATES_PROVIDER); double expected = PERIOD_PRICER.forecastValue(SETTLE_PERIOD_LATE, RATES_PROVIDER); assertEquals(computed.getAmount(), expected, QUANTITY * NOTIONAL * TOL); }
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_currentCash_early() { CurrencyAmount computed = PRICER.currentCash(TRADE_EARLY, RATES_PROVIDER); CurrencyAmount expected = PRICER.netAmount(TRADE_EARLY, RATES_PROVIDER); assertEquals(computed.getAmount(), expected.getAmount(), NOTIONAL * QUANTITY * TOL); }
private CurrencyAmount presentValueSettlement( ResolvedCapitalIndexedBondTrade trade, RatesProvider ratesProvider, LegalEntityDiscountingProvider discountingProvider) { 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(); ResolvedCapitalIndexedBond product = trade.getProduct(); CurrencyAmount netAmount = netAmount(trade, ratesProvider); RepoCurveDiscountFactors repoDf = DiscountingCapitalIndexedBondProductPricer.repoCurveDf(product, discountingProvider); return netAmount.multipliedBy(repoDf.discountFactor(settlePeriod.getPaymentDate())); }
/** * Calculates the current cash of the bond trade. * * @param trade the trade * @param ratesProvider the rates provider, used to determine price index values * @return the current cash */ public CurrencyAmount currentCash( ResolvedCapitalIndexedBondTrade trade, RatesProvider ratesProvider) { LocalDate valuationDate = ratesProvider.getValuationDate(); LocalDate settlementDate = settlementDate(trade, valuationDate); CurrencyAmount cashProduct = productPricer.currentCash(trade.getProduct(), ratesProvider, settlementDate); if (!trade.getSettlement().isPresent()) { return cashProduct; } BondPaymentPeriod settlePeriod = trade.getSettlement().get().getPayment(); double cashSettle = settlePeriod.getPaymentDate().isEqual(valuationDate) ? netAmount(trade, ratesProvider).getAmount() : 0d; return cashProduct.plus(cashSettle); }
public void test_presentValueFromCleanPrice_early_exCoupon() { CurrencyAmount computed = PRICER.presentValueFromCleanPrice( TRADE_EX_COUPON_EARLY, RATES_PROVIDER, ISSUER_RATES_PROVIDER, REF_DATA, TRADE_PRICE); CurrencyAmount netAmount = PRICER.netAmount(TRADE_EX_COUPON_EARLY, RATES_PROVIDER); double df1 = ISSUER_RATES_PROVIDER.repoCurveDiscountFactors(SECURITY_ID, LEGAL_ENTITY, USD) .discountFactor(SETTLEMENT_EARLY); double df2 = ISSUER_RATES_PROVIDER.repoCurveDiscountFactors(SECURITY_ID, LEGAL_ENTITY, USD) .discountFactor(SETTLEMENT_STANDARD); double expected1 = netAmount.getAmount() * df1; double expected2 = QUANTITY * df2 * PRICER.forecastValueStandardFromCleanPrice( RPRODUCT_EX_COUPON, RATES_PROVIDER, SETTLEMENT_STANDARD, TRADE_PRICE).getAmount(); assertEquals(computed.getAmount(), expected1 + expected2, NOTIONAL * QUANTITY * TOL); }
public void test_presentValueFromCleanPriceWithZSpread_standard() { CurrencyAmount computed = PRICER.presentValueFromCleanPriceWithZSpread(TRADE_STANDARD, RATES_PROVIDER, ISSUER_RATES_PROVIDER, REF_DATA, TRADE_PRICE, Z_SPREAD, PERIODIC, PERIOD_PER_YEAR); CurrencyAmount netAmount = PRICER.netAmount(TRADE_STANDARD, RATES_PROVIDER); double df1 = ISSUER_RATES_PROVIDER.repoCurveDiscountFactors(SECURITY_ID, LEGAL_ENTITY, USD) .discountFactor(SETTLEMENT_STANDARD); double df2 = ISSUER_RATES_PROVIDER.repoCurveDiscountFactors(SECURITY_ID, LEGAL_ENTITY, USD) .discountFactor(SETTLEMENT_STANDARD); double expected1 = netAmount.getAmount() * df1; double expected2 = QUANTITY * df2 * PRICER.forecastValueStandardFromCleanPrice( RPRODUCT, RATES_PROVIDER, SETTLEMENT_STANDARD, TRADE_PRICE).getAmount(); assertEquals(computed.getAmount(), expected1 + expected2, NOTIONAL * QUANTITY * TOL); }
public void test_presentValueFromCleanPriceWithZSpread_early_exCoupon() { CurrencyAmount computed = PRICER.presentValueFromCleanPriceWithZSpread( TRADE_EX_COUPON_EARLY, RATES_PROVIDER, ISSUER_RATES_PROVIDER, REF_DATA, TRADE_PRICE, Z_SPREAD, CONTINUOUS, 0); CurrencyAmount netAmount = PRICER.netAmount(TRADE_EX_COUPON_EARLY, RATES_PROVIDER); double df1 = ISSUER_RATES_PROVIDER.repoCurveDiscountFactors(SECURITY_ID, LEGAL_ENTITY, USD) .discountFactor(SETTLEMENT_EARLY); double df2 = ISSUER_RATES_PROVIDER.repoCurveDiscountFactors(SECURITY_ID, LEGAL_ENTITY, USD) .discountFactor(SETTLEMENT_STANDARD); double expected1 = netAmount.getAmount() * df1; double expected2 = QUANTITY * df2 * PRICER.forecastValueStandardFromCleanPrice( RPRODUCT_EX_COUPON, RATES_PROVIDER, SETTLEMENT_STANDARD, TRADE_PRICE).getAmount(); assertEquals(computed.getAmount(), expected1 + expected2, NOTIONAL * QUANTITY * TOL); }
public void test_presentValueFromCleanPrice_late() { CurrencyAmount computed = PRICER.presentValueFromCleanPrice( TRADE_LATE, RATES_PROVIDER, ISSUER_RATES_PROVIDER, REF_DATA, TRADE_PRICE); CurrencyAmount netAmount = PRICER.netAmount(TRADE_LATE, RATES_PROVIDER); CapitalIndexedBondPaymentPeriod period = PRODUCT.resolve(REF_DATA).getPeriodicPayments().get(17); double pvDiff = PERIOD_PRICER.presentValue(period, RATES_PROVIDER, ISSUER_DISCOUNT_FACTORS) * QUANTITY; double df1 = ISSUER_RATES_PROVIDER.repoCurveDiscountFactors(SECURITY_ID, LEGAL_ENTITY, USD) .discountFactor(SETTLEMENT_LATE); double df2 = ISSUER_RATES_PROVIDER.repoCurveDiscountFactors(SECURITY_ID, LEGAL_ENTITY, USD) .discountFactor(SETTLEMENT_STANDARD); double expected1 = netAmount.getAmount() * df1; double expected2 = pvDiff + QUANTITY * df2 * PRICER.forecastValueStandardFromCleanPrice( RPRODUCT, RATES_PROVIDER, SETTLEMENT_STANDARD, TRADE_PRICE).getAmount(); assertEquals(computed.getAmount(), expected1 + expected2, NOTIONAL * QUANTITY * TOL); }
public void test_presentValueFromCleanPrice_early() { CurrencyAmount computed = PRICER.presentValueFromCleanPrice( TRADE_EARLY, RATES_PROVIDER, ISSUER_RATES_PROVIDER, REF_DATA, TRADE_PRICE); CurrencyAmount netAmount = PRICER.netAmount(TRADE_EARLY, RATES_PROVIDER); CapitalIndexedBondPaymentPeriod period = PRODUCT.resolve(REF_DATA).getPeriodicPayments().get(16); double pvDiff = PERIOD_PRICER.presentValue(period, RATES_PROVIDER, ISSUER_DISCOUNT_FACTORS) * QUANTITY; double df1 = ISSUER_RATES_PROVIDER.repoCurveDiscountFactors(SECURITY_ID, LEGAL_ENTITY, USD) .discountFactor(SETTLEMENT_EARLY); double df2 = ISSUER_RATES_PROVIDER.repoCurveDiscountFactors(SECURITY_ID, LEGAL_ENTITY, USD) .discountFactor(SETTLEMENT_STANDARD); double expected1 = netAmount.getAmount() * df1; double expected2 = -pvDiff + QUANTITY * df2 * PRICER.forecastValueStandardFromCleanPrice(RPRODUCT, RATES_PROVIDER, SETTLEMENT_STANDARD, TRADE_PRICE).getAmount(); assertEquals(computed.getAmount(), expected1 + expected2, NOTIONAL * QUANTITY * TOL); }
public void test_presentValueFromCleanPriceWithZSpread_early() { CurrencyAmount computed = PRICER.presentValueFromCleanPriceWithZSpread( TRADE_EARLY, RATES_PROVIDER, ISSUER_RATES_PROVIDER, REF_DATA, TRADE_PRICE, Z_SPREAD, CONTINUOUS, 0); CurrencyAmount netAmount = PRICER.netAmount(TRADE_EARLY, RATES_PROVIDER); CapitalIndexedBondPaymentPeriod period = PRODUCT.resolve(REF_DATA).getPeriodicPayments().get(16); double pvDiff = PERIOD_PRICER.presentValueWithZSpread( period, RATES_PROVIDER, ISSUER_DISCOUNT_FACTORS, Z_SPREAD, CONTINUOUS, 0) * QUANTITY; double df1 = ISSUER_RATES_PROVIDER.repoCurveDiscountFactors(SECURITY_ID, LEGAL_ENTITY, USD) .discountFactor(SETTLEMENT_EARLY); double df2 = ISSUER_RATES_PROVIDER.repoCurveDiscountFactors(SECURITY_ID, LEGAL_ENTITY, USD) .discountFactor(SETTLEMENT_STANDARD); double expected1 = netAmount.getAmount() * df1; double expected2 = -pvDiff + QUANTITY * df2 * PRICER.forecastValueStandardFromCleanPrice( RPRODUCT, RATES_PROVIDER, SETTLEMENT_STANDARD, TRADE_PRICE).getAmount(); assertEquals(computed.getAmount(), expected1 + expected2, NOTIONAL * QUANTITY * TOL); }
public void test_presentValueFromCleanPriceWithZSpread_late() { CurrencyAmount computed = PRICER.presentValueFromCleanPriceWithZSpread( TRADE_LATE, RATES_PROVIDER, ISSUER_RATES_PROVIDER, REF_DATA, TRADE_PRICE, Z_SPREAD, CONTINUOUS, 0); CurrencyAmount netAmount = PRICER.netAmount(TRADE_LATE, RATES_PROVIDER); CapitalIndexedBondPaymentPeriod period = PRODUCT.resolve(REF_DATA).getPeriodicPayments().get(17); double pvDiff = PERIOD_PRICER.presentValueWithZSpread( period, RATES_PROVIDER, ISSUER_DISCOUNT_FACTORS, Z_SPREAD, CONTINUOUS, 0) * QUANTITY; double df1 = ISSUER_RATES_PROVIDER.repoCurveDiscountFactors(SECURITY_ID, LEGAL_ENTITY, USD) .discountFactor(SETTLEMENT_LATE); double df2 = ISSUER_RATES_PROVIDER.repoCurveDiscountFactors(SECURITY_ID, LEGAL_ENTITY, USD) .discountFactor(SETTLEMENT_STANDARD); double expected1 = netAmount.getAmount() * df1; double expected2 = pvDiff + QUANTITY * df2 * PRICER.forecastValueStandardFromCleanPrice( RPRODUCT, RATES_PROVIDER, SETTLEMENT_STANDARD, TRADE_PRICE).getAmount(); assertEquals(computed.getAmount(), expected1 + expected2, NOTIONAL * QUANTITY * TOL); }