public void test_dirtyPriceFromCleanPrice_cleanPriceFromDirtyPrice() { double dirtyPrice = PRICER.dirtyPriceFromCurves(PRODUCT, PROVIDER, REF_DATA); LocalDate settlement = DATE_OFFSET.adjust(VAL_DATE, REF_DATA); double cleanPrice = PRICER.cleanPriceFromDirtyPrice(PRODUCT, settlement, dirtyPrice); double accruedInterest = PRICER.accruedInterest(PRODUCT, settlement); assertEquals(cleanPrice, dirtyPrice - accruedInterest / NOTIONAL, NOTIONAL * TOL); double dirtyPriceRe = PRICER.dirtyPriceFromCleanPrice(PRODUCT, settlement, cleanPrice); assertEquals(dirtyPriceRe, dirtyPrice, TOL); }
public void test_zSpreadFromCurvesAndPV_periodic() { double dirtyPrice = PRICER.dirtyPriceFromCurvesWithZSpread( PRODUCT, PROVIDER, REF_DATA, Z_SPREAD, PERIODIC, PERIOD_PER_YEAR); double computed = PRICER.zSpreadFromCurvesAndDirtyPrice( PRODUCT, PROVIDER, REF_DATA, dirtyPrice, PERIODIC, PERIOD_PER_YEAR); assertEquals(computed, Z_SPREAD, TOL); }
public void modifiedDurationFromYieldUSLastPeriod() { double computed = PRICER.modifiedDurationFromYield(PRODUCT_US, SETTLEMENT_LAST_US, YIELD_US); double price = PRICER.dirtyPriceFromYield(PRODUCT_US, SETTLEMENT_LAST_US, YIELD_US); double priceUp = PRICER.dirtyPriceFromYield(PRODUCT_US, SETTLEMENT_LAST_US, YIELD_US + EPS); double priceDw = PRICER.dirtyPriceFromYield(PRODUCT_US, SETTLEMENT_LAST_US, YIELD_US - EPS); double expected = 0.5 * (priceDw - priceUp) / price / EPS; assertEquals(computed, expected, EPS); }
public void convexityFromYieldUS() { double computed = PRICER.convexityFromYield(PRODUCT_US, SETTLEMENT_US, YIELD_US); double duration = PRICER.modifiedDurationFromYield(PRODUCT_US, SETTLEMENT_US, YIELD_US); double durationUp = PRICER.modifiedDurationFromYield(PRODUCT_US, SETTLEMENT_US, YIELD_US + EPS); double durationDw = PRICER.modifiedDurationFromYield(PRODUCT_US, SETTLEMENT_US, YIELD_US - EPS); double expected = 0.5 * (durationDw - durationUp) / EPS + duration * duration; assertEquals(computed, expected, EPS); }
for (int i = 0; i < size; ++i) { ResolvedFixedCouponBond bond = basket.get(i); double dirtyPrice = bondPricer.dirtyPriceFromCurvesWithZSpread( bond, discountingProvider, zSpread, compoundedRateType, periodPerYear, future.getLastDeliveryDate()); priceBonds[i] = bondPricer.cleanPriceFromDirtyPrice( bond, future.getLastDeliveryDate(), dirtyPrice) / future.getConversionFactors().get(i);
PointSensitivityBuilder dirtyPriceSensitivityWithZspread( ResolvedFixedCouponBond bond, LegalEntityDiscountingProvider provider, double zSpread, CompoundedRateType compoundedRateType, int periodsPerYear, LocalDate referenceDate) { RepoCurveDiscountFactors repoDf = repoCurveDf(bond, provider); double df = repoDf.discountFactor(referenceDate); CurrencyAmount pv = presentValueWithZSpread(bond, provider, zSpread, compoundedRateType, periodsPerYear); double notional = bond.getNotional(); PointSensitivityBuilder pvSensi = presentValueSensitivityWithZSpread( bond, provider, zSpread, compoundedRateType, periodsPerYear).multipliedBy(1d / df / notional); RepoCurveZeroRateSensitivity dfSensi = repoDf.zeroRatePointSensitivity(referenceDate) .multipliedBy(-pv.getAmount() / df / df / notional); return pvSensi.combinedWith(dfSensi); }
/** * Calculates the price of the bond future product. * <p> * The price of the product is the price on the valuation date. * <p> * Strata uses <i>decimal prices</i> for bond futures. This is coherent with the pricing of {@link FixedCouponBond}. * For example, a price of 99.32% is represented in Strata by 0.9932. * * @param future the future * @param discountingProvider the discounting provider * @return the price of the product, in decimal form */ public double price(ResolvedBondFuture future, LegalEntityDiscountingProvider discountingProvider) { ImmutableList<ResolvedFixedCouponBond> basket = future.getDeliveryBasket(); int size = basket.size(); double[] priceBonds = new double[size]; for (int i = 0; i < size; ++i) { ResolvedFixedCouponBond bond = basket.get(i); double dirtyPrice = bondPricer.dirtyPriceFromCurves(bond, discountingProvider, future.getLastDeliveryDate()); priceBonds[i] = bondPricer.cleanPriceFromDirtyPrice( bond, future.getLastDeliveryDate(), dirtyPrice) / future.getConversionFactors().get(i); } return Doubles.min(priceBonds); }
public void dirtyPriceFromYieldUSLastPeriod() { double dirtyPrice = PRICER.dirtyPriceFromYield(PRODUCT_US, SETTLEMENT_LAST_US, YIELD_US); assertEquals(dirtyPrice, 1.005635683760684, TOL); // 2.x. double yield = PRICER.yieldFromDirtyPrice(PRODUCT_US, SETTLEMENT_LAST_US, dirtyPrice); assertEquals(yield, YIELD_US, TOL); }
for (int i = 0; i < size; i++) { ResolvedFixedCouponBond bond = basket.get(i); double dirtyPrice = bondPricer.dirtyPriceFromCurves(bond, discountingProvider, future.getLastDeliveryDate()); priceBonds[i] = bondPricer.cleanPriceFromDirtyPrice( bond, future.getLastDeliveryDate(), dirtyPrice) / future.getConversionFactors().get(i); if (priceBonds[i] < priceMin) { PointSensitivityBuilder pointSensi = bondPricer.dirtyPriceSensitivity( bond, discountingProvider, future.getLastDeliveryDate()); return pointSensi.multipliedBy(1d / future.getConversionFactors().get(indexCTD)).build();
for (int i = 0; i < size; i++) { ResolvedFixedCouponBond bond = basket.get(i); double dirtyPrice = bondPricer.dirtyPriceFromCurvesWithZSpread( bond, discountingProvider, zSpread, compoundedRateType, periodPerYear, future.getLastDeliveryDate()); priceBonds[i] = bondPricer.cleanPriceFromDirtyPrice( bond, future.getLastDeliveryDate(), dirtyPrice) / future.getConversionFactors().get(i); if (priceBonds[i] < priceMin) { PointSensitivityBuilder pointSensi = bondPricer.dirtyPriceSensitivityWithZspread( bond, discountingProvider, zSpread, compoundedRateType, periodPerYear, future.getLastDeliveryDate()); return pointSensi.multipliedBy(1d / future.getConversionFactors().get(indexCTD)).build();
public void dirtyPriceFromYieldJP() { double computed = PRICER.dirtyPriceFromYield(PRODUCT_JP, SETTLEMENT_JP, YIELD_JP); double maturity = DayCounts.NL_365.relativeYearFraction(SETTLEMENT_JP, END_JP); double expected = PRICER.dirtyPriceFromCleanPrice( PRODUCT_JP, SETTLEMENT_JP, (1d + RATE_JP * maturity) / (1d + YIELD_JP * maturity)); assertEquals(computed, expected, TOL); double yield = PRICER.yieldFromDirtyPrice(PRODUCT_JP, SETTLEMENT_JP, computed); assertEquals(yield, YIELD_JP, TOL); }
/** * Calculates the dirty price of the fixed coupon bond from its settlement date and clean price. * * @param bond the product * @param settlementDate the settlement date * @param cleanPrice the clean price * @return the present value of the fixed coupon bond product */ public double dirtyPriceFromCleanPrice(ResolvedFixedCouponBond bond, LocalDate settlementDate, double cleanPrice) { double notional = bond.getNotional(); double accruedInterest = accruedInterest(bond, settlementDate); return cleanPrice + accruedInterest / notional; }
PointSensitivityBuilder dirtyPriceSensitivity( ResolvedFixedCouponBond bond, LegalEntityDiscountingProvider provider, LocalDate referenceDate) { RepoCurveDiscountFactors repoDf = repoCurveDf(bond, provider); double df = repoDf.discountFactor(referenceDate); CurrencyAmount pv = presentValue(bond, provider); double notional = bond.getNotional(); PointSensitivityBuilder pvSensi = presentValueSensitivity(bond, provider).multipliedBy(1d / df / notional); RepoCurveZeroRateSensitivity dfSensi = repoDf.zeroRatePointSensitivity(referenceDate) .multipliedBy(-pv.getAmount() / df / df / notional); return pvSensi.combinedWith(dfSensi); }
LocalDate tradeSettlementDate = settlementDate(trade, provider.getValuationDate()); Currency currency = product.getCurrency(); RepoCurveDiscountFactors repoDf = DiscountingFixedCouponBondProductPricer.repoCurveDf(product, provider); double df = repoDf.discountFactor(standardSettlementDate); double pvStandard = (cleanPrice * product.getNotional() + productPricer.accruedInterest(product, standardSettlementDate)) * df; if (standardSettlementDate.isEqual(tradeSettlementDate)) { return presentValueFromProductPresentValue(trade, provider, CurrencyAmount.of(currency, pvStandard)); IssuerCurveDiscountFactors issuerDf = DiscountingFixedCouponBondProductPricer.issuerCurveDf(product, provider); double pvDiff = 0d; if (standardSettlementDate.isAfter(tradeSettlementDate)) { pvDiff = productPricer.presentValueCoupon(product, issuerDf, tradeSettlementDate, standardSettlementDate); } else { pvDiff = -productPricer.presentValueCoupon(product, issuerDf, standardSettlementDate, tradeSettlementDate);
LocalDate tradeSettlementDate = settlementDate(trade, provider.getValuationDate()); Currency currency = product.getCurrency(); RepoCurveDiscountFactors repoDf = DiscountingFixedCouponBondProductPricer.repoCurveDf(product, provider); double df = repoDf.discountFactor(standardSettlementDate); double pvStandard = (cleanPrice * product.getNotional() + productPricer.accruedInterest(product, standardSettlementDate)) * df; if (standardSettlementDate.isEqual(tradeSettlementDate)) { return presentValueFromProductPresentValue(trade, provider, CurrencyAmount.of(currency, pvStandard)); IssuerCurveDiscountFactors issuerDf = DiscountingFixedCouponBondProductPricer.issuerCurveDf(product, provider); double pvDiff = 0d; if (standardSettlementDate.isAfter(tradeSettlementDate)) { pvDiff = productPricer.presentValueCouponWithZSpread( product, issuerDf, periodsPerYear); } else { pvDiff = -productPricer.presentValueCouponWithZSpread( product, issuerDf,
int nCoupon = payments.size() - couponIndex(payments, settlementDate); FixedCouponBondYieldConvention yieldConv = bond.getYieldConvention(); if (nCoupon == 1) { if (yieldConv.equals(US_STREET) || yieldConv.equals(DE_BONDS)) { double couponPerYear = bond.getFrequency().eventsPerYear(); double factorToNextCoupon = factorToNextCoupon(bond, settlementDate); double timeToPay = factorToNextCoupon / couponPerYear; double disc = (1d + factorToNextCoupon * yield / couponPerYear); return convexityFromYieldStandard(bond, settlementDate, yield); double num = 1d + bond.getFixedRate() * maturity; double den = 1d + yield * maturity; double dirtyPrice = dirtyPriceFromCleanPrice(bond, settlementDate, num / den); return 2d * num * Math.pow(maturity, 2) * Math.pow(den, -3) / dirtyPrice;
int nCoupon = payments.size() - couponIndex(payments, settlementDate); FixedCouponBondYieldConvention yieldConv = bond.getYieldConvention(); if (nCoupon == 1) { FixedCouponBondPaymentPeriod payment = payments.get(payments.size() - 1); return (1d + payment.getFixedRate() * payment.getYearFraction()) / (1d + factorToNextCoupon(bond, settlementDate) * yield / ((double) bond.getFrequency().eventsPerYear())); return dirtyPriceFromYieldStandard(bond, settlementDate, yield); return dirtyPriceFromCleanPrice(bond, settlementDate, cleanPrice);
int nCoupon = payments.size() - couponIndex(payments, settlementDate); FixedCouponBondYieldConvention yieldConv = bond.getYieldConvention(); if (nCoupon == 1) { if (yieldConv.equals(US_STREET) || yieldConv.equals(DE_BONDS)) { double couponPerYear = bond.getFrequency().eventsPerYear(); double factor = factorToNextCoupon(bond, settlementDate); return factor / couponPerYear / (1d + factor * yield / couponPerYear); return modifiedDurationFromYieldStandard(bond, settlementDate, yield); double num = 1d + bond.getFixedRate() * maturity; double den = 1d + yield * maturity; double dirtyPrice = dirtyPriceFromCleanPrice(bond, settlementDate, num / den); return num * maturity / den / den / dirtyPrice;
public void test_dirtyPriceSensitivityWithZspread_continuous() { PointSensitivityBuilder point = PRICER.dirtyPriceSensitivityWithZspread(PRODUCT, PROVIDER, REF_DATA, Z_SPREAD, CONTINUOUS, 0); CurrencyParameterSensitivities computed = PROVIDER.parameterSensitivity(point.build()); CurrencyParameterSensitivities expected = FD_CAL.sensitivity(PROVIDER, p -> CurrencyAmount.of( EUR, PRICER.dirtyPriceFromCurvesWithZSpread(PRODUCT, p, REF_DATA, Z_SPREAD, CONTINUOUS, 0))); assertTrue(computed.equalWithTolerance(expected, NOTIONAL * EPS)); }
public void test_dirtyPriceFromCurvesWithZSpread_continuous() { double computed = PRICER.dirtyPriceFromCurvesWithZSpread( PRODUCT, PROVIDER, REF_DATA, Z_SPREAD, CONTINUOUS, 0); CurrencyAmount pv = PRICER.presentValueWithZSpread(PRODUCT, PROVIDER, Z_SPREAD, CONTINUOUS, 0); LocalDate settlement = DATE_OFFSET.adjust(VAL_DATE, REF_DATA); double df = DSC_FACTORS_REPO.discountFactor(settlement); assertEquals(computed, pv.getAmount() / df / NOTIONAL); }