/** * Restricted copy constructor. * @param beanToCopy the bean to copy from, not null */ private Builder(ResolvedBondFutureTrade beanToCopy) { this.info = beanToCopy.getInfo(); this.product = beanToCopy.getProduct(); this.quantity = beanToCopy.getQuantity(); this.tradedPrice = beanToCopy.tradedPrice; }
@Override public ResolvedBondFutureTrade build() { return new ResolvedBondFutureTrade( info, product, quantity, tradedPrice); }
/** * Calculates the present value sensitivity of the bond 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 discountingProvider the discounting provider * @return the present value curve sensitivity of the trade */ public PointSensitivities presentValueSensitivity( ResolvedBondFutureTrade trade, LegalEntityDiscountingProvider discountingProvider) { ResolvedBondFuture product = trade.getProduct(); PointSensitivities priceSensi = productPricer.priceSensitivity(product, discountingProvider); PointSensitivities marginIndexSensi = productPricer.marginIndexSensitivity(product, priceSensi); return marginIndexSensi.multipliedBy(trade.getQuantity()); }
/** * Calculates the par spread sensitivity of the bond 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 discountingProvider the discounting provider * @return the par spread curve sensitivity of the trade */ public PointSensitivities parSpreadSensitivity( ResolvedBondFutureTrade trade, LegalEntityDiscountingProvider discountingProvider) { return productPricer.priceSensitivity(trade.getProduct(), discountingProvider); }
/** * 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(ResolvedBondFutureTrade 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_resolve() { ResolvedBondFutureTrade expected = ResolvedBondFutureTrade.builder() .info(POSITION_INFO) .product(PRODUCT.resolve(REF_DATA)) .quantity(QUANTITY) .build(); assertEquals(sut().resolve(REF_DATA), expected); }
/** * Calculates the present value sensitivity of the bond future trade with z-spread. * <p> * The present value sensitivity of the trade is the sensitivity of the present value to * the underlying curves. * <p> * The z-spread is a parallel shift applied to continuously compounded rates or periodic compounded rates * of the issuer discounting curve. * * @param trade the trade * @param discountingProvider the discounting provider * @param zSpread the z-spread * @param compoundedRateType the compounded rate type * @param periodPerYear the number of periods per year * @return the present value curve sensitivity of the trade */ public PointSensitivities presentValueSensitivityWithZSpread( ResolvedBondFutureTrade trade, LegalEntityDiscountingProvider discountingProvider, double zSpread, CompoundedRateType compoundedRateType, int periodPerYear) { ResolvedBondFuture product = trade.getProduct(); PointSensitivities priceSensi = productPricer.priceSensitivityWithZSpread(product, discountingProvider, zSpread, compoundedRateType, periodPerYear); PointSensitivities marginIndexSensi = productPricer.marginIndexSensitivity(product, priceSensi); return marginIndexSensi.multipliedBy(trade.getQuantity()); }
/** * Calculates the price of the bond future trade. * <p> * The price of the trade is the price on the valuation date. * <p> * Strata uses <i>decimal prices</i> for bond futures. This is coherent with the pricing of {@link FixedCouponBond}. * For example, a price of 99.32% is represented in Strata by 0.9932. * * @param trade the trade * @param discountingProvider the discounting provider * @return the price of the trade, in decimal form */ public double price(ResolvedBondFutureTrade trade, LegalEntityDiscountingProvider discountingProvider) { return productPricer.price(trade.getProduct(), discountingProvider); }
public void test_getters() { ResolvedBondFutureTrade test = sut(); BondFutureTrade base = BondFutureTradeTest.sut(); assertEquals(test.getTradedPrice().get(), TradedPrice.of(base.getInfo().getTradeDate().get(), base.getPrice())); }
public void test_resolve() { ResolvedBondFutureTrade expected = ResolvedBondFutureTrade.builder() .info(TRADE_INFO) .product(FUTURE.resolve(REF_DATA)) .quantity(QUANTITY) .tradedPrice(TradedPrice.of(TRADE_INFO.getTradeDate().get(), PRICE)) .build(); assertEquals(sut().resolve(REF_DATA), expected); }
@Override protected Object propertyGet(Bean bean, String propertyName, boolean quiet) { switch (propertyName.hashCode()) { case 3237038: // info return ((ResolvedBondFutureTrade) bean).getInfo(); case -309474065: // product return ((ResolvedBondFutureTrade) bean).getProduct(); case -1285004149: // quantity return ((ResolvedBondFutureTrade) bean).getQuantity(); case -1873824343: // tradedPrice return ((ResolvedBondFutureTrade) bean).tradedPrice; } return super.propertyGet(bean, propertyName, quiet); }
/** * Calculates the present value of the bond 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 price on the valuation date * @param referencePrice the price with respect to which the margining should be done * @return the present value */ CurrencyAmount presentValue(ResolvedBondFutureTrade trade, double currentPrice, double referencePrice) { ResolvedBondFuture 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); }
/** * Calculates the price of the bond future trade with z-spread. * <p> * The price of the trade is the price on the valuation date. * <p> * The z-spread is a parallel shift applied to continuously compounded rates or periodic compounded rates * of the issuer discounting curve. * * @param trade the trade * @param discountingProvider the discounting provider * @param zSpread the z-spread * @param compoundedRateType the compounded rate type * @param periodPerYear the number of periods per year * @return the price of the trade, in decimal form */ public double priceWithZSpread( ResolvedBondFutureTrade trade, LegalEntityDiscountingProvider discountingProvider, double zSpread, CompoundedRateType compoundedRateType, int periodPerYear) { return productPricer.priceWithZSpread(trade.getProduct(), discountingProvider, zSpread, compoundedRateType, periodPerYear); }
@Override public ResolvedBondFutureTrade resolve(ReferenceData refData) { ResolvedBondFuture resolved = product.resolve(refData); return new ResolvedBondFutureTrade(info, resolved, getQuantity(), null); }
/** * Calculates the par spread sensitivity of the bond future trade with z-spread. * <p> * The par spread sensitivity of the trade is the sensitivity of the par spread to * the underlying curves. * <p> * The z-spread is a parallel shift applied to continuously compounded rates or periodic compounded rates * of the issuer discounting curve. * * @param trade the trade * @param discountingProvider the discounting provider * @param zSpread the z-spread * @param compoundedRateType the compounded rate type * @param periodPerYear the number of periods per year * @return the par spread curve sensitivity of the trade */ public PointSensitivities parSpreadSensitivityWithZSpread( ResolvedBondFutureTrade trade, LegalEntityDiscountingProvider discountingProvider, double zSpread, CompoundedRateType compoundedRateType, int periodPerYear) { return productPricer.priceSensitivityWithZSpread( trade.getProduct(), discountingProvider, zSpread, compoundedRateType, periodPerYear); }
@Override public ResolvedBondFutureTrade resolve(ReferenceData refData) { if (!info.getTradeDate().isPresent()) { throw new IllegalArgumentException("Trade date on TradeInfo must be present"); } ResolvedBondFuture resolved = getProduct().resolve(refData); TradedPrice tradedPrice = TradedPrice.of(info.getTradeDate().get(), price); return new ResolvedBondFutureTrade(info, resolved, quantity, tradedPrice); }