public void test_presentValue_aftermaturity() { CurrencyAmount pvComputed = PRICER.presentValue(BILL_PAST, PROVIDER); assertEquals(pvComputed.getCurrency(), EUR); assertEquals(pvComputed.getAmount(), 0.0d, TOLERANCE_PV); } public void test_presentValue_zspread() {
public void presentValueSensitivity_aftermaturity() { PointSensitivities sensiComputed = PRICER.presentValueSensitivity(BILL_PAST, PROVIDER); PointSensitivities sensiExpected = PointSensitivities.empty(); assertTrue(sensiComputed.equalWithTolerance(sensiExpected, TOLERANCE_PV)); }
public void presentValueSensitivity_zspread_aftermaturity() { PointSensitivities sensiComputed = PRICER.presentValueSensitivityWithZSpread(BILL_PAST, PROVIDER, Z_SPREAD, CompoundedRateType.CONTINUOUS, 0); PointSensitivities sensiExpected = PointSensitivities.empty(); assertTrue(sensiComputed.equalWithTolerance(sensiExpected, TOLERANCE_PV)); }
public void yieldFromCurves_zspread() { LocalDate settlementDate = VAL_DATE.plusDays(1); double yieldComputed = PRICER.yieldFromCurvesWithZSpread(BILL, PROVIDER, settlementDate, Z_SPREAD, CompoundedRateType.CONTINUOUS, 0); double priceExpected = PRICER.priceFromCurvesWithZSpread(BILL, PROVIDER, settlementDate, Z_SPREAD, CompoundedRateType.CONTINUOUS, 0); double yieldExpected = BILL.yieldFromPrice(priceExpected, settlementDate); assertEquals(yieldComputed, yieldExpected, TOLERANCE_PRICE); }
/** * Calculates the price for settlement at a given settlement date using curves. * * @param bill the bill * @param provider the discounting provider * @param settlementDate the settlement date * @return the price */ public double priceFromCurves(ResolvedBill bill, LegalEntityDiscountingProvider provider, LocalDate settlementDate) { ArgChecker.inOrderNotEqual(settlementDate, bill.getNotional().getDate(), "settlementDate", "endDate"); ArgChecker.inOrderOrEqual(provider.getValuationDate(), settlementDate, "valuationDate", "settlementDate"); IssuerCurveDiscountFactors issuerDf = issuerCurveDf(bill, provider); double dfMaturity = issuerDf.discountFactor(bill.getNotional().getDate()); RepoCurveDiscountFactors repoDf = repoCurveDf(bill, provider); double dfRepoSettle = repoDf.discountFactor(settlementDate); return dfMaturity / dfRepoSettle; }
public void presentValueSensitivity() { PointSensitivities sensiComputed = PRICER.presentValueSensitivity(BILL, PROVIDER); PointSensitivities sensiExpected = IssuerCurveDiscountFactors.of(DSC_FACTORS_ISSUER, GROUP_ISSUER) .zeroRatePointSensitivity(MATURITY_DATE) .multipliedBy(NOTIONAL.getAmount()).build(); assertTrue(sensiComputed.equalWithTolerance(sensiExpected, TOLERANCE_PV)); CurrencyParameterSensitivities paramSensiComputed = PROVIDER.parameterSensitivity(sensiComputed); CurrencyParameterSensitivities paramSensiExpected = FD_CALC.sensitivity(PROVIDER, p -> PRICER.presentValue(BILL, p)); assertTrue(paramSensiComputed.equalWithTolerance(paramSensiExpected, EPS * NOTIONAL_AMOUNT)); }
public void presentValueSensitivity_zspread() { PointSensitivities sensiComputed = PRICER.presentValueSensitivityWithZSpread(BILL, PROVIDER, Z_SPREAD, CompoundedRateType.CONTINUOUS, 0); PointSensitivities sensiExpected = IssuerCurveZeroRateSensitivity.of( DSC_FACTORS_ISSUER.zeroRatePointSensitivityWithSpread(MATURITY_DATE, Z_SPREAD, CompoundedRateType.CONTINUOUS, 0), GROUP_ISSUER) .multipliedBy(NOTIONAL.getAmount()) .build(); assertTrue(sensiComputed.equalWithTolerance(sensiExpected, TOLERANCE_PV)); CurrencyParameterSensitivities paramSensiComputed = PROVIDER.parameterSensitivity(sensiComputed); CurrencyParameterSensitivities paramSensiExpected = FD_CALC.sensitivity( PROVIDER, p -> PRICER.presentValueWithZSpread(BILL, p, Z_SPREAD, CompoundedRateType.CONTINUOUS, 0)); assertTrue(paramSensiComputed.equalWithTolerance(paramSensiExpected, EPS * NOTIONAL_AMOUNT)); }
public void test_presentValue_zspread_aftermaturity() { CurrencyAmount pvComputed = PRICER.presentValueWithZSpread(BILL_PAST, PROVIDER, Z_SPREAD, CompoundedRateType.CONTINUOUS, 0); assertEquals(pvComputed.getCurrency(), EUR); assertEquals(pvComputed.getAmount(), 0.0d, TOLERANCE_PV); }
/** * Calculates the yield for settlement at a given settlement date using curves with z-spread. * <p> * The z-spread is a parallel shift applied to continuously compounded rates or * periodic compounded rates of the issuer discounting curve. * <p> * The z-spread is applied only on the legal entity curve, not on the repo curve. * * @param bill the bill * @param provider the discounting provider * @param settlementDate the settlement date * @param zSpread the z-spread * @param compoundedRateType the compounded rate type * @param periodsPerYear the number of periods per year * @return the yield */ public double yieldFromCurvesWithZSpread( ResolvedBill bill, LegalEntityDiscountingProvider provider, LocalDate settlementDate, double zSpread, CompoundedRateType compoundedRateType, int periodsPerYear) { double price = priceFromCurvesWithZSpread(bill, provider, settlementDate, zSpread, compoundedRateType, periodsPerYear); return bill.yieldFromPrice(price, settlementDate); }
/** * Calculates the yield for settlement at a given settlement date using curves. * * @param bill the bill * @param provider the discounting provider * @param settlementDate the settlement date * @return the yield */ public double yieldFromCurves(ResolvedBill bill, LegalEntityDiscountingProvider provider, LocalDate settlementDate) { double price = priceFromCurves(bill, provider, settlementDate); return bill.yieldFromPrice(price, settlementDate); }
/** * Calculates the present value sensitivity of a bill trade. * <p> * If the settlement details are provided, the sensitivity is the sum of the underlying product's sensitivity * multiplied by the quantity and the sensitivity of the settlement payment if still due at the valuation date. * If not it is the underlying product's sensitivity multiplied by the quantity. * * @param trade the trade * @param provider the discounting provider * @return the present value sensitivity */ public PointSensitivities presentValueSensitivity(ResolvedBillTrade trade, LegalEntityDiscountingProvider provider) { if (provider.getValuationDate().isAfter(trade.getProduct().getNotional().getDate())) { return PointSensitivities.empty(); } PointSensitivities sensiProduct = productPricer.presentValueSensitivity(trade.getProduct(), provider) .multipliedBy(trade.getQuantity()); if (!trade.getSettlement().isPresent()) { return sensiProduct; } Payment settlement = trade.getSettlement().get(); RepoCurveDiscountFactors repoDf = DiscountingBillProductPricer.repoCurveDf(trade.getProduct(), provider); PointSensitivities sensiSettle = presentValueSensitivitySettlement(settlement, repoDf); return sensiProduct.combinedWith(sensiSettle); }
/** * Calculates the present value of a bill trade. * <p> * If the settlement details are provided, the present value is the sum of the underlying product's present value * multiplied by the quantity and the present value of the settlement payment if still due at the valuation date. * If not it is the underlying product's present value multiplied by the quantity. * * @param trade the trade * @param provider the discounting provider * @return the present value */ public CurrencyAmount presentValue(ResolvedBillTrade trade, LegalEntityDiscountingProvider provider) { if (provider.getValuationDate().isAfter(trade.getProduct().getNotional().getDate())) { return CurrencyAmount.of(trade.getProduct().getCurrency(), 0.0d); } CurrencyAmount pvProduct = productPricer.presentValue(trade.getProduct(), provider) .multipliedBy(trade.getQuantity()); if (trade.getSettlement().isPresent()) { RepoCurveDiscountFactors repoDf = DiscountingBillProductPricer.repoCurveDf(trade.getProduct(), provider); CurrencyAmount pvSettle = paymentPricer.presentValue(trade.getSettlement().get(), repoDf.getDiscountFactors()); return pvProduct.plus(pvSettle); } return pvProduct; }
.presentValueSensitivityWithZSpread(trade.getProduct(), provider, zSpread, compoundedRateType, periodsPerYear) .multipliedBy(trade.getQuantity()); if (!trade.getSettlement().isPresent()) { RepoCurveDiscountFactors repoDf = DiscountingBillProductPricer.repoCurveDf(trade.getProduct(), provider); PointSensitivities sensiSettle = presentValueSensitivitySettlement(settlement, repoDf); return sensiProduct.combinedWith(sensiSettle);
.presentValueWithZSpread(trade.getProduct(), provider, zSpread, compoundedRateType, periodsPerYear) .multipliedBy(trade.getQuantity()); if (trade.getSettlement().isPresent()) { RepoCurveDiscountFactors repoDf = DiscountingBillProductPricer.repoCurveDf(trade.getProduct(), provider); CurrencyAmount pvSettle = paymentPricer.presentValue(trade.getSettlement().get(), repoDf.getDiscountFactors()); return pvProduct.plus(pvSettle);
/** * Calculates the present value sensitivity of the bill product. * <p> * The present value sensitivity of the product is the sensitivity of the present value to * the underlying curves. * * @param bill the product * @param provider the discounting provider * @return the present value curve sensitivity of the product */ public PointSensitivities presentValueSensitivity(ResolvedBill bill, LegalEntityDiscountingProvider provider) { if (provider.getValuationDate().isAfter(bill.getNotional().getDate())) { return PointSensitivities.empty(); } IssuerCurveDiscountFactors issuerDf = issuerCurveDf(bill, provider); double dfEndBar = bill.getNotional().getAmount(); PointSensitivityBuilder sensMaturity = issuerDf.zeroRatePointSensitivity(bill.getNotional().getDate()) .multipliedBy(dfEndBar); return sensMaturity.build(); }
public void yield_settle_date_after_maturity_error() { assertThrows(() -> PRICER.yieldFromCurves(BILL, PROVIDER, MATURITY_DATE), IllegalArgumentException.class); }
public void yield_zspread_settle_date_after_maturity_error() { assertThrows( () -> PRICER.yieldFromCurvesWithZSpread(BILL, PROVIDER, MATURITY_DATE, Z_SPREAD, CompoundedRateType.CONTINUOUS, 0), IllegalArgumentException.class); }
public void test_presentValue_zspread() { CurrencyAmount pvComputed = PRICER.presentValueWithZSpread(BILL, PROVIDER, Z_SPREAD, CompoundedRateType.CONTINUOUS, 0); double pvExpected = DSC_FACTORS_ISSUER.discountFactor(MATURITY_DATE) * NOTIONAL.getAmount() * Math.exp(-Z_SPREAD * DSC_FACTORS_ISSUER.relativeYearFraction(MATURITY_DATE)); assertEquals(pvComputed.getCurrency(), EUR); assertEquals(pvComputed.getAmount(), pvExpected, TOLERANCE_PV); }
public void price_zspread_settle_date_after_maturity_error() { assertThrows( () -> PRICER.priceFromCurvesWithZSpread(BILL, PROVIDER, MATURITY_DATE, Z_SPREAD, CompoundedRateType.CONTINUOUS, 0), IllegalArgumentException.class); }
public void price_settle_date_after_maturity_error() { assertThrows(() -> PRICER.priceFromCurves(BILL, PROVIDER, MATURITY_DATE), IllegalArgumentException.class); }