//------------------------------------------------------------------------- /// <summary> /// Calculates the price sensitivity of the bond future product. /// <para> /// The price sensitivity of the product is the sensitivity of the price to the underlying curves. /// </para> /// <para> /// Note that the price sensitivity should be no currency. /// /// </para> /// </summary> /// <param name="future"> the future </param> /// <param name="discountingProvider"> the discounting provider </param> /// <returns> the price curve sensitivity of the product </returns> public PointSensitivities priceSensitivity(ResolvedBondFuture future, LegalEntityDiscountingProvider discountingProvider) { ImmutableList <ResolvedFixedCouponBond> basket = future.DeliveryBasket; int size = basket.size(); double[] priceBonds = new double[size]; int indexCTD = 0; double priceMin = 2d; for (int i = 0; i < size; i++) { ResolvedFixedCouponBond bond = basket.get(i); double dirtyPrice = bondPricer.dirtyPriceFromCurves(bond, discountingProvider, future.LastDeliveryDate); priceBonds[i] = bondPricer.cleanPriceFromDirtyPrice(bond, future.LastDeliveryDate, dirtyPrice) / future.ConversionFactors.get(i); if (priceBonds[i] < priceMin) { priceMin = priceBonds[i]; indexCTD = i; } } ResolvedFixedCouponBond bond = basket.get(indexCTD); PointSensitivityBuilder pointSensi = bondPricer.dirtyPriceSensitivity(bond, discountingProvider, future.LastDeliveryDate); return(pointSensi.multipliedBy(1d / future.ConversionFactors.get(indexCTD)).build()); }
public virtual void test_dirtyPriceSensitivity() { PointSensitivityBuilder point = PRICER.dirtyPriceSensitivity(PRODUCT, PROVIDER, REF_DATA); CurrencyParameterSensitivities computed = PROVIDER.parameterSensitivity(point.build()); CurrencyParameterSensitivities expected = FD_CAL.sensitivity(PROVIDER, p => CurrencyAmount.of(EUR, PRICER.dirtyPriceFromCurves(PRODUCT, p, REF_DATA))); assertTrue(computed.equalWithTolerance(expected, NOTIONAL * EPS)); }