@Override protected Object propertyGet(Bean bean, String propertyName, boolean quiet) { switch (propertyName.hashCode()) { case 111972721: // value return ((AdjustablePayment) bean).getValue(); case 3076014: // date return ((AdjustablePayment) bean).getDate(); } return super.propertyGet(bean, propertyName, quiet); }
/** * Computes the price from the yield at a given settlement date. * * @param yield the yield * @param settlementDate the settlement date * @return the price */ public double priceFromYield(double yield, LocalDate settlementDate) { double accrualFactor = dayCount.relativeYearFraction(settlementDate, notional.getDate().getUnadjusted()); return yieldConvention.priceFromYield(yield, accrualFactor); }
/** * Computes the yield from the price at a given settlement date. * * @param price the price * @param settlementDate the settlement date * @return the yield */ public double yieldFromPrice(double price, LocalDate settlementDate) { double accrualFactor = dayCount.relativeYearFraction(settlementDate, notional.getDate().getUnadjusted()); return yieldConvention.yieldFromPrice(price, accrualFactor); }
public void test_ofYield() { BillTrade test = sut_yield(); assertEquals(test.getProduct(), PRODUCT); assertEquals(test.getInfo(), TRADE_INFO); assertEquals(test.getQuantity(), QUANTITY); double price = 1.0d - YIELD * PRODUCT.getDayCount().relativeYearFraction(SETTLEMENT_DATE, PRODUCT.getNotional().getDate().getUnadjusted()); assertEquals(test.getPrice(), price, TOLERANCE_PRICE); assertEquals(test.withInfo(TRADE_INFO).getInfo(), TRADE_INFO); assertEquals(test.withQuantity(129).getQuantity(), 129d, 0d); assertEquals(test.withPrice(129).getPrice(), 129d, 0d); }