Esempio n. 1
0
  /**
   * Inelastics constructor
   *
   * @param dblLeft Spline Left Ordinate
   * @param dblRight Spline Right Ordinate
   * @throws java.lang.Exception Thrown if inputs are invalid
   */
  public Inelastics(final double dblLeft, final double dblRight) throws java.lang.Exception {
    if (!org.drip.math.common.NumberUtil.IsValid(_dblLeft = dblLeft)
        || !org.drip.math.common.NumberUtil.IsValid(_dblRight = dblRight)
        || _dblLeft >= _dblRight) {
      System.out.println(_dblLeft + "=>" + _dblRight);

      throw new java.lang.Exception("Inelastics ctr: Invalid inputs!");
    }
  }
  @Override
  public double getNotional(final double dblDate1, final double dblDate2)
      throws java.lang.Exception {
    if (null == _notlSchedule
        || !org.drip.math.common.NumberUtil.IsValid(dblDate1)
        || !org.drip.math.common.NumberUtil.IsValid(dblDate2))
      throw new java.lang.Exception("Bad date into getNotional");

    return _notlSchedule.getFactor(dblDate1, dblDate2);
  }
Esempio n. 3
0
  /**
   * Print the contents of the 1D array
   *
   * @param strName Label Name
   * @param adblA The 1D array
   * @param bBailOnNaN Bail on encountering an NaN
   * @return TRUE => Print Successful
   */
  public static final boolean Print1DArray(
      final java.lang.String strName, final double[] adblA, final boolean bBailOnNaN) {
    if (null == adblA || 0 == adblA.length) return false;

    int iSize = adblA.length;

    for (int i = 0; i < iSize; ++i) {
      if (!org.drip.math.common.NumberUtil.IsValid(adblA[i]) && bBailOnNaN) return false;

      System.out.println(strName + "[" + i + "] = " + adblA[i]);
    }

    return true;
  }
  /**
   * Creates the EOS from the dates/factors string arrays
   *
   * @param strDates String representing the date array
   * @param strFactors String representing the factor array
   * @param iNoticePeriod Exercise Notice Period
   * @param bIsPut True (Put), False (Call)
   * @param bIsDiscrete True (Discrete), False (Continuous)
   * @param dblScheduleStart Schedule start Date
   * @param bFixToFloatOnExercise True => component becomes a floater on call
   * @param dblFixToFloatExerciseDate Date at which the fix to float conversion happens
   * @param strFloatIndex Floater Rate Index
   * @param dblFixToFloatSpread Floater Spread
   * @return EOS object
   */
  public static final EmbeddedOptionSchedule CreateFromDateFactorSet(
      final java.lang.String strDates,
      final java.lang.String strFactors,
      final int iNoticePeriod,
      final boolean bIsPut,
      final boolean bIsDiscrete,
      final double dblScheduleStart,
      final boolean bFixToFloatOnExercise,
      final double dblFixToFloatExerciseDate,
      final java.lang.String strFloatIndex,
      final double dblFixToFloatSpread) {
    if (null == strDates
        || strDates.isEmpty()
        || null == strFactors
        || strFactors.isEmpty()
        || !org.drip.math.common.NumberUtil.IsValid(dblScheduleStart)) return null;

    if (bIsDiscrete) {
      try {
        return new EmbeddedOptionSchedule(
            org.drip.math.common.StringUtil.MakeDoubleArrayFromStringTokenizer(
                new java.util.StringTokenizer(strDates, ";")),
            org.drip.math.common.StringUtil.MakeDoubleArrayFromStringTokenizer(
                new java.util.StringTokenizer(strFactors, ";")),
            bIsPut,
            iNoticePeriod,
            bFixToFloatOnExercise,
            dblFixToFloatExerciseDate,
            strFloatIndex,
            dblFixToFloatSpread);
      } catch (java.lang.Exception e) {
        e.printStackTrace();
      }

      return null;
    }

    return fromAmerican(
        dblScheduleStart,
        org.drip.math.common.StringUtil.MakeDoubleArrayFromStringTokenizer(
            new java.util.StringTokenizer(strDates, ";")),
        org.drip.math.common.StringUtil.MakeDoubleArrayFromStringTokenizer(
            new java.util.StringTokenizer(strFactors, ";")),
        bIsPut,
        iNoticePeriod,
        bFixToFloatOnExercise,
        dblFixToFloatExerciseDate,
        strFloatIndex,
        dblFixToFloatSpread);
  }
  /**
   * Creates the named CDX from effective, maturity, coupon, IR curve name, credit curve name set,
   * and their weights.
   *
   * @param dtEffective JulianDate Effective
   * @param dtMaturity JulianDate Maturity
   * @param dblCoupon Coupon
   * @param strIR IR curve name
   * @param astrCC credit curve name
   * @param adblWeight Credit Component Weights
   * @param strName CDX name
   * @return BasketDefaultSwap
   */
  public static final org.drip.product.definition.BasketProduct MakeCDX(
      final org.drip.analytics.date.JulianDate dtEffective,
      final org.drip.analytics.date.JulianDate dtMaturity,
      final double dblCoupon,
      final java.lang.String strIR,
      final java.lang.String[] astrCC,
      final double[] adblWeight,
      final java.lang.String strName) {
    if (null == dtEffective
        || null == dtMaturity
        || !org.drip.math.common.NumberUtil.IsValid(dblCoupon)
        || null == strIR
        || strIR.isEmpty()
        || null == strName
        || strName.isEmpty()
        || null == astrCC
        || 0 == astrCC.length
        || null == adblWeight
        || 0 == adblWeight.length
        || adblWeight.length != astrCC.length) return null;

    org.drip.product.definition.CreditDefaultSwap aCDS[] =
        new org.drip.product.definition.CreditDefaultSwap[astrCC.length];

    for (int i = 0; i < astrCC.length; ++i) {
      try {
        aCDS[i] =
            org.drip.product.creator.CDSBuilder.CreateCDS(
                dtEffective, dtMaturity, dblCoupon, strIR, 0.40, astrCC[i], strIR, true);
      } catch (java.lang.Exception e) {
        e.printStackTrace();

        return null;
      }
    }

    try {
      return new org.drip.product.credit.CDSBasket(
          dtEffective, dtMaturity, dblCoupon, aCDS, adblWeight, strName);
    } catch (java.lang.Exception e) {
      e.printStackTrace();
    }

    return null;
  }
Esempio n. 6
0
  /**
   * Print the contents of the 2D array
   *
   * @param strName Label Name
   * @param aadblA The 2D array
   * @param bBailOnNaN Bail on encountering an NaN
   * @return TRUE => Print Successful
   */
  public static final boolean Print2DArray(
      final java.lang.String strName, final double[][] aadblA, final boolean bBailOnNaN) {
    if (null == aadblA || 0 == aadblA.length) return false;

    int iSize = aadblA.length;

    for (int i = 0; i < iSize; ++i) {
      for (int j = 0; j < iSize; ++j) {
        if (!org.drip.math.common.NumberUtil.IsValid(aadblA[i][j]) && bBailOnNaN) return false;

        System.out.println(
            strName
                + "["
                + i
                + "]["
                + j
                + "] = "
                + org.drip.math.common.FormatUtil.FormatDouble(aadblA[i][j], 0, 6, 1.));
      }
    }

    return true;
  }
Esempio n. 7
0
 /**
  * Finds out if the point is inside the segment - left/right is inclusive.
  *
  * @param dblPoint Point
  * @return TRUE => Point is inside the segment
  */
 public boolean isInSegment(final double dblPoint) {
   return org.drip.math.common.NumberUtil.IsValid(dblPoint)
       && _dblLeft <= dblPoint
       && _dblRight >= dblPoint;
 }