Example #1
0
  /**
   * Flatten an input 2D string/double map into a delimited string array
   *
   * @param map2DSD 2D String/Double map
   * @param strKVDelimiter Element delimiter
   * @param strRecordDelimiter Record delimiter
   * @return Flattened map string
   */
  public static final java.lang.String TwoDSDMapToFlatString(
      final org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double> map2DSD,
      final java.lang.String strKVDelimiter,
      final java.lang.String strRecordDelimiter) {
    if (null == map2DSD
        || 0 == map2DSD.size()
        || null == map2DSD.entrySet()
        || null == strKVDelimiter
        || strKVDelimiter.isEmpty()
        || null == strRecordDelimiter
        || strRecordDelimiter.isEmpty()) return "";

    boolean bFirstEntry = true;

    java.lang.StringBuffer sb = new java.lang.StringBuffer();

    for (java.util.Map.Entry<java.lang.String, java.lang.Double> me : map2DSD.entrySet()) {
      if (null == me || null == me.getKey() || me.getKey().isEmpty()) continue;

      if (bFirstEntry) bFirstEntry = false;
      else sb.append(strRecordDelimiter);

      sb.append(me.getKey() + strKVDelimiter + me.getValue());
    }

    return sb.toString();
  }
  /**
   * Validate the CDXRefData instance
   *
   * @return TRUE if successful
   */
  public boolean validate() {
    if (null == _strCurveID
        || _strCurveID.isEmpty()
        || null == _strSPN
        || _strSPN.isEmpty()
        || null == _strIndexLabel
        || _strIndexLabel.isEmpty()
        || null == _strIndexName
        || _strIndexName.isEmpty()
        || null == _strCurveName
        || _strCurveName.isEmpty()
        || null == _dtIssue
        || null == _dtMaturity
        || _dtIssue.getJulian() >= _dtMaturity.getJulian()
        || !org.drip.quant.common.NumberUtil.IsValid(_dblCoupon)
        || null == _strCurrency
        || _strCurrency.isEmpty()
        || null == _strDayCount
        || _strDayCount.isEmpty()
        || !org.drip.quant.common.NumberUtil.IsValid(_dblRecovery)
        || null == _strRedID
        || _strRedID.isEmpty()
        || null == _strIndexClass
        || _strIndexClass.isEmpty()
        || null == _strIndexGroupName
        || _strIndexGroupName.isEmpty()) return false;

    return true;
  }
 public static java.lang.String className(
     @Name("obj") @TypeInfo("ceylon.language::Object") final java.lang.Object object) {
   // TODO: type args?
   Name annot = object.getClass().getAnnotation(Name.class);
   if (annot != null) {
     if (object.getClass().getPackage() != null) {
       return object.getClass().getPackage().getName() + "::" + annot.value();
     } else {
       return annot.value();
     }
   } else {
     Ceylon ann = object.getClass().getAnnotation(Ceylon.class);
     java.lang.String pkg =
         object.getClass().getPackage() == null ? "" : object.getClass().getPackage().getName();
     java.lang.String name = object.getClass().getSimpleName();
     if (name.isEmpty()) {
       name = object.getClass().getName();
       // Remove the package from the classname
       if (!pkg.isEmpty()) {
         name = name.substring(pkg.length() + 1);
       }
     }
     // FIXME The mangle part really shouldn't be necessary as long as we add @Name
     // annotations to all classes with mangled names
     return mangle(pkg, ann) + "::" + mangle(name, ann);
   }
 }
  @Override
  public byte[] serialize() {
    java.lang.StringBuffer sb = new java.lang.StringBuffer();

    sb.append(org.drip.service.stream.Serializer.VERSION + getFieldDelimiter());

    sb.append(_dblNotional + getFieldDelimiter());

    sb.append(_dblSpread + getFieldDelimiter());

    if (null == _strIR || _strIR.isEmpty())
      sb.append(org.drip.service.stream.Serializer.NULL_SER_STRING + getFieldDelimiter());
    else sb.append(_strIR + getFieldDelimiter());

    if (null == _strCode || _strCode.isEmpty())
      sb.append(org.drip.service.stream.Serializer.NULL_SER_STRING + getFieldDelimiter());
    else sb.append(_strCode + getFieldDelimiter());

    sb.append(_bApplyAccEOMAdj + getFieldDelimiter());

    sb.append(_bApplyCpnEOMAdj + getFieldDelimiter());

    sb.append(_dblMaturity + getFieldDelimiter());

    sb.append(_dblEffective + getFieldDelimiter());

    if (null == _fri)
      sb.append(org.drip.service.stream.Serializer.NULL_SER_STRING + getFieldDelimiter());
    else sb.append(new java.lang.String(_fri.serialize()) + getFieldDelimiter());

    if (null == _notlSchedule)
      sb.append(org.drip.service.stream.Serializer.NULL_SER_STRING + getFieldDelimiter());
    else sb.append(new java.lang.String(_notlSchedule.serialize()) + getFieldDelimiter());

    if (null == _settleParams)
      sb.append(org.drip.service.stream.Serializer.NULL_SER_STRING + getFieldDelimiter());
    else sb.append(new java.lang.String(_settleParams.serialize()) + getFieldDelimiter());

    if (null == _lsCouponPeriod) sb.append(org.drip.service.stream.Serializer.NULL_SER_STRING);
    else {
      boolean bFirstEntry = true;

      java.lang.StringBuffer sbPeriods = new java.lang.StringBuffer();

      for (org.drip.analytics.period.CashflowPeriod p : _lsCouponPeriod) {
        if (null == p) continue;

        if (bFirstEntry) bFirstEntry = false;
        else sbPeriods.append(getCollectionRecordDelimiter());

        sbPeriods.append(new java.lang.String(p.serialize()));
      }

      if (sbPeriods.toString().isEmpty())
        sb.append(org.drip.service.stream.Serializer.NULL_SER_STRING);
      else sb.append(sbPeriods.toString());
    }

    return sb.append(getObjectTrailer()).toString().getBytes();
  }
Example #5
0
  /**
   * RatesSetting de-serialization from input byte array
   *
   * @param ab Byte Array
   * @throws java.lang.Exception Thrown if RatesSetting cannot be properly de-serialized
   */
  public RatesSetting(final byte[] ab) throws java.lang.Exception {
    if (null == ab || 0 == ab.length)
      throw new java.lang.Exception("RatesSetting de-serializer: Invalid input Byte array");

    java.lang.String strRawString = new java.lang.String(ab);

    if (null == strRawString || strRawString.isEmpty())
      throw new java.lang.Exception("RatesSetting de-serializer: Empty state");

    java.lang.String strSerializedRatesSetting =
        strRawString.substring(0, strRawString.indexOf(getObjectTrailer()));

    if (null == strSerializedRatesSetting || strSerializedRatesSetting.isEmpty())
      throw new java.lang.Exception("RatesSetting de-serializer: Cannot locate state");

    java.lang.String[] astrField =
        org.drip.math.common.StringUtil.Split(strSerializedRatesSetting, getFieldDelimiter());

    if (null == astrField || 5 > astrField.length)
      throw new java.lang.Exception("RatesSetting de-serializer: Invalid reqd field set");

    // double dblVersion = new java.lang.Double (astrField[0]);

    if (null == astrField[1]
        || astrField[1].isEmpty()
        || org.drip.service.stream.Serializer.NULL_SER_STRING.equalsIgnoreCase(astrField[1]))
      throw new java.lang.Exception("RatesSetting de-serializer: Cannot locate Trade Currency");

    _strTradeDiscountCurve = astrField[1];

    if (null == astrField[2]
        || astrField[2].isEmpty()
        || org.drip.service.stream.Serializer.NULL_SER_STRING.equalsIgnoreCase(astrField[2]))
      throw new java.lang.Exception("RatesSetting de-serializer: Cannot locate Coupon Currency");

    _strCouponDiscountCurve = astrField[2];

    if (null == astrField[3]
        || astrField[3].isEmpty()
        || org.drip.service.stream.Serializer.NULL_SER_STRING.equalsIgnoreCase(astrField[3]))
      throw new java.lang.Exception("RatesSetting de-serializer: Cannot locate Principal Currency");

    _strPrincipalDiscountCurve = astrField[3];

    if (null == astrField[4]
        || astrField[4].isEmpty()
        || org.drip.service.stream.Serializer.NULL_SER_STRING.equalsIgnoreCase(astrField[4]))
      throw new java.lang.Exception(
          "RatesSetting de-serializer: Cannot locate Redemption Currency");

    _strRedemptionDiscountCurve = astrField[4];

    if (!validate()) throw new java.lang.Exception("RatesSetting de-serializer: Cannot validate!");
  }
Example #6
0
  @Override
  public boolean validate() {
    if (null == _strTradeDiscountCurve
        || _strTradeDiscountCurve.isEmpty()
        || null == _strCouponDiscountCurve
        || _strCouponDiscountCurve.isEmpty()
        || null == _strPrincipalDiscountCurve
        || _strPrincipalDiscountCurve.isEmpty()
        || null == _strRedemptionDiscountCurve
        || _strRedemptionDiscountCurve.isEmpty()) return false;

    return true;
  }
  /**
   * TerminationSetting de-serialization from input byte array
   *
   * @param ab Byte Array
   * @throws java.lang.Exception Thrown if TerminationSetting cannot be properly de-serialized
   */
  public TerminationSetting(final byte[] ab) throws java.lang.Exception {
    if (null == ab || 0 == ab.length)
      throw new java.lang.Exception("TerminationSetting de-serializer: Invalid input Byte array");

    java.lang.String strRawString = new java.lang.String(ab);

    if (null == strRawString || strRawString.isEmpty())
      throw new java.lang.Exception("TerminationSetting de-serializer: Empty state");

    java.lang.String strSerializedTerminationSetting =
        strRawString.substring(0, strRawString.indexOf(getObjectTrailer()));

    if (null == strSerializedTerminationSetting || strSerializedTerminationSetting.isEmpty())
      throw new java.lang.Exception("TerminationSetting de-serializer: Cannot locate state");

    java.lang.String[] astrField =
        org.drip.quant.common.StringUtil.Split(
            strSerializedTerminationSetting, getFieldDelimiter());

    if (null == astrField || 4 > astrField.length)
      throw new java.lang.Exception("TerminationSetting de-serializer: Invalid reqd field set");

    // double dblVersion = new java.lang.Double (astrField[0]);

    if (null == astrField[1]
        || astrField[1].isEmpty()
        || org.drip.service.stream.Serializer.NULL_SER_STRING.equalsIgnoreCase(astrField[1]))
      throw new java.lang.Exception(
          "TerminationSetting de-serializer: Cannot locate perpetual flag");

    _bIsPerpetual = new java.lang.Boolean(astrField[1]);

    if (null == astrField[2]
        || astrField[2].isEmpty()
        || org.drip.service.stream.Serializer.NULL_SER_STRING.equalsIgnoreCase(astrField[2]))
      throw new java.lang.Exception(
          "TerminationSetting de-serializer: Cannot locate defaulted flag");

    _bIsDefaulted = new java.lang.Boolean(astrField[2]);

    if (null == astrField[3]
        || astrField[3].isEmpty()
        || org.drip.service.stream.Serializer.NULL_SER_STRING.equalsIgnoreCase(astrField[3]))
      throw new java.lang.Exception(
          "TerminationSetting de-serializer: Cannot locate exercised flag");

    _bHasBeenExercised = new java.lang.Boolean(astrField[3]);

    if (!validate())
      throw new java.lang.Exception("TerminationSetting de-serializer: Cannot validate!");
  }
Example #8
0
  /**
   * Turn a flattened 2D (string, double) string sequence into its corresponding map
   *
   * @param str2DMap Flattened 2D array input
   * @param strKVDelimiter Key-Value delimiter string
   * @param strRecordDelimiter Record delimiter string
   * @param bSkipNullValue Indicates whether NULL Values are to be skipped
   * @param strNULLString NULL string
   * @return [String, double] map
   */
  public static final org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double>
      FlatStringTo2DSDMap(
          final java.lang.String str2DMap,
          final java.lang.String strKVDelimiter,
          final java.lang.String strRecordDelimiter,
          final boolean bSkipNullValue,
          final java.lang.String strNULLString) {
    if (null == str2DMap
        || str2DMap.isEmpty()
        || null == strNULLString
        || strNULLString.isEmpty()
        || strNULLString.equalsIgnoreCase(str2DMap)
        || null == strKVDelimiter
        || strKVDelimiter.isEmpty()
        || null == strRecordDelimiter
        || strRecordDelimiter.isEmpty()) return null;

    java.lang.String[] astrRecord =
        org.drip.math.common.StringUtil.Split(str2DMap, strRecordDelimiter);

    if (null == astrRecord || 0 == astrRecord.length) return null;

    org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double> map2D =
        new org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double>();

    for (int i = 0; i < astrRecord.length; ++i) {
      if (null == astrRecord[i]
          || astrRecord[i].isEmpty()
          || strNULLString.equalsIgnoreCase(astrRecord[i])) continue;

      java.lang.String[] astrKVPair =
          org.drip.math.common.StringUtil.Split(astrRecord[i], strKVDelimiter);

      if (null == astrKVPair
          || 2 != astrKVPair.length
          || null == astrKVPair[0]
          || astrKVPair[0].isEmpty()
          || strNULLString.equalsIgnoreCase(astrKVPair[0])
          || (bSkipNullValue
              && (null == astrKVPair[1]
                  || astrKVPair[1].isEmpty()
                  || strNULLString.equalsIgnoreCase(astrKVPair[1])))) continue;

      map2D.put(astrKVPair[0], new java.lang.Double(astrKVPair[1]));
    }

    if (0 == map2D.size()) return null;

    return map2D;
  }
  /**
   * 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);
  }
  /**
   * Get the Market Node given the Strike and the Tenor
   *
   * @param dblStrike The Strike
   * @param strTenor The Maturity Tenor
   * @return The Volatility evaluated from the Volatility Surface
   * @throws java.lang.Exception Thrown if the Inputs are Invalid
   */
  public double node(final double dblStrike, final java.lang.String strTenor)
      throws java.lang.Exception {
    if (null == strTenor || strTenor.isEmpty())
      throw new java.lang.Exception("MarketSurface::node => Invalid Inputs");

    return node(dblStrike, epoch().addTenor(strTenor).julian());
  }
  private static final int[] GetIntArrayTagValue(
      final org.w3c.dom.Element eTag, final java.lang.String strTag) {
    if (null == eTag || null == strTag || null == eTag.getElementsByTagName(strTag)) return null;

    org.w3c.dom.NodeList nl = eTag.getElementsByTagName(strTag);

    if (!(nl.item(0) instanceof org.w3c.dom.Element)) return null;

    org.w3c.dom.Element elem = (org.w3c.dom.Element) nl.item(0);

    if (null == elem
        || null == elem.getChildNodes()
        || null == elem.getChildNodes().item(0)
        || !(elem.getChildNodes().item(0) instanceof org.w3c.dom.Node)) return null;

    java.lang.String strValue = elem.getChildNodes().item(0).getNodeValue();

    if (null == strValue || strValue.isEmpty()) return null;

    java.lang.String[] astrValue = strValue.split(",");

    int[] ai = new int[astrValue.length];

    for (int i = 0; i < astrValue.length; ++i)
      ai[i] = new java.lang.Integer(astrValue[i]).intValue();

    return ai;
  }
  /**
   * FloatingStream constructor
   *
   * @param dblEffective Effective Date
   * @param dblMaturity Maturity Date
   * @param dblSpread Spread
   * @param fri Floating Rate Index
   * @param iFreq Frequency
   * @param strCouponDC Coupon Day Count
   * @param strAccrualDC Accrual Day Count
   * @param bFullStub TRUE => Generate full first-stub
   * @param dapEffective Effective DAP
   * @param dapMaturity Maturity DAP
   * @param dapPeriodStart Period Start DAP
   * @param dapPeriodEnd Period End DAP
   * @param dapAccrualStart Accrual Start DAP
   * @param dapAccrualEnd Accrual End DAP
   * @param dapPay Pay DAP
   * @param dapReset Reset DAP
   * @param notlSchedule Notional Schedule
   * @param dblNotional Initial Notional Amount
   * @param strIR IR Curve
   * @param strCalendar Calendar
   * @throws java.lang.Exception Thrown if inputs are invalid
   */
  public FloatingStream(
      final double dblEffective,
      final double dblMaturity,
      final double dblSpread,
      final org.drip.product.params.FloatingRateIndex fri,
      final int iFreq,
      final java.lang.String strCouponDC,
      final java.lang.String strAccrualDC,
      final boolean bFullStub,
      final org.drip.analytics.daycount.DateAdjustParams dapEffective,
      final org.drip.analytics.daycount.DateAdjustParams dapMaturity,
      final org.drip.analytics.daycount.DateAdjustParams dapPeriodStart,
      final org.drip.analytics.daycount.DateAdjustParams dapPeriodEnd,
      final org.drip.analytics.daycount.DateAdjustParams dapAccrualStart,
      final org.drip.analytics.daycount.DateAdjustParams dapAccrualEnd,
      final org.drip.analytics.daycount.DateAdjustParams dapPay,
      final org.drip.analytics.daycount.DateAdjustParams dapReset,
      final org.drip.product.params.FactorSchedule notlSchedule,
      final double dblNotional,
      final java.lang.String strIR,
      final java.lang.String strCalendar)
      throws java.lang.Exception {
    if (null == (_strIR = strIR)
        || _strIR.isEmpty()
        || !org.drip.quant.common.NumberUtil.IsValid(_dblEffective = dblEffective)
        || !org.drip.quant.common.NumberUtil.IsValid(_dblMaturity = dblMaturity)
        || !org.drip.quant.common.NumberUtil.IsValid(_dblSpread = dblSpread)
        || null == (_fri = fri)
        || !org.drip.quant.common.NumberUtil.IsValid(_dblNotional = dblNotional))
      throw new java.lang.Exception("FloatingStream ctr => Invalid Input params! " + _fri);

    if (null == (_notlSchedule = notlSchedule))
      _notlSchedule = org.drip.product.params.FactorSchedule.CreateBulletSchedule();

    if (null
            == (_lsCouponPeriod =
                org.drip.analytics.period.CashflowPeriod.GeneratePeriodsBackward(
                    dblEffective, // Effective
                    dblMaturity, // Maturity
                    dapEffective, // Effective DAP
                    dapMaturity, // Maturity DAP
                    dapPeriodStart, // Period Start DAP
                    dapPeriodEnd, // Period End DAP
                    dapAccrualStart, // Accrual Start DAP
                    dapAccrualEnd, // Accrual End DAP
                    dapPay, // Pay DAP
                    dapReset, // Reset DAP
                    iFreq, // Coupon Freq
                    strCouponDC, // Coupon Day Count
                    _bApplyCpnEOMAdj,
                    strAccrualDC, // Accrual Day Count
                    _bApplyAccEOMAdj,
                    bFullStub, // Full First Coupon Period?
                    false, // Merge the first 2 Periods - create a long stub?
                    true,
                    strCalendar))
        || 0 == _lsCouponPeriod.size())
      throw new java.lang.Exception("FloatingStream ctr: Cannot generate Period Schedule");
  }
  @Override
  public boolean setCurves(
      final java.lang.String strIR, final java.lang.String strIRTSY, final java.lang.String strCC) {
    if (null == strIR || strIR.isEmpty()) return false;

    _strIR = strIR;
    return true;
  }
  /**
   * 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;
  }
 protected MarketSurface(
     final double dblEpochDate,
     final org.drip.state.identifier.CustomMetricLabel label,
     final java.lang.String strCurrency)
     throws java.lang.Exception {
   if (!org.drip.quant.common.NumberUtil.IsValid(_dblEpochDate = dblEpochDate)
       || null == (_label = label)
       || null == (_strCurrency = strCurrency)
       || _strCurrency.isEmpty())
     throw new java.lang.Exception("MarketSurface ctr: Invalid Inputs");
 }
  /**
   * De-serialize the FloatFloatComponent from the byte array
   *
   * @param ab Byte Array
   * @throws java.lang.Exception Thrown if the FloatFloatComponent cannot be de-serialized from the
   *     byte array
   */
  public FloatFloatComponent(final byte[] ab) throws java.lang.Exception {
    if (null == ab || 0 == ab.length)
      throw new java.lang.Exception("FloatFloatComponent de-serializer: Invalid input Byte array");

    java.lang.String strRawString = new java.lang.String(ab);

    if (null == strRawString || strRawString.isEmpty())
      throw new java.lang.Exception("FloatFloatComponent de-serializer: Empty state");

    java.lang.String strSerializedFloatFloatComponent =
        strRawString.substring(0, strRawString.indexOf(getObjectTrailer()));

    if (null == strSerializedFloatFloatComponent || strSerializedFloatFloatComponent.isEmpty())
      throw new java.lang.Exception("FloatFloatComponent de-serializer: Cannot locate state");

    java.lang.String[] astrField =
        org.drip.quant.common.StringUtil.Split(
            strSerializedFloatFloatComponent, getFieldDelimiter());

    if (null == astrField || 3 > astrField.length)
      throw new java.lang.Exception("FloatFloatComponent de-serializer: Invalid reqd field set");

    // double dblVersion = new java.lang.Double (astrField[0]).doubleValue();

    if (null == astrField[1] || astrField[1].isEmpty())
      throw new java.lang.Exception(
          "FloatFloatComponent de-serializer: Cannot locate visible floating stream");

    if (org.drip.service.stream.Serializer.NULL_SER_STRING.equalsIgnoreCase(astrField[1]))
      _floatReference = null;
    else _floatReference = new org.drip.product.rates.FloatingStream(astrField[1].getBytes());

    if (null == astrField[2] || astrField[2].isEmpty())
      throw new java.lang.Exception(
          "FloatFloatComponent de-serializer: Cannot locate work-out floating stream");

    if (org.drip.service.stream.Serializer.NULL_SER_STRING.equalsIgnoreCase(astrField[2]))
      _floatDerived = null;
    else _floatDerived = new org.drip.product.rates.FloatingStream(astrField[2].getBytes());
  }
 /**
  * RatesBasket constructor
  *
  * @param strName Basket Name
  * @param aCompFixedStream Array of Fixed Stream Components
  * @param aCompFloatStream Array of Float Stream Components
  * @throws java.lang.Exception Thrown if the inputs are invalid
  */
 public RatesBasket(
     final java.lang.String strName,
     final org.drip.product.rates.Stream[] aCompFixedStream,
     final org.drip.product.rates.Stream[] aCompFloatStream)
     throws java.lang.Exception {
   if (null == (_strName = strName)
       || _strName.isEmpty()
       || null == (_aCompFixedStream = aCompFixedStream)
       || 0 == _aCompFixedStream.length
       || null == (_aCompFloatStream = aCompFloatStream)
       || 0 == _aCompFloatStream.length)
     throw new java.lang.Exception("RatesBasket ctr => Invalid Inputs");
 }
  @Override
  public byte[] serialize() {
    java.lang.StringBuffer sb = new java.lang.StringBuffer();

    sb.append(org.drip.service.stream.Serializer.VERSION + getFieldDelimiter());

    sb.append(_dblNotional + getFieldDelimiter());

    if (null == _strIR || _strIR.isEmpty())
      sb.append(org.drip.service.stream.Serializer.NULL_SER_STRING + getFieldDelimiter());
    else sb.append(_strIR + getFieldDelimiter());

    if (null == _strCode || _strCode.isEmpty())
      sb.append(org.drip.service.stream.Serializer.NULL_SER_STRING + getFieldDelimiter());
    else sb.append(_strCode + getFieldDelimiter());

    if (null == _strDC || _strDC.isEmpty())
      sb.append(org.drip.service.stream.Serializer.NULL_SER_STRING + getFieldDelimiter());
    else sb.append(_strDC + getFieldDelimiter());

    if (null == _strCalendar || _strCalendar.isEmpty())
      sb.append(org.drip.service.stream.Serializer.NULL_SER_STRING + getFieldDelimiter());
    else sb.append(_strCalendar + getFieldDelimiter());

    sb.append(_dblMaturity + getFieldDelimiter());

    sb.append(_dblEffective + getFieldDelimiter());

    if (null == _notlSchedule)
      sb.append(org.drip.service.stream.Serializer.NULL_SER_STRING + getFieldDelimiter());
    else sb.append(new java.lang.String(_notlSchedule.serialize()) + getFieldDelimiter());

    if (null == _settleParams) sb.append(org.drip.service.stream.Serializer.NULL_SER_STRING);
    else sb.append(new java.lang.String(_settleParams.serialize()));

    return sb.append(getObjectTrailer()).toString().getBytes();
  }
  protected double getMeasure(
      final java.lang.String strMeasure,
      final org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double> mapCalc)
      throws java.lang.Exception {
    if (null == strMeasure || strMeasure.isEmpty() || null == mapCalc || null == mapCalc.entrySet())
      throw new java.lang.Exception("BasketProduct::getMeasure => Invalid Params");

    for (java.util.Map.Entry<java.lang.String, java.lang.Double> me : mapCalc.entrySet()) {
      if (null != me && null != me.getKey() && me.getKey().equalsIgnoreCase(strMeasure))
        return me.getValue();
    }

    throw new java.lang.Exception(
        "BasketProduct::getMeasure => " + strMeasure + " is an invalid measure!");
  }
  /**
   * De-serialization of DateAdjustParams from byte stream
   *
   * @param ab Byte stream
   * @throws java.lang.Exception Thrown if cannot properly de-serialize DateAdjustParams
   */
  public DateAdjustParams(final byte[] ab) throws java.lang.Exception {
    if (null == ab || 0 == ab.length)
      throw new java.lang.Exception("DateAdjustParams de-serialize: Invalid byte stream input");

    java.lang.String strRawString = new java.lang.String(ab);

    if (null == strRawString || strRawString.isEmpty())
      throw new java.lang.Exception("DateAdjustParams de-serializer: Empty state");

    java.lang.String strDAP = strRawString.substring(0, strRawString.indexOf(getObjectTrailer()));

    if (null == strDAP || strDAP.isEmpty())
      throw new java.lang.Exception("DateAdjustParams de-serializer: Cannot locate state");

    java.lang.String[] astrField =
        org.drip.analytics.support.GenericUtil.Split(strDAP, getFieldDelimiter());

    if (null == astrField || 3 > astrField.length)
      throw new java.lang.Exception("DateAdjustParams de-serialize: Invalid number of fields");

    // double dblVersion = new java.lang.Double (astrField[0]);

    if (null == astrField[1]
        || astrField[1].isEmpty()
        || org.drip.service.stream.Serializer.NULL_SER_STRING.equals(astrField[1]))
      throw new java.lang.Exception("DateAdjustParams de-serializer: Cannot locate roll mode");

    _iRollMode = new java.lang.Integer(astrField[1]).intValue();

    if (null == astrField[2]
        || astrField[2].isEmpty()
        || org.drip.service.stream.Serializer.NULL_SER_STRING.equals(astrField[2]))
      throw new java.lang.Exception("DateAdjustParams de-serializer: Cannot locate calendar");

    _strCalendar = astrField[2];
  }
Example #21
0
  /**
   * Prefix the keys in the input map, and return them in a new map
   *
   * @param mapIn Input map
   * @param strPrefix The prefix
   * @return Map containing the prefixed entries
   */
  public static final org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double>
      PrefixKeys(
          final org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double> mapIn,
          final java.lang.String strPrefix) {
    if (null == mapIn || null == mapIn.entrySet() || null == strPrefix || strPrefix.isEmpty())
      return null;

    org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double> mapOut =
        new org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double>();

    for (java.util.Map.Entry<java.lang.String, java.lang.Double> me : mapIn.entrySet()) {
      if (null != me.getKey() && !me.getKey().isEmpty())
        mapOut.put(strPrefix + me.getKey(), me.getValue());
    }

    return mapOut;
  }
  /**
   * Constructs a Cash Component
   *
   * @param dtEffective Effective Date
   * @param dtMaturity Maturity Date
   * @param strIR IR Curve
   * @param strDC Day Count
   * @param strCalendar Calendar
   * @throws java.lang.Exception Thrown if the inputs are invalid
   */
  public CashComponent(
      final org.drip.analytics.date.JulianDate dtEffective,
      final org.drip.analytics.date.JulianDate dtMaturity,
      final java.lang.String strIR,
      final java.lang.String strDC,
      final java.lang.String strCalendar)
      throws java.lang.Exception {
    if (null == dtEffective
        || null == dtMaturity
        || null == (_strIR = strIR)
        || strIR.isEmpty()
        || (_dblMaturity = dtMaturity.getJulian()) <= (_dblEffective = dtEffective.getJulian()))
      throw new java.lang.Exception("CashComponent ctr: Invalid Inputs!");

    _strDC = strDC;
    _strCalendar = strCalendar;

    _notlSchedule = org.drip.product.params.FactorSchedule.CreateBulletSchedule();
  }
  @Override
  public byte[] serialize() {
    java.lang.StringBuffer sb = new java.lang.StringBuffer();

    sb.append(
        org.drip.service.stream.Serializer.VERSION
            + getFieldDelimiter()
            + _iNoticePeriod
            + getFieldDelimiter()
            + _bIsPut
            + getFieldDelimiter()
            + _bFixToFloatOnExercise
            + getFieldDelimiter()
            + _dblFixToFloatSpread
            + getFieldDelimiter()
            + _dblFixToFloatExerciseDate
            + getFieldDelimiter());

    if (null == _strFloatIndex || _strFloatIndex.isEmpty())
      sb.append(org.drip.service.stream.Serializer.NULL_SER_STRING + getFieldDelimiter());
    else sb.append(_strFloatIndex + getFieldDelimiter());

    if (null == _adblDate
        || 0 == _adblDate.length
        || null == _adblFactor
        || 0 == _adblFactor.length) sb.append(org.drip.service.stream.Serializer.NULL_SER_STRING);
    else {
      java.lang.StringBuffer sbEOS = new java.lang.StringBuffer();

      for (int i = 0; i < _adblDate.length; ++i) {
        if (0 != i) sbEOS.append(getCollectionRecordDelimiter());

        sbEOS.append(_adblDate[i] + getCollectionKeyValueDelimiter() + _adblFactor[i]);
      }

      if (sbEOS.toString().isEmpty()) sb.append(org.drip.service.stream.Serializer.NULL_SER_STRING);
      else sb.append(sbEOS.toString());
    }

    return sb.append(getObjectTrailer()).toString().getBytes();
  }
  private static final org.w3c.dom.Document GetNormalizedXMLDoc(final java.lang.String strXMLFile) {
    if (null == strXMLFile || strXMLFile.isEmpty()) return null;

    org.w3c.dom.Document doc = null;

    try {
      doc =
          javax.xml.parsers.DocumentBuilderFactory.newInstance()
              .newDocumentBuilder()
              .parse(new java.io.File(strXMLFile));
    } catch (java.lang.Exception e) {
      e.printStackTrace();

      return null;
    }

    if (null == doc || null == doc.getDocumentElement()) return null;

    doc.getDocumentElement().normalize();

    return doc;
  }
  /**
   * Set the index short name
   *
   * @param strShortName Index Short Name
   * @return TRUE if successful
   */
  public boolean setShortName(final java.lang.String strShortName) {
    if (null == (_strShortName = strShortName) || _strShortName.isEmpty()) return false;

    return true;
  }
  /**
   * Set the Index BBG Ticker
   *
   * @param strBBGTicker Index BBG Ticker
   * @return TRUE if successful
   */
  public boolean setBBGTicker(final java.lang.String strBBGTicker) {
    if (null == (_strBBGTicker = strBBGTicker) || strBBGTicker.isEmpty()) return false;

    return true;
  }
  /**
   * Set the Index Location
   *
   * @param strLocation Index Location
   * @return TRUE if successful
   */
  public boolean setLocation(final java.lang.String strLocation) {
    if (null == (_strLocation = strLocation) || _strLocation.isEmpty()) return false;

    return true;
  }
  /**
   * Set the Index Composite Curve ID
   *
   * @param strCurvyCurveID Index Composite Curve ID
   * @return TRUE if successful
   */
  public boolean setCurvyCurveID(final java.lang.String strCurvyCurveID) {
    if (null == (_strCurvyCurveID = strCurvyCurveID) || _strCurvyCurveID.isEmpty()) return false;

    return true;
  }
  /**
   * Set the Index Class
   *
   * @param strIndexClass Index Class
   * @return TRUE if successful
   */
  public boolean setIndexClass(final java.lang.String strIndexClass) {
    if (null == (_strIndexClass = strIndexClass) || _strIndexClass.isEmpty()) return false;

    return true;
  }
  /**
   * Set the Index Day Count
   *
   * @param strDayCount Index Day Count
   * @return TRUE if successful
   */
  public boolean setDayCount(final java.lang.String strDayCount) {
    if (null == (_strDayCount = strDayCount) || _strDayCount.isEmpty()) return false;

    return true;
  }