/** * Calculates the present value sensitivity of the Ibor future trade. * <p> * The present value sensitivity of the trade is the sensitivity of the present value to * the underlying curves. * * @param trade the trade * @param ratesProvider the rates provider * @return the present value curve sensitivity of the trade */ public PointSensitivities presentValueSensitivity(ResolvedIborFutureTrade trade, RatesProvider ratesProvider) { ResolvedIborFuture product = trade.getProduct(); PointSensitivities priceSensi = productPricer.priceSensitivity(product, ratesProvider); PointSensitivities marginIndexSensi = productPricer.marginIndexSensitivity(product, priceSensi); return marginIndexSensi.multipliedBy(trade.getQuantity()); }
/** * Restricted copy constructor. * @param beanToCopy the bean to copy from, not null */ private Builder(ResolvedIborFutureTrade beanToCopy) { this.info = beanToCopy.getInfo(); this.product = beanToCopy.getProduct(); this.quantity = beanToCopy.getQuantity(); this.tradedPrice = beanToCopy.tradedPrice; }
@Override public ResolvedIborFutureTrade build() { return new ResolvedIborFutureTrade( info, product, quantity, tradedPrice); }
public void test_builder() { ResolvedIborFutureTrade test = sut(); assertEquals(test.getInfo(), TRADE_INFO); assertEquals(test.getProduct(), PRODUCT); assertEquals(test.getQuantity(), QUANTITY); assertEquals(test.getTradedPrice(), Optional.of(TradedPrice.of(TRADE_DATE, PRICE))); }
public void test_presentValue_on_trade_date() { IborIndexRates mockIbor = mock(IborIndexRates.class); SimpleRatesProvider prov = new SimpleRatesProvider(); prov.setIborRates(mockIbor); prov.setValuationDate(FUTURE_TRADE.getTradedPrice().get().getTradeDate()); when(mockIbor.rate(FUTURE.getIborRate().getObservation())).thenReturn(RATE); double lastClosingPrice = 1.025; DiscountingIborFutureTradePricer pricerFn = DiscountingIborFutureTradePricer.DEFAULT; double expected = ((1.0 - RATE) - FUTURE_TRADE.getTradedPrice().get().getPrice()) * FUTURE.getAccrualFactor() * FUTURE.getNotional() * FUTURE_TRADE.getQuantity(); CurrencyAmount computed = pricerFn.presentValue(FUTURE_TRADE, prov, lastClosingPrice); assertEquals(computed.getAmount(), expected, TOLERANCE_PV); assertEquals(computed.getCurrency(), FUTURE.getCurrency()); }
/** * Calculates the price sensitivity of the Ibor future product. * <p> * The price sensitivity of the product is the sensitivity of the price to the underlying curves. * * @param trade the trade * @param ratesProvider the rates provider * @return the price curve sensitivity of the product */ public PointSensitivities priceSensitivity(ResolvedIborFutureTrade trade, RatesProvider ratesProvider) { return productPricer.priceSensitivity(trade.getProduct(), ratesProvider); }
/** * 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(ResolvedIborFutureTrade 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_presentValueSensitivity() { IborIndexRates mockIbor = mock(IborIndexRates.class); SimpleRatesProvider prov = new SimpleRatesProvider(); prov.setIborRates(mockIbor); PointSensitivities sensiPrice = PRICER_PRODUCT.priceSensitivity(FUTURE, prov); PointSensitivities sensiPresentValueExpected = sensiPrice.multipliedBy( FUTURE.getNotional() * FUTURE.getAccrualFactor() * FUTURE_TRADE.getQuantity()); PointSensitivities sensiPresentValueComputed = PRICER_TRADE.presentValueSensitivity(FUTURE_TRADE, prov); assertTrue(sensiPresentValueComputed.equalWithTolerance(sensiPresentValueExpected, TOLERANCE_PV_DELTA)); }
public void test_resolve() { ResolvedIborFutureTrade expected = ResolvedIborFutureTrade.builder() .info(POSITION_INFO) .product(PRODUCT.resolve(REF_DATA)) .quantity(QUANTITY) .build(); assertEquals(sut().resolve(REF_DATA), expected); }
public void test_resolve() { IborFutureTrade test = sut(); ResolvedIborFutureTrade resolved = test.resolve(REF_DATA); assertEquals(resolved.getInfo(), TRADE_INFO); assertEquals(resolved.getProduct(), PRODUCT.resolve(REF_DATA)); assertEquals(resolved.getQuantity(), QUANTITY); assertEquals(resolved.getTradedPrice(), Optional.of(TradedPrice.of(TRADE_DATE, PRICE))); }
public void test_presentValue_after_trade_date() { IborIndexRates mockIbor = mock(IborIndexRates.class); SimpleRatesProvider prov = new SimpleRatesProvider(); prov.setIborRates(mockIbor); prov.setValuationDate(FUTURE_TRADE.getTradedPrice().get().getTradeDate().plusDays(1)); when(mockIbor.rate(FUTURE.getIborRate().getObservation())).thenReturn(RATE); double lastClosingPrice = 1.025; DiscountingIborFutureTradePricer pricerFn = DiscountingIborFutureTradePricer.DEFAULT; double expected = ((1.0 - RATE) - lastClosingPrice) * FUTURE.getAccrualFactor() * FUTURE.getNotional() * FUTURE_TRADE.getQuantity(); CurrencyAmount computed = pricerFn.presentValue(FUTURE_TRADE, prov, lastClosingPrice); assertEquals(computed.getAmount(), expected, TOLERANCE_PV); assertEquals(computed.getCurrency(), FUTURE.getCurrency()); }
/** * Calculates the price of the Ibor future trade. * <p> * The price of the trade is the price on the valuation date. * The price is calculated using the discounting model. * * @param trade the trade * @param ratesProvider the rates provider * @return the price of the trade, in decimal form */ public double price(ResolvedIborFutureTrade trade, RatesProvider ratesProvider) { return productPricer.price(trade.getProduct(), ratesProvider); }
/** * 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 */ double referencePrice(ResolvedIborFutureTrade trade, LocalDate valuationDate, double lastSettlementPrice) { ArgChecker.notNull(valuationDate, "valuationDate"); return trade.getTradedPrice() .filter(tp -> tp.getTradeDate().equals(valuationDate)) .map(tp -> tp.getPrice()) .orElse(lastSettlementPrice); }
static ResolvedIborFutureTrade sut() { return ResolvedIborFutureTrade.builder() .info(TRADE_INFO) .product(PRODUCT) .quantity(QUANTITY) .tradedPrice(TradedPrice.of(TRADE_DATE, PRICE)) .build(); }
/** * Calculates the present value sensitivity of the Ibor future trade. * <p> * The present value sensitivity of the trade is the sensitivity of the present value to * the underlying curves. * * @param trade the trade * @param ratesProvider the rates provider * @param hwProvider the Hull-White model parameter provider * @return the present value curve sensitivity of the trade */ public PointSensitivities presentValueSensitivityRates( ResolvedIborFutureTrade trade, RatesProvider ratesProvider, HullWhiteOneFactorPiecewiseConstantParametersProvider hwProvider) { ResolvedIborFuture product = trade.getProduct(); PointSensitivities priceSensi = productPricer.priceSensitivityRates(product, ratesProvider, hwProvider); PointSensitivities marginIndexSensi = productPricer.marginIndexSensitivity(product, priceSensi); return marginIndexSensi.multipliedBy(trade.getQuantity()); }
@Override protected Object propertyGet(Bean bean, String propertyName, boolean quiet) { switch (propertyName.hashCode()) { case 3237038: // info return ((ResolvedIborFutureTrade) bean).getInfo(); case -309474065: // product return ((ResolvedIborFutureTrade) bean).getProduct(); case -1285004149: // quantity return ((ResolvedIborFutureTrade) bean).getQuantity(); case -1873824343: // tradedPrice return ((ResolvedIborFutureTrade) bean).tradedPrice; } return super.propertyGet(bean, propertyName, quiet); }
/** * Calculates the par spread sensitivity of the Ibor future trade. * <p> * The par spread sensitivity of the trade is the sensitivity of the par spread to * the underlying curves. * * @param trade the trade * @param ratesProvider the rates provider * @return the par spread curve sensitivity of the trade */ public PointSensitivities parSpreadSensitivity(ResolvedIborFutureTrade trade, RatesProvider ratesProvider) { return productPricer.priceSensitivity(trade.getProduct(), ratesProvider); }
public void test_reference_price_on_trade_date() { LocalDate tradeDate = FUTURE_TRADE.getTradedPrice().get().getTradeDate(); LocalDate valuationDate = tradeDate; double settlementPrice = 0.995; double referencePrice = PRICER_TRADE.referencePrice(FUTURE_TRADE, valuationDate, settlementPrice); assertEquals(referencePrice, FUTURE_TRADE.getTradedPrice().get().getPrice()); }
static ResolvedIborFutureTrade sut2() { return ResolvedIborFutureTrade.builder() .info(TRADE_INFO2) .product(PRODUCT2) .quantity(QUANTITY2) .tradedPrice(TradedPrice.of(TRADE_DATE, PRICE2)) .build(); }
@Override public ResolvedIborFutureTrade resolve(ReferenceData refData) { ResolvedIborFuture resolved = product.resolve(refData); return new ResolvedIborFutureTrade(info, resolved, getQuantity(), null); }