public void price_from_yield_discount() { double yield = 0.01; LocalDate settlementDate = LocalDate.of(2018, 8, 17); double af = US_BILL.getDayCount().relativeYearFraction(settlementDate, MATURITY_DATE); double priceExpected = 1.0d - yield * af; double priceComputed = US_BILL.priceFromYield(yield, settlementDate); assertEquals(priceExpected, priceComputed, TOLERANCE_PRICE); }
/** * Generates a Bill trade instance where the price is computed from the traded yield. * * @param info the additional trade information * @param product the bill that was traded * @param quantity the quantity that was traded * @param yield the yield at which the bill was traded * @return the instance */ public static BillTrade ofYield(TradeInfo info, Bill product, double quantity, double yield) { ArgChecker.isTrue(info.getSettlementDate().isPresent(), "Bill trades from yield need a settlement date"); LocalDate settlementDate = info.getSettlementDate().get(); double price = product.priceFromYield(yield, settlementDate); return BillTrade.builder() .info(info) .product(product) .quantity(quantity) .price(price) .build(); }
public void price_from_yield_intatmat() { Bill bill = US_BILL.toBuilder().yieldConvention(BillYieldConvention.INTEREST_AT_MATURITY).build(); double yield = 0.01; LocalDate settlementDate = LocalDate.of(2018, 8, 17); double af = bill.getDayCount().relativeYearFraction(settlementDate, MATURITY_DATE); double priceExpected = 1.0d / (1 + yield * af); double priceComputed = bill.priceFromYield(yield, settlementDate); assertEquals(priceExpected, priceComputed, TOLERANCE_PRICE); }