/** Test present value for ISDA FRA Discounting method. */
  public void test_presentValue_AFMA() {
    ExpandedFra fraExp = FRA_AFMA.expand();
    SimpleRatesProvider prov = createProvider(fraExp);

    DiscountingFraProductPricer test = DiscountingFraProductPricer.DEFAULT;
    CurrencyAmount pvComputed = test.presentValue(fraExp, prov);
    CurrencyAmount pvExpected = test.forecastValue(fraExp, prov).multipliedBy(DISCOUNT_FACTOR);
    assertEquals(pvComputed.getAmount(), pvExpected.getAmount(), TOLERANCE);
  }
 private void assertPresentValue(ImmutableRatesProvider result) {
   // Test PV USD;
   List<Trade> usdTrades = new ArrayList<>();
   for (int i = 0; i < USD_DSC_NODES.length; i++) {
     usdTrades.add(USD_DSC_NODES[i].trade(VAL_DATE, ALL_QUOTES));
   }
   // Depo
   for (int i = 0; i < USD_DSC_NB_DEPO_NODES; i++) {
     CurrencyAmount pvDep =
         DEPO_PRICER.presentValue(((TermDepositTrade) usdTrades.get(i)).getProduct(), result);
     assertEquals(pvDep.getAmount(), 0.0, TOLERANCE_PV);
   }
   // OIS
   for (int i = 0; i < USD_DSC_NB_OIS_NODES; i++) {
     MultiCurrencyAmount pvOis =
         SWAP_PRICER.presentValue(
             ((SwapTrade) usdTrades.get(USD_DSC_NB_DEPO_NODES + i)).getProduct(), result);
     assertEquals(pvOis.getAmount(USD).getAmount(), 0.0, TOLERANCE_PV);
   }
   // Test PV EUR;
   List<Trade> eurTrades = new ArrayList<>();
   for (int i = 0; i < EUR_DSC_NODES.length; i++) {
     eurTrades.add(EUR_DSC_NODES[i].trade(VAL_DATE, ALL_QUOTES));
   }
   // Depo
   for (int i = 0; i < EUR_DSC_NB_FX_NODES; i++) {
     MultiCurrencyAmount pvFx =
         FX_PRICER.presentValue(((FxSwapTrade) eurTrades.get(i)).getProduct(), result);
     assertEquals(pvFx.convertedTo(USD, result).getAmount(), 0.0, TOLERANCE_PV);
   }
 }
 // -------------------------------------------------------------------------
 public void test_dirtyPriceFromCurves() {
   double computed = PRICER.dirtyPriceFromCurves(BOND_SECURITY, PROVIDER);
   CurrencyAmount pv = PRICER.presentValue(PRODUCT, PROVIDER);
   LocalDate settlement = DATE_OFFSET.adjust(VAL_DATE);
   double df = DSC_FACTORS_REPO.discountFactor(settlement);
   assertEquals(computed, pv.getAmount() / df / NOTIONAL);
 }
  /** Test explain. */
  public void test_explainPresentValue_ISDA() {
    ExpandedFra fraExp = FRA.expand();
    SimpleRatesProvider prov = createProvider(fraExp);

    DiscountingFraProductPricer test = DiscountingFraProductPricer.DEFAULT;
    CurrencyAmount fvExpected = test.forecastValue(fraExp, prov);
    CurrencyAmount pvExpected = test.presentValue(fraExp, prov);

    ExplainMap explain = test.explainPresentValue(fraExp, prov);
    Currency currency = fraExp.getCurrency();
    int daysBetween = (int) DAYS.between(fraExp.getStartDate(), fraExp.getEndDate());
    assertEquals(explain.get(ExplainKey.ENTRY_TYPE).get(), "FRA");
    assertEquals(explain.get(ExplainKey.PAYMENT_DATE).get(), fraExp.getPaymentDate());
    assertEquals(explain.get(ExplainKey.START_DATE).get(), fraExp.getStartDate());
    assertEquals(explain.get(ExplainKey.END_DATE).get(), fraExp.getEndDate());
    assertEquals(explain.get(ExplainKey.ACCRUAL_YEAR_FRACTION).get(), fraExp.getYearFraction());
    assertEquals(explain.get(ExplainKey.ACCRUAL_DAYS).get(), (Integer) (int) daysBetween);
    assertEquals(explain.get(ExplainKey.PAYMENT_CURRENCY).get(), currency);
    assertEquals(
        explain.get(ExplainKey.NOTIONAL).get().getAmount(), fraExp.getNotional(), TOLERANCE);
    assertEquals(
        explain.get(ExplainKey.TRADE_NOTIONAL).get().getAmount(), fraExp.getNotional(), TOLERANCE);

    assertEquals(explain.get(ExplainKey.OBSERVATIONS).get().size(), 1);
    ExplainMap explainObs = explain.get(ExplainKey.OBSERVATIONS).get().get(0);
    IborRateObservation floatingRate = (IborRateObservation) fraExp.getFloatingRate();
    assertEquals(explainObs.get(ExplainKey.INDEX).get(), floatingRate.getIndex());
    assertEquals(explainObs.get(ExplainKey.FIXING_DATE).get(), floatingRate.getFixingDate());
    assertEquals(explainObs.get(ExplainKey.INDEX_VALUE).get(), FORWARD_RATE, TOLERANCE);
    assertEquals(explain.get(ExplainKey.DISCOUNT_FACTOR).get(), DISCOUNT_FACTOR, TOLERANCE);
    assertEquals(explain.get(ExplainKey.FIXED_RATE).get(), fraExp.getFixedRate(), TOLERANCE);
    assertEquals(explain.get(ExplainKey.PAY_OFF_RATE).get(), FORWARD_RATE, TOLERANCE);
    assertEquals(explain.get(ExplainKey.COMBINED_RATE).get(), FORWARD_RATE, TOLERANCE);
    assertEquals(
        explain.get(ExplainKey.UNIT_AMOUNT).get(),
        fvExpected.getAmount() / fraExp.getNotional(),
        TOLERANCE);
    assertEquals(explain.get(ExplainKey.FORECAST_VALUE).get().getCurrency(), currency);
    assertEquals(
        explain.get(ExplainKey.FORECAST_VALUE).get().getAmount(),
        fvExpected.getAmount(),
        TOLERANCE);
    assertEquals(explain.get(ExplainKey.PRESENT_VALUE).get().getCurrency(), currency);
    assertEquals(
        explain.get(ExplainKey.PRESENT_VALUE).get().getAmount(), pvExpected.getAmount(), TOLERANCE);
  }
  /** Test FRA paying in the past. */
  public void test_presentValue_inPast() {
    ExpandedFra fraExp = FRA.expand().toBuilder().paymentDate(VAL_DATE.minusDays(1)).build();
    SimpleRatesProvider prov = createProvider(fraExp);

    DiscountingFraProductPricer test = DiscountingFraProductPricer.DEFAULT;
    CurrencyAmount computed = test.presentValue(fraExp, prov);
    assertEquals(computed.getAmount(), 0d, TOLERANCE);
  }
 public void test_presentValue_noExcoupon() {
   CurrencyAmount computed = PRICER.presentValue(PRODUCT_NO_EXCOUPON, PROVIDER);
   ExpandedFixedCouponBond expanded = PRODUCT.expand();
   CurrencyAmount expected =
       PRICER_NOMINAL.presentValue(expanded.getNominalPayment(), DSC_FACTORS_ISSUER);
   int size = expanded.getPeriodicPayments().size();
   double pvcCupon = 0d;
   for (int i = 2; i < size; ++i) {
     FixedCouponBondPaymentPeriod payment = expanded.getPeriodicPayments().get(i);
     pvcCupon +=
         PRICER_COUPON.presentValue(
             payment, IssuerCurveDiscountFactors.of(DSC_FACTORS_ISSUER, GROUP_ISSUER));
   }
   expected = expected.plus(pvcCupon);
   assertEquals(computed.getCurrency(), EUR);
   assertEquals(computed.getAmount(), expected.getAmount(), NOTIONAL * TOL);
 }
Пример #7
0
 // -------------------------------------------------------------------------
 @ImmutableValidator
 private void validate() {
   if (rebate != null) {
     ArgChecker.isTrue(rebate.getAmount() > 0d, "rebate must be positive");
     ArgChecker.isTrue(
         underlyingOption.getUnderlying().getCurrencyPair().contains(rebate.getCurrency()),
         "The rebate currency must be one of underlying currency pair");
   }
 }
 public void test_cashFlowEquivalent_pv() {
   Swap swap = Swap.builder().legs(IBOR_LEG, FIXED_LEG).build();
   ExpandedSwapLeg cfe =
       CashFlowEquivalentCalculator.cashFlowEquivalentSwap(swap.expand(), PROVIDER);
   DiscountingSwapLegPricer pricerLeg = DiscountingSwapLegPricer.DEFAULT;
   DiscountingSwapProductPricer pricerSwap = DiscountingSwapProductPricer.DEFAULT;
   CurrencyAmount pvCfe = pricerLeg.presentValue(cfe, PROVIDER);
   MultiCurrencyAmount pvSwap = pricerSwap.presentValue(swap, PROVIDER);
   assertEquals(pvCfe.getAmount(), pvSwap.getAmount(GBP).getAmount(), TOLERANCE_PV);
 }
  /** Test par spread for AFMA FRA Discounting method. */
  public void test_parSpread_AFMA() {
    ExpandedFra fraExp = FRA_AFMA.expand();
    SimpleRatesProvider prov = createProvider(fraExp);

    DiscountingFraProductPricer test = DiscountingFraProductPricer.DEFAULT;
    double parSpread = test.parSpread(fraExp, prov);
    Fra fra = createNewFra(FRA_AFMA, FRA_AFMA.getFixedRate() + parSpread);
    CurrencyAmount pv = test.presentValue(fra, prov);
    assertEquals(pv.getAmount(), 0.0, TOLERANCE);
  }
 public void test_dirtyPriceFromCurvesWithZSpread_periodic() {
   double computed =
       PRICER.dirtyPriceFromCurvesWithZSpread(
           BOND_SECURITY, PROVIDER, Z_SPREAD, PERIODIC, PERIOD_PER_YEAR);
   CurrencyAmount pv =
       PRICER.presentValueWithZSpread(PRODUCT, PROVIDER, Z_SPREAD, PERIODIC, PERIOD_PER_YEAR);
   LocalDate settlement = DATE_OFFSET.adjust(VAL_DATE);
   double df = DSC_FACTORS_REPO.discountFactor(settlement);
   assertEquals(computed, pv.getAmount() / df / NOTIONAL);
 }
  /** Test par rate for NONE FRA Discounting method. */
  public void test_parRate_NONE() {
    ExpandedFra fraExp = FRA_NONE.expand();
    SimpleRatesProvider prov = createProvider(fraExp);

    DiscountingFraProductPricer test = DiscountingFraProductPricer.DEFAULT;
    double parRate = test.parRate(fraExp, prov);
    assertEquals(parRate, FORWARD_RATE);
    Fra fra = createNewFra(FRA_NONE, parRate);
    CurrencyAmount pv = test.presentValue(fra, prov);
    assertEquals(pv.getAmount(), 0.0, TOLERANCE);
  }
  /** Test forecast value for NONE FRA Discounting method. */
  public void test_forecastValue_NONE() {
    ExpandedFra fraExp = FRA_NONE.expand();
    SimpleRatesProvider prov = createProvider(fraExp);

    double fixedRate = FRA_NONE.getFixedRate();
    double yearFraction = fraExp.getYearFraction();
    double notional = fraExp.getNotional();
    double expected = notional * yearFraction * (FORWARD_RATE - fixedRate);

    DiscountingFraProductPricer test = DiscountingFraProductPricer.DEFAULT;
    CurrencyAmount computed = test.forecastValue(fraExp, prov);
    assertEquals(computed.getAmount(), expected, TOLERANCE);
  }
  /** Test forecast value for ISDA FRA Discounting method. */
  public void test_forecastValue_ISDA() {
    ExpandedFra fraExp = FRA.expand();
    SimpleRatesProvider prov = createProvider(fraExp);

    double fixedRate = FRA.getFixedRate();
    double yearFraction = fraExp.getYearFraction();
    double notional = fraExp.getNotional();
    double expected =
        notional * yearFraction * (FORWARD_RATE - fixedRate) / (1.0 + yearFraction * FORWARD_RATE);

    DiscountingFraProductPricer test = DiscountingFraProductPricer.DEFAULT;
    CurrencyAmount computed = test.forecastValue(fraExp, prov);
    assertEquals(computed.getAmount(), expected, TOLERANCE);

    // test via FraTrade
    DiscountingFraTradePricer testTrade = new DiscountingFraTradePricer(test);
    assertEquals(testTrade.forecastValue(FRA_TRADE, prov), test.forecastValue(fraExp, prov));
  }