static ResolvedBill sut2() { return BillTest.BILL_2.resolve(REF_DATA); }
static ResolvedBill sut() { return BillTest.US_BILL.resolve(REF_DATA); }
@Override public ResolvedBillTrade resolve(ReferenceData refData) { ResolvedBill resolved = product.resolve(refData); return new ResolvedBillTrade(info, resolved, getQuantity(), null); }
public void test_resolve() { ResolvedBill resolved = US_BILL.resolve(REF_DATA); assertEquals(resolved.getDayCount(), DAY_COUNT); assertEquals(resolved.getLegalEntityId(), LEGAL_ENTITY); assertEquals(resolved.getNotional(), NOTIONAL.resolve(REF_DATA)); assertEquals(resolved.getSecurityId(), SECURITY_ID); assertEquals(resolved.getSettlementDateOffset(), SETTLE); assertEquals(resolved.getYieldConvention(), YIELD_CONVENTION); }
public void test_presentValue_settle_before_val() { CurrencyAmount pvComputed = PRICER_TRADE.presentValue(BILL_TRADE_SETTLE_BEFORE_VAL, PROVIDER); CurrencyAmount pvExpected = PRICER_PRODUCT.presentValue(BILL_PRODUCT.resolve(REF_DATA), PROVIDER) .multipliedBy(QUANTITY); assertEquals(pvComputed.getCurrency(), EUR); assertEquals(pvComputed.getAmount(), pvExpected.getAmount(), TOLERANCE_PV); MultiCurrencyAmount ceComputed = PRICER_TRADE.currencyExposure(BILL_TRADE_SETTLE_BEFORE_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_BEFORE_VAL, VAL_DATE); assertEquals(cashComputed.getCurrency(), EUR); assertEquals(cashComputed.getAmount(), 0, TOLERANCE_PV); }
public void test_pvsensi_settle_before_val() { PointSensitivities pvsensiComputed = PRICER_TRADE.presentValueSensitivity(BILL_TRADE_SETTLE_BEFORE_VAL, PROVIDER); PointSensitivities pvsensiExpected = PRICER_PRODUCT.presentValueSensitivity(BILL_PRODUCT.resolve(REF_DATA), PROVIDER) .multipliedBy(QUANTITY); assertTrue(pvsensiComputed.equalWithTolerance(pvsensiExpected, TOLERANCE_PVSENSI)); CurrencyParameterSensitivities paramSensiComputed = PROVIDER.parameterSensitivity(pvsensiComputed); CurrencyParameterSensitivities paramSensiExpected = FD_CALC.sensitivity( PROVIDER, p -> PRICER_TRADE.presentValue(BILL_TRADE_SETTLE_BEFORE_VAL, p)); assertTrue(paramSensiComputed.equalWithTolerance(paramSensiExpected, EPS * NOTIONAL_AMOUNT * QUANTITY)); }
public void test_presentValueZSpread_settle_before_val() { CurrencyAmount pvComputed = PRICER_TRADE .presentValueWithZSpread(BILL_TRADE_SETTLE_BEFORE_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); assertEquals(pvComputed.getCurrency(), EUR); assertEquals(pvComputed.getAmount(), pvExpected.getAmount(), TOLERANCE_PV); MultiCurrencyAmount ceComputed = PRICER_TRADE .currencyExposureWithZSpread(BILL_TRADE_SETTLE_BEFORE_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); }
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() { 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_presentValue_settle_on_val() { CurrencyAmount pvComputed = PRICER_TRADE.presentValue(BILL_TRADE_SETTLE_ON_VAL, PROVIDER); CurrencyAmount pvExpected = PRICER_PRODUCT.presentValue(BILL_PRODUCT.resolve(REF_DATA), PROVIDER) .plus(-PRICE * NOTIONAL_AMOUNT) .multipliedBy(QUANTITY); assertEquals(pvComputed.getCurrency(), EUR); assertEquals(pvComputed.getAmount(), pvExpected.getAmount(), TOLERANCE_PV); MultiCurrencyAmount ceComputed = PRICER_TRADE.currencyExposure(BILL_TRADE_SETTLE_ON_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_ON_VAL, VAL_DATE); assertEquals(cashComputed.getCurrency(), EUR); assertEquals(cashComputed.getAmount(), -PRICE * NOTIONAL_AMOUNT * QUANTITY, TOLERANCE_PV); }
public void test_presentValueZSpread_settle_on_val() { CurrencyAmount pvComputed = PRICER_TRADE .presentValueWithZSpread(BILL_TRADE_SETTLE_ON_VAL, PROVIDER, Z_SPREAD, CompoundedRateType.CONTINUOUS, 0); CurrencyAmount pvExpected = PRICER_PRODUCT .presentValueWithZSpread(BILL_PRODUCT.resolve(REF_DATA), PROVIDER, Z_SPREAD, CompoundedRateType.CONTINUOUS, 0) .plus(-PRICE * NOTIONAL_AMOUNT) .multipliedBy(QUANTITY); assertEquals(pvComputed.getCurrency(), EUR); assertEquals(pvComputed.getAmount(), pvExpected.getAmount(), TOLERANCE_PV); MultiCurrencyAmount ceComputed = PRICER_TRADE .currencyExposureWithZSpread(BILL_TRADE_SETTLE_ON_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); }
public void test_pvsensiZSpread_settle_before_val() { PointSensitivities pvsensiComputed = PRICER_TRADE .presentValueSensitivityWithZSpread(BILL_TRADE_SETTLE_BEFORE_VAL, PROVIDER, Z_SPREAD, CompoundedRateType.CONTINUOUS, 0); PointSensitivities pvsensiExpected = PRICER_PRODUCT .presentValueSensitivityWithZSpread(BILL_PRODUCT.resolve(REF_DATA), PROVIDER, Z_SPREAD, CompoundedRateType.CONTINUOUS, 0) .multipliedBy(QUANTITY); assertTrue(pvsensiComputed.equalWithTolerance(pvsensiExpected, TOLERANCE_PVSENSI)); CurrencyParameterSensitivities paramSensiComputed = PROVIDER.parameterSensitivity(pvsensiComputed); CurrencyParameterSensitivities paramSensiExpected = FD_CALC.sensitivity( PROVIDER, p -> PRICER_TRADE.presentValueWithZSpread(BILL_TRADE_SETTLE_BEFORE_VAL, p, Z_SPREAD, CompoundedRateType.CONTINUOUS, 0)); assertTrue(paramSensiComputed.equalWithTolerance(paramSensiExpected, EPS * NOTIONAL_AMOUNT * QUANTITY)); }
@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 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_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); }
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 test_resolve() { BillPosition base = BillPosition.builder() .info(POSITION_INFO1) .product(PRODUCT1) .longQuantity(QUANTITY1) .build(); ResolvedBillTrade computed = base.resolve(REF_DATA); ResolvedBillTrade expected = ResolvedBillTrade.builder() .info(POSITION_INFO1) .product(PRODUCT1.resolve(REF_DATA)) .quantity(QUANTITY1) .build(); assertEquals(computed, expected); }
public void test_pvsensi_settle_on_val() { PointSensitivities pvsensiComputed = PRICER_TRADE.presentValueSensitivity(BILL_TRADE_SETTLE_ON_VAL, PROVIDER); PointSensitivities pvsensiExpected = PRICER_PRODUCT.presentValueSensitivity(BILL_PRODUCT.resolve(REF_DATA), PROVIDER) .multipliedBy(QUANTITY) .combinedWith(RepoCurveZeroRateSensitivity.of( (ZeroRateSensitivity) PRICER_PAYMENT.presentValueSensitivity( BILL_TRADE_SETTLE_ON_VAL.getSettlement().get(), PROVIDER.repoCurveDiscountFactors( BILL_PRODUCT.getSecurityId(), BILL_PRODUCT.getLegalEntityId(), BILL_PRODUCT.getCurrency()) .getDiscountFactors()), GROUP_REPO).build()); assertTrue(pvsensiComputed.equalWithTolerance(pvsensiExpected, TOLERANCE_PVSENSI)); CurrencyParameterSensitivities paramSensiComputed = PROVIDER.parameterSensitivity(pvsensiComputed); CurrencyParameterSensitivities paramSensiExpected = FD_CALC.sensitivity( PROVIDER, p -> PRICER_TRADE.presentValue(BILL_TRADE_SETTLE_ON_VAL, p)); assertTrue(paramSensiComputed.equalWithTolerance(paramSensiExpected, EPS * NOTIONAL_AMOUNT * QUANTITY)); }
public void test_pvsensi_settle_after_val() { PointSensitivities pvsensiComputed = PRICER_TRADE.presentValueSensitivity(BILL_TRADE_SETTLE_AFTER_VAL, PROVIDER); PointSensitivities pvsensiExpected = PRICER_PRODUCT.presentValueSensitivity(BILL_PRODUCT.resolve(REF_DATA), PROVIDER) .multipliedBy(QUANTITY) .combinedWith(RepoCurveZeroRateSensitivity.of( (ZeroRateSensitivity) PRICER_PAYMENT.presentValueSensitivity( BILL_TRADE_SETTLE_AFTER_VAL.getSettlement().get(), PROVIDER.repoCurveDiscountFactors( BILL_PRODUCT.getSecurityId(), BILL_PRODUCT.getLegalEntityId(), BILL_PRODUCT.getCurrency()) .getDiscountFactors()), GROUP_REPO).build()); assertTrue(pvsensiComputed.equalWithTolerance(pvsensiExpected, TOLERANCE_PVSENSI)); CurrencyParameterSensitivities paramSensiComputed = PROVIDER.parameterSensitivity(pvsensiComputed); CurrencyParameterSensitivities paramSensiExpected = FD_CALC.sensitivity( PROVIDER, p -> PRICER_TRADE.presentValue(BILL_TRADE_SETTLE_AFTER_VAL, p)); assertTrue(paramSensiComputed.equalWithTolerance(paramSensiExpected, EPS * NOTIONAL_AMOUNT * QUANTITY)); }
public void test_pvsensiZSpread_settle_after_val() { PointSensitivities pvsensiComputed = PRICER_TRADE .presentValueSensitivityWithZSpread(BILL_TRADE_SETTLE_AFTER_VAL, PROVIDER, Z_SPREAD, CompoundedRateType.CONTINUOUS, 0); PointSensitivities pvsensiExpected = PRICER_PRODUCT .presentValueSensitivityWithZSpread(BILL_PRODUCT.resolve(REF_DATA), PROVIDER, Z_SPREAD, CompoundedRateType.CONTINUOUS, 0) .multipliedBy(QUANTITY) .combinedWith(RepoCurveZeroRateSensitivity.of( (ZeroRateSensitivity) PRICER_PAYMENT.presentValueSensitivity( BILL_TRADE_SETTLE_AFTER_VAL.getSettlement().get(), PROVIDER.repoCurveDiscountFactors( BILL_PRODUCT.getSecurityId(), BILL_PRODUCT.getLegalEntityId(), BILL_PRODUCT.getCurrency()) .getDiscountFactors()), GROUP_REPO).build()); assertTrue(pvsensiComputed.equalWithTolerance(pvsensiExpected, TOLERANCE_PVSENSI)); CurrencyParameterSensitivities paramSensiComputed = PROVIDER.parameterSensitivity(pvsensiComputed); CurrencyParameterSensitivities paramSensiExpected = FD_CALC.sensitivity( PROVIDER, p -> PRICER_TRADE.presentValueWithZSpread(BILL_TRADE_SETTLE_AFTER_VAL, p, Z_SPREAD, CompoundedRateType.CONTINUOUS, 0)); assertTrue(paramSensiComputed.equalWithTolerance(paramSensiExpected, EPS * NOTIONAL_AMOUNT * QUANTITY)); }