public void test_builder() { assertEquals(US_BILL.getCurrency(), CCY); assertEquals(US_BILL.getDayCount(), DAY_COUNT); assertEquals(US_BILL.getLegalEntityId(), LEGAL_ENTITY); assertEquals(US_BILL.getNotional(), NOTIONAL); assertEquals(US_BILL.getSecurityId(), SECURITY_ID); assertEquals(US_BILL.getSettlementDateOffset(), SETTLE); assertEquals(US_BILL.getYieldConvention(), YIELD_CONVENTION); }
static ResolvedBill sut2() { return BillTest.BILL_2.resolve(REF_DATA); }
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); }
/** * Restricted copy constructor. * @param beanToCopy the bean to copy from, not null */ private Builder(Bill beanToCopy) { this.securityId = beanToCopy.getSecurityId(); this.notional = beanToCopy.getNotional(); this.dayCount = beanToCopy.getDayCount(); this.yieldConvention = beanToCopy.getYieldConvention(); this.legalEntityId = beanToCopy.getLegalEntityId(); this.settlementDateOffset = beanToCopy.getSettlementDateOffset(); }
public void yield_from_price_discount() { double price = 0.99; LocalDate settlementDate = LocalDate.of(2018, 8, 17); double af = US_BILL.getDayCount().relativeYearFraction(settlementDate, MATURITY_DATE); double yieldExpected = (1.0d - price) / af; double yieldComputed = US_BILL.yieldFromPrice(price, settlementDate); assertEquals(yieldExpected, yieldComputed, TOLERANCE_PRICE); }
public void test_presentValueZSpread_settle_after_val() { CurrencyAmount pvComputed = PRICER_TRADE .presentValueWithZSpread(BILL_TRADE_SETTLE_AFTER_VAL, PROVIDER, Z_SPREAD, CompoundedRateType.CONTINUOUS, 0); CurrencyAmount pvExpected = PRICER_PRODUCT .presentValueWithZSpread(BILL_PRODUCT.resolve(REF_DATA), PROVIDER, Z_SPREAD, CompoundedRateType.CONTINUOUS, 0) .multipliedBy(QUANTITY) .plus(PRICER_PAYMENT.presentValue(BILL_TRADE_SETTLE_AFTER_VAL.getSettlement().get(), PROVIDER.repoCurveDiscountFactors(BILL_PRODUCT.getSecurityId(), BILL_PRODUCT.getLegalEntityId(), BILL_PRODUCT.getCurrency()) .getDiscountFactors())); assertEquals(pvComputed.getCurrency(), EUR); assertEquals(pvComputed.getAmount(), pvExpected.getAmount(), TOLERANCE_PV); MultiCurrencyAmount ceComputed = PRICER_TRADE .currencyExposureWithZSpread(BILL_TRADE_SETTLE_AFTER_VAL, PROVIDER, Z_SPREAD, CompoundedRateType.CONTINUOUS, 0); assertEquals(ceComputed.getCurrencies().size(), 1); assertTrue(ceComputed.contains(EUR)); assertEquals(ceComputed.getAmount(EUR).getAmount(), pvExpected.getAmount(), TOLERANCE_PV); }
@Override public ResolvedBillTrade resolve(ReferenceData refData) { ResolvedBill resolvedProduct = product.resolve(refData); CurrencyAmount settleAmount = product.getNotional().getValue().multipliedBy(-price * quantity); LocalDate settlementDate = calculateSettlementDate(refData); Payment settlement = Payment.of(settleAmount, settlementDate); return ResolvedBillTrade.builder() .info(info) .product(resolvedProduct) .quantity(quantity) .settlement(settlement).build(); }
public void yield_from_price_intatmat() { ResolvedBill bill = BillTest.US_BILL .toBuilder().yieldConvention(BillYieldConvention.INTEREST_AT_MATURITY).build().resolve(REF_DATA); double price = 0.99; LocalDate settlementDate = LocalDate.of(2018, 8, 17); double af = bill.getDayCount().relativeYearFraction(settlementDate, bill.getNotional().getDate()); double yieldExpected = (1.0d / price - 1.0d) / af; double yieldComputed = bill.yieldFromPrice(price, settlementDate); assertEquals(yieldExpected, yieldComputed, TOLERANCE_PRICE); }
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); }
public void yield_from_price_intatmat() { Bill bill = US_BILL.toBuilder().yieldConvention(BillYieldConvention.INTEREST_AT_MATURITY).build(); double price = 0.99; LocalDate settlementDate = LocalDate.of(2018, 8, 17); double af = bill.getDayCount().relativeYearFraction(settlementDate, MATURITY_DATE); double yieldExpected = (1.0d / price - 1.0d) / af; double yieldComputed = bill.yieldFromPrice(price, settlementDate); assertEquals(yieldExpected, yieldComputed, TOLERANCE_PRICE); }
@Override public SecurityId getSecurityId() { return product.getSecurityId(); }
public void test_ofYield() { BillTrade test = sut_yield(); assertEquals(test.getProduct(), PRODUCT); assertEquals(test.getInfo(), TRADE_INFO); assertEquals(test.getQuantity(), QUANTITY); double price = 1.0d - YIELD * PRODUCT.getDayCount().relativeYearFraction(SETTLEMENT_DATE, PRODUCT.getNotional().getDate().getUnadjusted()); assertEquals(test.getPrice(), price, TOLERANCE_PRICE); assertEquals(test.withInfo(TRADE_INFO).getInfo(), TRADE_INFO); assertEquals(test.withQuantity(129).getQuantity(), 129d, 0d); assertEquals(test.withPrice(129).getPrice(), 129d, 0d); }
@Override public Currency getCurrency() { return product.getCurrency(); }
private LocalDate calculateSettlementDate(ReferenceData refData) { if (info.getSettlementDate().isPresent()) { return info.getSettlementDate().get(); } LocalDate tradeDate = info.getTradeDate().get(); return product.getSettlementDateOffset().adjust(tradeDate, refData); }
/** * 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 test_presentValue_settle_after_val() { CurrencyAmount pvComputed = PRICER_TRADE.presentValue(BILL_TRADE_SETTLE_AFTER_VAL, PROVIDER); CurrencyAmount pvExpected = PRICER_PRODUCT.presentValue(BILL_PRODUCT.resolve(REF_DATA), PROVIDER) .multipliedBy(QUANTITY) .plus(PRICER_PAYMENT.presentValue(BILL_TRADE_SETTLE_AFTER_VAL.getSettlement().get(), PROVIDER.repoCurveDiscountFactors(BILL_PRODUCT.getSecurityId(), BILL_PRODUCT.getLegalEntityId(), BILL_PRODUCT.getCurrency()) .getDiscountFactors())); assertEquals(pvComputed.getCurrency(), EUR); assertEquals(pvComputed.getAmount(), pvExpected.getAmount(), TOLERANCE_PV); MultiCurrencyAmount ceComputed = PRICER_TRADE.currencyExposure(BILL_TRADE_SETTLE_AFTER_VAL, PROVIDER); assertEquals(ceComputed.getCurrencies().size(), 1); assertTrue(ceComputed.contains(EUR)); assertEquals(ceComputed.getAmount(EUR).getAmount(), pvExpected.getAmount(), TOLERANCE_PV); CurrencyAmount cashComputed = PRICER_TRADE.currentCash(BILL_TRADE_SETTLE_AFTER_VAL, VAL_DATE); assertEquals(cashComputed.getCurrency(), EUR); assertEquals(cashComputed.getAmount(), 0, TOLERANCE_PV); }
public void test_resolve() { Payment settle = Payment .of(PRODUCT.getNotional().getValue().multipliedBy(-PRICE * QUANTITY), SETTLEMENT_DATE); ResolvedBillTrade expected = ResolvedBillTrade.builder() .info(TRADE_INFO) .product(PRODUCT.resolve(REF_DATA)) .quantity(QUANTITY) .settlement(settle) .build(); assertEquals(sut_price().resolve(REF_DATA), expected); }
public void price_from_yield_intatmat() { ResolvedBill bill = BillTest.US_BILL .toBuilder().yieldConvention(BillYieldConvention.INTEREST_AT_MATURITY).build().resolve(REF_DATA); double yield = 0.01; LocalDate settlementDate = LocalDate.of(2018, 8, 17); double af = bill.getDayCount().relativeYearFraction(settlementDate, bill.getNotional().getDate()); double priceExpected = 1.0d / (1 + yield * af); double priceComputed = bill.priceFromYield(yield, settlementDate); assertEquals(priceExpected, priceComputed, TOLERANCE_PRICE); }
public void test_builder_of() { BillPosition test = BillPosition.builder() .info(POSITION_INFO1) .product(PRODUCT1) .longQuantity(QUANTITY1) .shortQuantity(QUANTITY2) .build(); assertEquals(test.getCurrency(), USD); assertEquals(test.getId(), POSITION_INFO1.getId()); assertEquals(test.getInfo(), POSITION_INFO1); assertEquals(test.getLongQuantity(), QUANTITY1); assertEquals(test.getShortQuantity(), QUANTITY2); assertEquals(test.getProduct(), PRODUCT1); assertEquals(test.getQuantity(), QUANTITY1 - QUANTITY2); assertEquals(test.getSecurityId(), PRODUCT1.getSecurityId()); BillPosition test1 = BillPosition.ofLongShort(POSITION_INFO1, PRODUCT1, QUANTITY1, QUANTITY2); assertEquals(test, test1); }
@Override protected Object propertyGet(Bean bean, String propertyName, boolean quiet) { switch (propertyName.hashCode()) { case 1574023291: // securityId return ((Bill) bean).getSecurityId(); case 1585636160: // notional return ((Bill) bean).getNotional(); case 1905311443: // dayCount return ((Bill) bean).getDayCount(); case -1895216418: // yieldConvention return ((Bill) bean).getYieldConvention(); case 866287159: // legalEntityId return ((Bill) bean).getLegalEntityId(); case 135924714: // settlementDateOffset return ((Bill) bean).getSettlementDateOffset(); } return super.propertyGet(bean, propertyName, quiet); }