BillSecurityDiscountingMethod { public double yieldFromPriceDerivative(final BillSecurity bill, final double price) { if (bill.getYieldConvention() == SimpleYieldConvention.DISCOUNT) { return -1.0 / bill.getAccrualFactor(); } if (bill.getYieldConvention() == SimpleYieldConvention.INTERESTATMTY) { return -1.0 / (price * price * bill.getAccrualFactor()); } throw new UnsupportedOperationException("The convention " + bill.getYieldConvention().getName() + " is not supported."); } private  BillSecurityDiscountingMethod(); static BillSecurityDiscountingMethod getInstance(); MultipleCurrencyAmount presentValue(final BillSecurity bill, final IssuerProviderInterface issuer); double priceFromYield(final BillSecurity bill, final double yield); double priceFromYield(final YieldConvention convention, final double yield, final double accrualFactor); double yieldFromCleanPrice(final BillSecurity bill, final double price); double yieldFromPriceDerivative(final BillSecurity bill, final double price); MultipleCurrencyAmount presentValueFromYield(final BillSecurity bill, final double yield, final IssuerProviderInterface issuer); MultipleCurrencyAmount presentValueFromPrice(final BillSecurity bill, final double price, final IssuerProviderInterface issuer); double priceFromCurves(final BillSecurity bill, final IssuerProviderInterface issuer); double yieldFromCurves(final BillSecurity bill, final IssuerProviderInterface issuer); MultipleCurrencyMulticurveSensitivity presentValueCurveSensitivity(final BillSecurity bill, final IssuerProviderInterface issuer);  }
@Test public void yieldFromPriceDerivative() { final double shift = 1.0E-8; final double yieldIAM = METHOD_SECURITY.yieldFromCleanPrice(BILL_BEL_IAM_SEC, PRICE); final double yieldPIAM = METHOD_SECURITY.yieldFromCleanPrice(BILL_BEL_IAM_SEC, PRICE + shift); final double yieldDerivativeExpectedIAM = (yieldPIAM - yieldIAM) / shift; final double yieldDerivativeComputedIAM = METHOD_SECURITY.yieldFromPriceDerivative(BILL_BEL_IAM_SEC, PRICE); assertEquals("Bill Security: discounting method - yield", yieldDerivativeExpectedIAM, yieldDerivativeComputedIAM, TOLERANCE_YIELD_DERIVATIVE); final double yieldDSC = METHOD_SECURITY.yieldFromCleanPrice(BILL_US_DSC_SEC, PRICE); final double yieldPDSC = METHOD_SECURITY.yieldFromCleanPrice(BILL_US_DSC_SEC, PRICE + shift); final double yieldDerivativeExpectedDSC = (yieldPDSC - yieldDSC) / shift; final double yieldDerivativeComputedDSC = METHOD_SECURITY.yieldFromPriceDerivative(BILL_US_DSC_SEC, PRICE); assertEquals("Bill Security: discounting method - yield", yieldDerivativeExpectedDSC, yieldDerivativeComputedDSC, TOLERANCE_YIELD_DERIVATIVE); }