/** * Calculates the reference price for the trade. * <p> * If the valuation date equals the trade date, then the reference price is the trade price. * Otherwise, the reference price is the last settlement price used for margining. * * @param trade the trade * @param valuationDate the date for which the reference price should be calculated * @param lastSettlementPrice the last settlement price used for margining, in decimal form * @return the reference price, in decimal form */ private double referencePrice(ResolvedBondFutureOptionTrade trade, LocalDate valuationDate, double lastSettlementPrice) { ArgChecker.notNull(valuationDate, "valuationDate"); return trade.getTradedPrice() .filter(tp -> tp.getTradeDate().equals(valuationDate)) .map(tp -> tp.getPrice()) .orElse(lastSettlementPrice); }
public void test_presentValue_from_prices_date() { double currentPrice = 0.0325; double lastClosingPrice = 0.03; LocalDate valuationDate1 = LocalDate.of(2014, 3, 30); // before trade date CurrencyAmount computed1 = OPTION_TRADE_PRICER.presentValue(OPTION_TRADE, valuationDate1, currentPrice, lastClosingPrice); double expected2 = NOTIONAL * QUANTITY * (currentPrice - lastClosingPrice); assertEquals(computed1.getCurrency(), Currency.EUR); assertEquals(computed1.getAmount(), expected2, TOL * NOTIONAL * QUANTITY); LocalDate valuationDate2 = LocalDate.of(2014, 3, 31); // equal to trade date CurrencyAmount computed2 = OPTION_TRADE_PRICER.presentValue(OPTION_TRADE, valuationDate2, currentPrice, lastClosingPrice); double expected = NOTIONAL * QUANTITY * (currentPrice - OPTION_TRADE.getTradedPrice().get().getPrice()); assertEquals(computed2.getCurrency(), Currency.EUR); assertEquals(computed2.getAmount(), expected, TOL * NOTIONAL * QUANTITY); }
public void test_getters() { ResolvedBondFutureOptionTrade test = sut(); BondFutureOptionTrade base = BondFutureOptionTradeTest.sut(); assertEquals(test.getTradedPrice().get(), TradedPrice.of(base.getInfo().getTradeDate().get(), base.getPrice())); }