Package com.opengamma.analytics.financial.interestrate.payments.derivative

Examples of com.opengamma.analytics.financial.interestrate.payments.derivative.CouponIbor


    final String[] bumpedCurvesForwardName = {FUNDING_CURVE_NAME, bumpedCurveName};
    final SwaptionPhysicalFixedIbor swaptionBumpedForward = SWAPTION_DEFINITION_LONG_PAYER.toDerivative(REFERENCE_DATE, bumpedCurvesForwardName);
    final YieldAndDiscountCurve curveForward = curves.getCurve(FORWARD_CURVE_NAME);
    final Set<Double> timeForwardSet = new TreeSet<>();
    for (final Payment pay : SWAPTION_LONG_PAYER.getUnderlyingSwap().getSecondLeg().getPayments()) {
      final CouponIbor coupon = (CouponIbor) pay;
      timeForwardSet.add(coupon.getFixingPeriodStartTime());
      timeForwardSet.add(coupon.getFixingPeriodEndTime());
    }
    final int nbForwardDate = timeForwardSet.size();
    final List<Double> timeForwardList = new ArrayList<>(timeForwardSet);
    Double[] timeForwardArray = new Double[nbForwardDate];
    timeForwardArray = timeForwardList.toArray(timeForwardArray);
View Full Code Here


    final Annuity<? extends Payment> iborAnnuity = iborAnnuityDefinition.toDerivative(REFERENCE_DATE, CURVES_NAME);

    //produce a array of strictly ascending times
    final Set<Double> times = new TreeSet<>();
    for (int i = 0; i < iborAnnuity.getNumberOfPayments(); i++) {
      final CouponIbor coupon = (CouponIbor) iborAnnuity.getNthPayment(i);
      times.add(coupon.getPaymentTime());
      times.add(coupon.getFixingPeriodStartTime());
      times.add(coupon.getFixingPeriodEndTime());
    }
    final Double[] tArray = times.toArray(new Double[times.size()]);
    final double[] t = new double[times.size()];
    for (int i = 0; i < times.size(); i++) {
      t[i] = tArray[i];
View Full Code Here

    for (int i = 0; i < fixedLeg.getNumberOfPayments(); i++) {
      final CouponFixed coupon = fixedLeg.getNthPayment(i);
      times.add(coupon.getPaymentTime());
    }
    for (int i = 0; i < floatLeg.getNumberOfPayments(); i++) {
      final CouponIbor coupon = (CouponIbor) floatLeg.getNthPayment(i);
      times.add(coupon.getPaymentTime());
      times.add(coupon.getFixingPeriodStartTime());
      times.add(coupon.getFixingPeriodEndTime());
    }
    final Double[] tArray = times.toArray(new Double[times.size()]);
    final double[] t = new double[times.size()];
    for (int i = 0; i < times.size(); i++) {
      t[i] = tArray[i];
View Full Code Here

    // 1. Forward curve sensitivity
    final String bumpedCurveName = "Bumped Curve";
    final SwaptionPhysicalFixedIbor swptBumpedForward = SWAPTION_PAYER_LONG_DEFINITION.toDerivative(REFERENCE_DATE, new String[] {CURVES_NAME[0], bumpedCurveName });
    final DoubleAVLTreeSet forwardTime = new DoubleAVLTreeSet();
    for (int loopcpn = 0; loopcpn < SWAPTION_PAYER_LONG.getUnderlyingSwap().getSecondLeg().getNumberOfPayments(); loopcpn++) {
      final CouponIbor cpn = (CouponIbor) SWAPTION_PAYER_LONG.getUnderlyingSwap().getSecondLeg().getNthPayment(loopcpn);
      forwardTime.add(cpn.getFixingPeriodStartTime());
      forwardTime.add(cpn.getFixingPeriodEndTime());
    }
    final double[] nodeTimesForward = forwardTime.toDoubleArray();
    final double[] sensiForwardMethod = SensitivityFiniteDifference.curveSensitivity(swptBumpedForward, BUNDLE_HW, CURVES_NAME[1], bumpedCurveName, nodeTimesForward, deltaShift, METHOD_HW);
    //    assertEquals("Sensitivity finite difference method: number of node", 2, sensiForwardMethod.length);
    final List<DoublesPair> sensiPvForward = pvsSwaption.getSensitivities().get(CURVES_NAME[1]);
    for (int loopnode = 0; loopnode < sensiForwardMethod.length; loopnode++) {
      final DoublesPair pairPv = sensiPvForward.get(loopnode);
      assertEquals("Sensitivity swaption pv to forward curve: Node " + loopnode, nodeTimesForward[loopnode], pairPv.getFirst(), 1E-8);
      assertEquals("Sensitivity finite difference method: node sensitivity " + loopnode, pairPv.second, sensiForwardMethod[loopnode], deltaTolerancePrice);
    }
    // 2. Discounting curve sensitivity
    final SwaptionPhysicalFixedIbor swptBumpedDisc = SWAPTION_PAYER_LONG_DEFINITION.toDerivative(REFERENCE_DATE, new String[] {bumpedCurveName, CURVES_NAME[1] });
    final DoubleAVLTreeSet discTime = new DoubleAVLTreeSet();
    for (int loopcpn = 0; loopcpn < SWAPTION_PAYER_LONG.getUnderlyingSwap().getSecondLeg().getNumberOfPayments(); loopcpn++) {
      final CouponIbor cpn = (CouponIbor) SWAPTION_PAYER_LONG.getUnderlyingSwap().getSecondLeg().getNthPayment(loopcpn);
      discTime.add(cpn.getPaymentTime());
    }
    final double[] nodeTimesDisc = discTime.toDoubleArray();
    final double[] sensiDiscMethod = SensitivityFiniteDifference.curveSensitivity(swptBumpedDisc, BUNDLE_HW, CURVES_NAME[0], bumpedCurveName, nodeTimesDisc, deltaShift, METHOD_HW);
    assertEquals("Sensitivity finite difference method: number of node", SWAP_TENOR_YEAR * 4, sensiDiscMethod.length);
    final List<DoublesPair> sensiPvDisc = pvsSwaption.getSensitivities().get(CURVES_NAME[0]);
View Full Code Here

    InterestRateCurveSensitivity pvcsSwaption = METHOD_BLACK.presentValueCurveSensitivity(SWAPTION_LONG_REC, CURVES_BLACK);
    pvcsSwaption = pvcsSwaption.cleaned();
    // 1. Forward curve sensitivity
    final DoubleAVLTreeSet forwardTime = new DoubleAVLTreeSet();
    for (int loopcpn = 0; loopcpn < SWAPTION_LONG_REC.getUnderlyingSwap().getSecondLeg().getNumberOfPayments(); loopcpn++) {
      final CouponIbor cpn = (CouponIbor) SWAPTION_LONG_REC.getUnderlyingSwap().getSecondLeg().getNthPayment(loopcpn);
      forwardTime.add(cpn.getFixingPeriodStartTime());
      forwardTime.add(cpn.getFixingPeriodEndTime());
    }
    final double[] nodeTimesForward = forwardTime.toDoubleArray();
    final List<DoublesPair> sensiPvFwd = pvcsSwaption.getSensitivities().get(CURVES_NAME[2]);
    final List<DoublesPair> fdSenseFwd = FDCurveSensitivityCalculator.curveSensitvityFDCalculator(SWAPTION_LONG_REC, METHOD_BLACK, CURVES_BLACK, CURVES_NAME[2], nodeTimesForward, TOLERANCE_DELTA);
    assertSensitivityEquals(sensiPvFwd, fdSenseFwd, TOLERANCE_DELTA);
    // 2. Discounting curve sensitivity
    final DoubleAVLTreeSet discTime = new DoubleAVLTreeSet();
    discTime.add(SWAPTION_LONG_REC.getSettlementTime());
    for (int loopcpn = 0; loopcpn < SWAPTION_LONG_REC.getUnderlyingSwap().getSecondLeg().getNumberOfPayments(); loopcpn++) {
      final CouponIbor cpn = (CouponIbor) SWAPTION_LONG_REC.getUnderlyingSwap().getSecondLeg().getNthPayment(loopcpn);
      discTime.add(cpn.getPaymentTime());
    }
    final double[] nodeTimesDisc = discTime.toDoubleArray();
    final List<DoublesPair> sensiPvDisc = pvcsSwaption.getSensitivities().get(CURVES_NAME[0]);
    final List<DoublesPair> fdSenseDsc = FDCurveSensitivityCalculator.curveSensitvityFDCalculator(SWAPTION_LONG_REC, METHOD_BLACK, CURVES_BLACK, CURVES_NAME[0], nodeTimesDisc, TOLERANCE_DELTA);
    assertSensitivityEquals(sensiPvDisc, fdSenseDsc, TOLERANCE_DELTA);
View Full Code Here

    // 1. Forward curve sensitivity
    final String bumpedCurveName = "Bumped Curve";
    final SwaptionPhysicalFixedIbor swptBumpedForward = SWAPTION_PAYER_LONG_DEFINITION.toDerivative(REFERENCE_DATE, new String[] {CURVES_NAME[0], bumpedCurveName });
    final DoubleAVLTreeSet forwardTime = new DoubleAVLTreeSet();
    for (int loopcpn = 0; loopcpn < SWAPTION_PAYER_LONG.getUnderlyingSwap().getSecondLeg().getNumberOfPayments(); loopcpn++) {
      final CouponIbor cpn = (CouponIbor) SWAPTION_PAYER_LONG.getUnderlyingSwap().getSecondLeg().getNthPayment(loopcpn);
      forwardTime.add(cpn.getFixingPeriodStartTime());
      forwardTime.add(cpn.getFixingPeriodEndTime());
    }
    final double[] nodeTimesForward = forwardTime.toDoubleArray();
    final double[] sensiForwardMethod = SensitivityFiniteDifference.curveSensitivity(swptBumpedForward, BUNDLE_LMM, CURVES_NAME[1], bumpedCurveName, nodeTimesForward, deltaShift, METHOD_LMM);
    final List<DoublesPair> sensiPvForward = pvsSwaption.getSensitivities().get(CURVES_NAME[1]);
    for (int loopnode = 0; loopnode < sensiForwardMethod.length; loopnode++) {
      final DoublesPair pairPv = sensiPvForward.get(loopnode);
      assertEquals("Sensitivity swaption pv to forward curve: Node " + loopnode, nodeTimesForward[loopnode], pairPv.getFirst(), 1E-8);
      assertEquals("Sensitivity finite difference method: node sensitivity " + loopnode, sensiForwardMethod[loopnode], pairPv.second, deltaTolerancePrice);
    }
    // 2. Discounting curve sensitivity
    final SwaptionPhysicalFixedIbor swptBumpedDisc = SWAPTION_PAYER_LONG_DEFINITION.toDerivative(REFERENCE_DATE, new String[] {bumpedCurveName, CURVES_NAME[1] });
    final DoubleAVLTreeSet discTime = new DoubleAVLTreeSet();
    discTime.add(SWAPTION_PAYER_LONG.getSettlementTime());
    for (int loopcpn = 0; loopcpn < SWAPTION_PAYER_LONG.getUnderlyingSwap().getSecondLeg().getNumberOfPayments(); loopcpn++) {
      final CouponIbor cpn = (CouponIbor) SWAPTION_PAYER_LONG.getUnderlyingSwap().getSecondLeg().getNthPayment(loopcpn);
      discTime.add(cpn.getPaymentTime());
    }
    final double[] nodeTimesDisc = discTime.toDoubleArray();
    final double[] sensiDiscMethod = SensitivityFiniteDifference.curveSensitivity(swptBumpedDisc, BUNDLE_LMM, CURVES_NAME[0], bumpedCurveName, nodeTimesDisc, deltaShift, METHOD_LMM);
    final List<DoublesPair> sensiPvDisc = pvsSwaption.getSensitivities().get(CURVES_NAME[0]);
    assertEquals("Sensitivity finite difference method: number of node", SWAP_TENOR_YEAR * 4 + 1, sensiPvDisc.size());
View Full Code Here

    final String[] bumpedCurvesForwardName = {FUNDING_CURVE_NAME, bumpedCurveName};
    final SwaptionCashFixedIbor swaptionBumpedForward = swaptionDefinitionLongPayerHighStrike.toDerivative(REFERENCE_DATE, bumpedCurvesForwardName);
    final YieldAndDiscountCurve curveForward = curves.getCurve(FORWARD_CURVE_NAME);
    final Set<Double> timeForwardSet = new TreeSet<>();
    for (final Payment pay : swaptionLongPayerHighStrike.getUnderlyingSwap().getSecondLeg().getPayments()) {
      final CouponIbor coupon = (CouponIbor) pay;
      timeForwardSet.add(coupon.getFixingPeriodStartTime());
      timeForwardSet.add(coupon.getFixingPeriodEndTime());
    }
    final int nbForwardDate = timeForwardSet.size();
    final List<Double> timeForwardList = new ArrayList<>(timeForwardSet);
    Double[] timeForwardArray = new Double[nbForwardDate];
    timeForwardArray = timeForwardList.toArray(timeForwardArray);
View Full Code Here

   * Tests the cash flow equivalent of a Ibor coupon.
   */
  public void iborCoupon() {
    final int cpnIndex = 17; // To have payment different from end fixing.
    final Payment cpn = SWAP.getSecondLeg().getNthPayment(cpnIndex);
    final CouponIbor cpnIbor = (CouponIbor) cpn;
    final AnnuityPaymentFixed cfe = cpn.accept(CFEC, CURVES);
    assertEquals("Fixed coupon: Number of flows", 2, cfe.getNumberOfPayments());
    assertEquals("Fixed coupon: Time", cpn.getPaymentTime(), cfe.getNthPayment(1).getPaymentTime(), 1E-5);
    assertEquals("Fixed coupon: Amount", -NOTIONAL * (FIXED_IS_PAYER ? 1.0 : -1.0) * cpnIbor.getPaymentYearFraction() / cpnIbor.getFixingAccrualFactor(), cfe.getNthPayment(1).getAmount(), 1E-2);
    assertEquals("Fixed coupon: Time", cpnIbor.getFixingPeriodStartTime(), cfe.getNthPayment(0).getPaymentTime(), 1E-5);
    final double beta = CURVES.getCurve(FORWARD_CURVE_NAME).getDiscountFactor(cpnIbor.getFixingPeriodStartTime()) /
        CURVES.getCurve(FORWARD_CURVE_NAME).getDiscountFactor(cpnIbor.getFixingPeriodEndTime())
        * CURVES.getCurve(FUNDING_CURVE_NAME).getDiscountFactor(cpnIbor.getPaymentTime()) / CURVES.getCurve(FUNDING_CURVE_NAME).getDiscountFactor(cpnIbor.getFixingPeriodStartTime());
    assertEquals("Fixed coupon: Amount", beta * NOTIONAL * (FIXED_IS_PAYER ? 1.0 : -1.0) * cpnIbor.getPaymentYearFraction() / cpnIbor.getFixingAccrualFactor(), cfe.getNthPayment(0).getAmount(), 1E-4);
    final double pvCpn = cpn.accept(PVC, CURVES);
    final double pvCfe = cfe.accept(PVC, CURVES);
    assertEquals("Cash flow equivalent - Swap: present value", pvCpn, pvCfe, 1E-5);
  }
View Full Code Here

  /**
   * Tests the cash-flow equivalent of a Ibor leg.
   */
  public void iborLeg() {
    final Annuity<Coupon> leg = SWAP.getSecondLeg();
    CouponIbor cpnIbor = (CouponIbor) SWAP.getSecondLeg().getNthPayment(0);
    final AnnuityPaymentFixed cfe = leg.accept(CFEC, CURVES);
    assertEquals("Ibor leg: Number of flows", FIXED_PAYMENT_PAYMENT_BY_YEAR * SWAP_TENOR_YEAR * 2 + 1, cfe.getNumberOfPayments());
    assertEquals("Ibor leg: Time", cpnIbor.getFixingPeriodStartTime(), cfe.getNthPayment(0).getPaymentTime(), 1E-5);
    double beta = CURVES.getCurve(FORWARD_CURVE_NAME).getDiscountFactor(cpnIbor.getFixingPeriodStartTime()) / CURVES.getCurve(FORWARD_CURVE_NAME).getDiscountFactor(cpnIbor.getFixingPeriodEndTime())
        * CURVES.getCurve(FUNDING_CURVE_NAME).getDiscountFactor(cpnIbor.getPaymentTime()) / CURVES.getCurve(FUNDING_CURVE_NAME).getDiscountFactor(cpnIbor.getFixingPeriodStartTime());
    assertEquals("Ibor leg: Amount", beta * NOTIONAL * (FIXED_IS_PAYER ? 1.0 : -1.0), cfe.getNthPayment(0).getAmount(), 1E-4);
    CouponIbor cpnIborPrevious;
    for (int loopcf = 1; loopcf < leg.getNumberOfPayments(); loopcf++) {
      cpnIborPrevious = (CouponIbor) SWAP.getSecondLeg().getNthPayment(loopcf - 1);
      cpnIbor = (CouponIbor) SWAP.getSecondLeg().getNthPayment(loopcf);
      beta = CURVES.getCurve(FORWARD_CURVE_NAME).getDiscountFactor(cpnIbor.getFixingPeriodStartTime()) / CURVES.getCurve(FORWARD_CURVE_NAME).getDiscountFactor(cpnIbor.getFixingPeriodEndTime())
          * CURVES.getCurve(FUNDING_CURVE_NAME).getDiscountFactor(cpnIbor.getPaymentTime()) / CURVES.getCurve(FUNDING_CURVE_NAME).getDiscountFactor(cpnIbor.getFixingPeriodStartTime());
      assertEquals("Ibor leg: Amount - item " + loopcf,
          (beta * cpnIbor.getPaymentYearFraction() / cpnIbor.getFixingAccrualFactor() - 1 * cpnIborPrevious.getPaymentYearFraction() / cpnIborPrevious.getFixingAccrualFactor()) * NOTIONAL
          * (FIXED_IS_PAYER ? 1.0 : -1.0), cfe.getNthPayment(loopcf).getAmount(), 1E-4);
      assertEquals("Ibor leg: Time", leg.getNthPayment(loopcf - 1).getPaymentTime(), cfe.getNthPayment(loopcf).getPaymentTime(), 1E-5);
    }
    assertEquals("Ibor leg: Amount", -1 * NOTIONAL * (FIXED_IS_PAYER ? 1.0 : -1.0), cfe.getNthPayment(leg.getNumberOfPayments()).getAmount(), 1E-4);
    assertEquals("Ibor leg: Time", leg.getNthPayment(leg.getNumberOfPayments() - 1).getPaymentTime(), cfe.getNthPayment(leg.getNumberOfPayments()).getPaymentTime(), 1E-5);
View Full Code Here

  /**
   * Tests the cash-flow equivalent of a fixed-Ibor swap.
   */
  public void swapFixedIbor() {
    final Annuity<Coupon> leg = SWAP.getSecondLeg();
    CouponIbor cpnIbor = (CouponIbor) SWAP.getSecondLeg().getNthPayment(0);
    final AnnuityPaymentFixed cfe = SWAP.accept(CFEC, CURVES);
    assertEquals("Swap: Number of flows", FIXED_PAYMENT_PAYMENT_BY_YEAR * SWAP_TENOR_YEAR * 2 + 1, cfe.getNumberOfPayments());
    assertEquals("Swap: Time", cpnIbor.getFixingPeriodStartTime(), cfe.getNthPayment(0).getPaymentTime(), 1E-5);
    double beta = CURVES.getCurve(FORWARD_CURVE_NAME).getDiscountFactor(cpnIbor.getFixingPeriodStartTime()) / CURVES.getCurve(FORWARD_CURVE_NAME).getDiscountFactor(cpnIbor.getFixingPeriodEndTime())
        * CURVES.getCurve(FUNDING_CURVE_NAME).getDiscountFactor(cpnIbor.getPaymentTime()) / CURVES.getCurve(FUNDING_CURVE_NAME).getDiscountFactor(cpnIbor.getFixingPeriodStartTime());
    assertEquals("Swap: Amount", beta * NOTIONAL * (FIXED_IS_PAYER ? 1.0 : -1.0), cfe.getNthPayment(0).getAmount(), 1E-4);
    CouponIbor cpnIborPrevious;
    for (int loopcf = 2; loopcf < leg.getNumberOfPayments(); loopcf += 2) {
      cpnIborPrevious = (CouponIbor) SWAP.getSecondLeg().getNthPayment(loopcf - 1);
      cpnIbor = (CouponIbor) SWAP.getSecondLeg().getNthPayment(loopcf);
      beta = CURVES.getCurve(FORWARD_CURVE_NAME).getDiscountFactor(cpnIbor.getFixingPeriodStartTime()) / CURVES.getCurve(FORWARD_CURVE_NAME).getDiscountFactor(cpnIbor.getFixingPeriodEndTime())
          * CURVES.getCurve(FUNDING_CURVE_NAME).getDiscountFactor(cpnIbor.getPaymentTime()) / CURVES.getCurve(FUNDING_CURVE_NAME).getDiscountFactor(cpnIbor.getFixingPeriodStartTime());
      assertEquals("Swap: Amount",
          (beta * cpnIbor.getPaymentYearFraction() / cpnIbor.getFixingAccrualFactor() - 1 * cpnIborPrevious.getPaymentYearFraction() / cpnIborPrevious.getFixingAccrualFactor()) * NOTIONAL
          * (FIXED_IS_PAYER ? 1.0 : -1.0) + SWAP.getFixedLeg().getNthPayment(loopcf / 2 - 1).getAmount(), cfe.getNthPayment(loopcf).getAmount(), 1E-4);
      assertEquals("Swap: Time", leg.getNthPayment(loopcf - 1).getPaymentTime(), cfe.getNthPayment(loopcf).getPaymentTime(), 1E-5);
    }
    for (int loopcf = 1; loopcf < leg.getNumberOfPayments(); loopcf += 2) {
      cpnIborPrevious = (CouponIbor) SWAP.getSecondLeg().getNthPayment(loopcf - 1);
      cpnIbor = (CouponIbor) SWAP.getSecondLeg().getNthPayment(loopcf);
      beta = CURVES.getCurve(FORWARD_CURVE_NAME).getDiscountFactor(cpnIbor.getFixingPeriodStartTime()) / CURVES.getCurve(FORWARD_CURVE_NAME).getDiscountFactor(cpnIbor.getFixingPeriodEndTime())
          * CURVES.getCurve(FUNDING_CURVE_NAME).getDiscountFactor(cpnIbor.getPaymentTime()) / CURVES.getCurve(FUNDING_CURVE_NAME).getDiscountFactor(cpnIbor.getFixingPeriodStartTime());
      assertEquals("Swap: Amount",
          (beta * cpnIbor.getPaymentYearFraction() / cpnIbor.getFixingAccrualFactor() - 1 * cpnIborPrevious.getPaymentYearFraction() / cpnIborPrevious.getFixingAccrualFactor()) * NOTIONAL
          * (FIXED_IS_PAYER ? 1.0 : -1.0), cfe.getNthPayment(loopcf).getAmount(), 1E-4);
      assertEquals("Swap: Time", leg.getNthPayment(loopcf - 1).getPaymentTime(), cfe.getNthPayment(loopcf).getPaymentTime(), 1E-5);
    }
    assertEquals("Swap: Amount", (-1 * NOTIONAL * (FIXED_IS_PAYER ? 1.0 : -1.0)) + SWAP.getFixedLeg().getNthPayment(SWAP.getFixedLeg().getNumberOfPayments() - 1).getAmount(),
        cfe.getNthPayment(leg.getNumberOfPayments()).getAmount(), 1E-4);
View Full Code Here

TOP

Related Classes of com.opengamma.analytics.financial.interestrate.payments.derivative.CouponIbor

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.