BillSecurityDiscountingMethod { public double yieldFromCleanPrice(final BillSecurity bill, final double price) { if (bill.getYieldConvention() == SimpleYieldConvention.DISCOUNT) { return (1.0 - price) / bill.getAccrualFactor(); } if (bill.getYieldConvention() == SimpleYieldConvention.INTERESTATMTY) { return (1.0 / price - 1) / 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 yieldFromPrice() { final double yieldComputedIAM = METHOD_SECURITY.yieldFromCleanPrice(BILL_BEL_IAM_SEC, PRICE); final double yieldExpectedIAM = (1.0 / PRICE - 1.0) / BILL_BEL_IAM_SEC.getAccrualFactor(); assertEquals("Bill Security: discounting method - yield", yieldExpectedIAM, yieldComputedIAM, TOLERANCE_YIELD); final double yieldComputedDSC = METHOD_SECURITY.yieldFromCleanPrice(BILL_US_DSC_SEC, PRICE); final double yieldExpectedDSC = (1.0 - PRICE) / BILL_US_DSC_SEC.getAccrualFactor(); assertEquals("Bill Security: discounting method - yield", yieldExpectedDSC, yieldComputedDSC, TOLERANCE_YIELD); }
@Test public void yieldFromPriceExternal() { final double yieldComputed = METHOD_SECURITY.yieldFromCleanPrice(BILL_BEL_IAM_SEC, PRICE); assertEquals("Bill Security: discounting method - yield", YIELD, yieldComputed, TOLERANCE_YIELD_EXTERNAL); }