/** * Calculates the present value sensitivity of the Overnight rate 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(ResolvedOvernightFutureTrade trade, RatesProvider ratesProvider) { ResolvedOvernightFuture 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(ResolvedOvernightFutureTrade beanToCopy) { this.info = beanToCopy.getInfo(); this.product = beanToCopy.getProduct(); this.quantity = beanToCopy.getQuantity(); this.tradedPrice = beanToCopy.tradedPrice; }
@Override public ResolvedOvernightFutureTrade build() { return new ResolvedOvernightFutureTrade( info, product, quantity, tradedPrice); }
public void test_builder() { ResolvedOvernightFutureTrade test = ResolvedOvernightFutureTrade.builder() .info(TRADE_INFO) .product(PRODUCT) .quantity(QUANTITY) .tradedPrice(TradedPrice.of(TRADE_DATE, PRICE)) .build(); 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() { double lastClosingPrice = 1.005; double expected = (PRICER_PRODUCT.price(RESOLVED_TRADE.getProduct(), RATES_PROVIDER_ON) - RESOLVED_TRADE.getTradedPrice().get().getPrice()) * FUTURE.getAccrualFactor() * FUTURE.getNotional() * RESOLVED_TRADE.getQuantity(); CurrencyAmount computed = PRICER_TRADE.presentValue(RESOLVED_TRADE, RATES_PROVIDER_ON, lastClosingPrice); assertEquals(computed.getAmount(), expected, TOLERANCE_PV); assertEquals(computed.getCurrency(), FUTURE.getCurrency()); }
/** * Calculates the price sensitivity of the Overnight rate 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(ResolvedOvernightFutureTrade 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 */ double referencePrice(ResolvedOvernightFutureTrade 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_serialization() { ResolvedOvernightFutureTrade test = ResolvedOvernightFutureTrade.builder() .info(TRADE_INFO) .product(PRODUCT) .quantity(QUANTITY) .tradedPrice(TradedPrice.of(TRADE_DATE, PRICE)) .build(); assertSerialization(test); }
public void test_resolve() { OvernightFutureTrade test = OvernightFutureTrade.builder() .info(TRADE_INFO) .product(PRODUCT) .quantity(QUANTITY) .price(PRICE) .build(); ResolvedOvernightFutureTrade 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))); }
/** * Calculates the par spread sensitivity of the Overnight rate 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(ResolvedOvernightFutureTrade trade, RatesProvider ratesProvider) { return productPricer.priceSensitivity(trade.getProduct(), ratesProvider); }
public void test_reference_price_on_trade_date() { LocalDate tradeDate = RESOLVED_TRADE.getTradedPrice().get().getTradeDate(); LocalDate valuationDate = tradeDate; double settlementPrice = 0.995; double referencePrice = PRICER_TRADE.referencePrice(RESOLVED_TRADE, valuationDate, settlementPrice); assertEquals(referencePrice, RESOLVED_TRADE.getTradedPrice().get().getPrice()); }
public void test_resolve() { OvernightFuturePosition base = OvernightFuturePosition.builder() .info(POSITION_INFO) .product(PRODUCT) .longQuantity(QUANTITY) .build(); ResolvedOvernightFutureTrade expected = ResolvedOvernightFutureTrade.builder() .info(POSITION_INFO) .product(PRODUCT.resolve(REF_DATA)) .quantity(QUANTITY) .build(); assertEquals(base.resolve(REF_DATA), expected); }
/** * Calculates the present value of the Overnight rate future trade from the current price. * <p> * The present value of the product is the value on the valuation date. * <p> * The calculation is performed against a reference price. The reference price * must be the last settlement price used for margining, except on the trade date, * when it must be the trade price. * * @param trade the trade * @param currentPrice the current price, in decimal form * @param referencePrice the reference price to margin against, typically the last settlement price, in decimal form * @return the present value */ CurrencyAmount presentValue(ResolvedOvernightFutureTrade trade, double currentPrice, double referencePrice) { ResolvedOvernightFuture future = trade.getProduct(); double priceIndex = productPricer.marginIndex(future, currentPrice); double referenceIndex = productPricer.marginIndex(future, referencePrice); double pv = (priceIndex - referenceIndex) * trade.getQuantity(); return CurrencyAmount.of(future.getCurrency(), pv); }
@Override protected Object propertyGet(Bean bean, String propertyName, boolean quiet) { switch (propertyName.hashCode()) { case 3237038: // info return ((ResolvedOvernightFutureTrade) bean).getInfo(); case -309474065: // product return ((ResolvedOvernightFutureTrade) bean).getProduct(); case -1285004149: // quantity return ((ResolvedOvernightFutureTrade) bean).getQuantity(); case -1873824343: // tradedPrice return ((ResolvedOvernightFutureTrade) bean).tradedPrice; } return super.propertyGet(bean, propertyName, quiet); }
/** * Calculates the price of the Overnight rate 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(ResolvedOvernightFutureTrade trade, RatesProvider ratesProvider) { return productPricer.price(trade.getProduct(), ratesProvider); }
public void test_parSpread_on_trade_date() { double lastClosingPrice = 0.99; double parSpreadExpected = PRICER_TRADE.price( RESOLVED_TRADE, RATES_PROVIDER_ON) - RESOLVED_TRADE.getTradedPrice().get().getPrice(); double parSpreadComputed = PRICER_TRADE.parSpread(RESOLVED_TRADE, RATES_PROVIDER_ON, lastClosingPrice); assertEquals(parSpreadComputed, parSpreadExpected, TOLERANCE_PRICE); }
public void coverage() { ResolvedOvernightFutureTrade test1 = ResolvedOvernightFutureTrade.builder() .info(TRADE_INFO) .product(PRODUCT) .quantity(QUANTITY) .tradedPrice(TradedPrice.of(TRADE_DATE, PRICE)) .build(); coverImmutableBean(test1); ResolvedOvernightFutureTrade test2 = ResolvedOvernightFutureTrade.builder() .info(TradeInfo.empty()) .product(PRODUCT2) .quantity(QUANTITY2) .tradedPrice(TradedPrice.of(TRADE_DATE, PRICE2)) .build(); coverBeanEquals(test1, test2); }
@Override public ResolvedOvernightFutureTrade resolve(ReferenceData refData) { ResolvedOvernightFuture resolved = product.resolve(refData); return new ResolvedOvernightFutureTrade(info, resolved, getQuantity(), null); }
public void test_presentValue() { double currentPrice = 0.995; double referencePrice = 0.9925; double currentPriceIndex = PRICER_PRODUCT.marginIndex(RESOLVED_TRADE.getProduct(), currentPrice); double referencePriceIndex = PRICER_PRODUCT.marginIndex(RESOLVED_TRADE.getProduct(), referencePrice); double presentValueExpected = (currentPriceIndex - referencePriceIndex) * RESOLVED_TRADE.getQuantity(); CurrencyAmount presentValueComputed = PRICER_TRADE.presentValue(RESOLVED_TRADE, currentPrice, referencePrice); assertEquals(presentValueComputed.getAmount(), presentValueExpected, TOLERANCE_PV); }
public void test_price() { double computed = PRICER_TRADE.price(RESOLVED_TRADE, RATES_PROVIDER); double expected = PRICER_PRODUCT.price(RESOLVED_TRADE.getProduct(), RATES_PROVIDER); assertEquals(computed, expected, TOL); }