/** * 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); }
double dirtyPrice = bondPricer.dirtyPriceFromCurvesWithZSpread( bond, discountingProvider, zSpread, compoundedRateType, periodPerYear, future.getLastDeliveryDate()); priceBonds[i] = bondPricer.cleanPriceFromDirtyPrice( bond, future.getLastDeliveryDate(), dirtyPrice) / future.getConversionFactors().get(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) {
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); }
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) {
public void test_price() { double computed = FUTURE_PRICER.price(FUTURE_PRODUCT, PROVIDER); double dirtyPrice = BOND_PRICER.dirtyPriceFromCurves( BOND, PROVIDER, FUTURE_PRODUCT.getLastDeliveryDate()); double expected = BOND_PRICER.cleanPriceFromDirtyPrice( BOND, FUTURE_PRODUCT.getLastDeliveryDate(), dirtyPrice) / CONVERSION_FACTOR[0]; assertEquals(computed, expected, TOL); }
public void test_priceWithZSpread_continuous() { double computed = FUTURE_PRICER.priceWithZSpread(FUTURE_PRODUCT, PROVIDER, Z_SPREAD, CONTINUOUS, 0); double dirtyPrice = BOND_PRICER.dirtyPriceFromCurvesWithZSpread( BOND, PROVIDER, Z_SPREAD, CONTINUOUS, 0, FUTURE_PRODUCT.getLastDeliveryDate()); double expected = BOND_PRICER.cleanPriceFromDirtyPrice( BOND, FUTURE_PRODUCT.getLastDeliveryDate(), dirtyPrice) / CONVERSION_FACTOR[0]; assertEquals(computed, expected, TOL); }
public void test_priceWithZSpread_periodic() { double computed = FUTURE_PRICER.priceWithZSpread(FUTURE_PRODUCT, PROVIDER, Z_SPREAD, PERIODIC, PERIOD_PER_YEAR); double dirtyPrice = BOND_PRICER.dirtyPriceFromCurvesWithZSpread( BOND, PROVIDER, Z_SPREAD, PERIODIC, PERIOD_PER_YEAR, FUTURE_PRODUCT.getLastDeliveryDate()); double expected = BOND_PRICER.cleanPriceFromDirtyPrice( BOND, FUTURE_PRODUCT.getLastDeliveryDate(), dirtyPrice) / CONVERSION_FACTOR[0]; assertEquals(computed, expected, TOL); }
public void test_presentValueFromCleanPrice_coherency() { double priceDirty = PRODUCT_PRICER.dirtyPriceFromCurves(PRODUCT, PROVIDER, REF_DATA); LocalDate standardSettlementDate = PRODUCT.getSettlementDateOffset().adjust(PROVIDER.getValuationDate(), REF_DATA); double priceCleanComputed = PRODUCT_PRICER.cleanPriceFromDirtyPrice(PRODUCT, standardSettlementDate, priceDirty); CurrencyAmount pvCleanPrice = TRADE_PRICER.presentValueFromCleanPrice(TRADE, PROVIDER, REF_DATA, priceCleanComputed); CurrencyAmount pvCurves = TRADE_PRICER.presentValue(TRADE, PROVIDER); assertEquals(pvCleanPrice.getAmount(), pvCurves.getAmount(), NOTIONAL * TOL); }
/** * Calculates the yield of the fixed coupon bond product from dirty price. * <p> * The dirty price must be fractional. * If the analytic formula is not available, the yield is computed by solving * a root-finding problem with {@link #dirtyPriceFromYield(ResolvedFixedCouponBond, LocalDate, double)}. * The result is also expressed in fraction. * * @param bond the product * @param settlementDate the settlement date * @param dirtyPrice the dirty price * @return the yield of the product */ public double yieldFromDirtyPrice(ResolvedFixedCouponBond bond, LocalDate settlementDate, double dirtyPrice) { if (bond.getYieldConvention().equals(JP_SIMPLE)) { double cleanPrice = cleanPriceFromDirtyPrice(bond, settlementDate, dirtyPrice); LocalDate maturityDate = bond.getUnadjustedEndDate(); double maturity = bond.getDayCount().relativeYearFraction(settlementDate, maturityDate); return (bond.getFixedRate() + (1d - cleanPrice) / maturity) / cleanPrice; } final Function<Double, Double> priceResidual = new Function<Double, Double>() { @Override public Double apply(final Double y) { return dirtyPriceFromYield(bond, settlementDate, y) - dirtyPrice; } }; double[] range = ROOT_BRACKETER.getBracketedPoints(priceResidual, 0.00, 0.20); double yield = ROOT_FINDER.getRoot(priceResidual, range[0], range[1]); return yield; }
public void test_presentValueFromCleanPriceWithZSpread_continuous_coherency() { double priceDirty = PRODUCT_PRICER .dirtyPriceFromCurvesWithZSpread(PRODUCT, PROVIDER, REF_DATA, Z_SPREAD, CONTINUOUS, 0); LocalDate standardSettlementDate = PRODUCT.getSettlementDateOffset().adjust(PROVIDER.getValuationDate(), REF_DATA); double priceCleanComputed = PRODUCT_PRICER.cleanPriceFromDirtyPrice(PRODUCT, standardSettlementDate, priceDirty); CurrencyAmount pvCleanPrice = TRADE_PRICER.presentValueFromCleanPriceWithZSpread( TRADE, PROVIDER, REF_DATA, priceCleanComputed, Z_SPREAD, CONTINUOUS, 0); CurrencyAmount pvCurves = TRADE_PRICER.presentValueWithZSpread(TRADE, PROVIDER, Z_SPREAD, CONTINUOUS, 0); assertEquals(pvCleanPrice.getAmount(), pvCurves.getAmount(), NOTIONAL * TOL); }
public void test_presentValueFromCleanPriceWithZSpread_continuous_noExcoupon_coherency() { double priceDirty = PRODUCT_PRICER.dirtyPriceFromCurvesWithZSpread( PRODUCT_NO_EXCOUPON, PROVIDER, REF_DATA, Z_SPREAD, CONTINUOUS, 0); LocalDate standardSettlementDate = PRODUCT.getSettlementDateOffset().adjust(PROVIDER.getValuationDate(), REF_DATA); double priceCleanComputed = PRODUCT_PRICER.cleanPriceFromDirtyPrice(PRODUCT, standardSettlementDate, priceDirty); CurrencyAmount pvCleanPrice = TRADE_PRICER.presentValueFromCleanPriceWithZSpread( TRADE_NO_EXCOUPON, PROVIDER, REF_DATA, priceCleanComputed, Z_SPREAD, CONTINUOUS, 0); CurrencyAmount pvCurves = TRADE_PRICER .presentValueWithZSpread(TRADE_NO_EXCOUPON, PROVIDER, Z_SPREAD, CONTINUOUS, 0); assertEquals(pvCleanPrice.getAmount(), pvCurves.getAmount(), NOTIONAL * TOL); }
public void test_presentValueFromCleanPriceWithZSpread_periodic_coherency() { double priceDirty = PRODUCT_PRICER.dirtyPriceFromCurvesWithZSpread( PRODUCT, PROVIDER, REF_DATA, Z_SPREAD, PERIODIC, PERIOD_PER_YEAR); LocalDate standardSettlementDate = PRODUCT.getSettlementDateOffset().adjust(PROVIDER.getValuationDate(), REF_DATA); double priceCleanComputed = PRODUCT_PRICER.cleanPriceFromDirtyPrice(PRODUCT, standardSettlementDate, priceDirty); CurrencyAmount pvCleanPrice = TRADE_PRICER.presentValueFromCleanPriceWithZSpread( TRADE, PROVIDER, REF_DATA, priceCleanComputed, Z_SPREAD, PERIODIC, PERIOD_PER_YEAR); CurrencyAmount pvCurves = TRADE_PRICER .presentValueWithZSpread(TRADE, PROVIDER, Z_SPREAD, PERIODIC, PERIOD_PER_YEAR); assertEquals(pvCleanPrice.getAmount(), pvCurves.getAmount(), NOTIONAL * TOL); }
public void test_presentValueFromCleanPrice_noExcoupon_coherency() { double priceDirty = PRODUCT_PRICER.dirtyPriceFromCurves(PRODUCT_NO_EXCOUPON, PROVIDER, REF_DATA); LocalDate standardSettlementDate = PRODUCT.getSettlementDateOffset().adjust(PROVIDER.getValuationDate(), REF_DATA); double priceCleanComputed = PRODUCT_PRICER.cleanPriceFromDirtyPrice(PRODUCT, standardSettlementDate, priceDirty); CurrencyAmount pvCleanPrice = TRADE_PRICER.presentValueFromCleanPrice( TRADE_NO_EXCOUPON, PROVIDER, REF_DATA, priceCleanComputed); CurrencyAmount pvCurves = TRADE_PRICER.presentValue(TRADE_NO_EXCOUPON, PROVIDER); assertEquals(pvCleanPrice.getAmount(), pvCurves.getAmount(), NOTIONAL * TOL); }
public void test_presentValueFromCleanPriceWithZSpread_periodic_noExcoupon_coherency() { double priceDirty = PRODUCT_PRICER.dirtyPriceFromCurvesWithZSpread( PRODUCT_NO_EXCOUPON, PROVIDER, REF_DATA, Z_SPREAD, PERIODIC, PERIOD_PER_YEAR); LocalDate standardSettlementDate = PRODUCT.getSettlementDateOffset().adjust(PROVIDER.getValuationDate(), REF_DATA); double priceCleanComputed = PRODUCT_PRICER.cleanPriceFromDirtyPrice(PRODUCT, standardSettlementDate, priceDirty); CurrencyAmount pvCleanPrice = TRADE_PRICER.presentValueFromCleanPriceWithZSpread( TRADE_NO_EXCOUPON, PROVIDER, REF_DATA, priceCleanComputed, Z_SPREAD, PERIODIC, PERIOD_PER_YEAR); CurrencyAmount pvCurves = TRADE_PRICER.presentValueWithZSpread( TRADE_NO_EXCOUPON, PROVIDER, Z_SPREAD, PERIODIC, PERIOD_PER_YEAR); assertEquals(pvCleanPrice.getAmount(), pvCurves.getAmount(), NOTIONAL * TOL); }