Beispiel #1
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);
  }
  /**
   * 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!");
  }
Beispiel #4
0
  /**
   * Turn a flattened 4D (string, string, string, double) string sequence into its corresponding map
   *
   * @param str4DMap Flattened 4D array input
   * @param strMultiLevelKeyDelimiter Multi-level key delimiter string
   * @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, [String, [String, double]]] map
   */
  public static final org.drip.analytics.support.CaseInsensitiveTreeMap<
          org.drip.analytics.support.CaseInsensitiveTreeMap<
              org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double>>>
      FlatStringTo4DSDMap(
          final java.lang.String str4DMap,
          final java.lang.String strMultiLevelKeyDelimiter,
          final java.lang.String strKVDelimiter,
          final java.lang.String strRecordDelimiter,
          final boolean bSkipNullValue,
          final java.lang.String strNULLString) {
    if (null == str4DMap
        || str4DMap.isEmpty()
        || null == strNULLString
        || strNULLString.isEmpty()
        || strNULLString.equalsIgnoreCase(str4DMap)
        || null == strKVDelimiter
        || strKVDelimiter.isEmpty()
        || null == strRecordDelimiter
        || strRecordDelimiter.isEmpty()) return null;

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

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

    org.drip.analytics.support.CaseInsensitiveTreeMap<
            org.drip.analytics.support.CaseInsensitiveTreeMap<
                org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double>>>
        map4D =
            new org.drip.analytics.support.CaseInsensitiveTreeMap<
                org.drip.analytics.support.CaseInsensitiveTreeMap<
                    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[] astrKVPairOut =
          org.drip.math.common.StringUtil.Split(astrRecord[i], strKVDelimiter);

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

      java.lang.String[] astrKeySet =
          org.drip.math.common.StringUtil.Split(astrKVPairOut[0], strMultiLevelKeyDelimiter);

      if (null == astrKeySet
          || 3 != astrKeySet.length
          || null == astrKeySet[0]
          || astrKeySet[0].isEmpty()
          || strNULLString.equalsIgnoreCase(astrKeySet[0])
          || null == astrKeySet[1]
          || astrKeySet[1].isEmpty()
          || strNULLString.equalsIgnoreCase(astrKeySet[1])
          || null == astrKeySet[2]
          || astrKeySet[2].isEmpty()
          || strNULLString.equalsIgnoreCase(astrKeySet[2])) continue;

      org.drip.analytics.support.CaseInsensitiveTreeMap<
              org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double>>
          map3D = map4D.get(astrKeySet[0]);

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

      org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double> map2D =
          map3D.get(astrKeySet[1]);

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

      map2D.put(astrKeySet[2], new java.lang.Double(astrKVPairOut[1]));

      map3D.put(astrKeySet[1], map2D);

      map4D.put(astrKeySet[0], map3D);
    }

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

    return map4D;
  }
  /**
   * EmbeddedOptionSchedule de-serialization from input byte array
   *
   * @param ab Byte Array
   * @throws java.lang.Exception Thrown if EmbeddedOptionSchedule cannot be properly de-serialized
   */
  public EmbeddedOptionSchedule(final byte[] ab) throws java.lang.Exception {
    if (null == ab || 0 == ab.length)
      throw new java.lang.Exception(
          "EmbeddedOptionSchedule 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("EmbeddedOptionSchedule de-serializer: Empty state");

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

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

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

    if (null == astrField || 8 > astrField.length)
      throw new java.lang.Exception("EmbeddedOptionSchedule 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(
          "EmbeddedOptionSchedule de-serializer: Cannot locate notice period");

    _iNoticePeriod = new java.lang.Integer(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("EmbeddedOptionSchedule de-serializer: Cannot locate Put flag");

    _bIsPut = 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(
          "EmbeddedOptionSchedule de-serializer: Cannot locate fix-to-float-on-exercise flag");

    _bFixToFloatOnExercise = new java.lang.Boolean(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(
          "EmbeddedOptionSchedule de-serializer: Cannot locate fix-to-float-on-exercise flag");

    _dblFixToFloatSpread = new java.lang.Double(astrField[4]);

    if (null == astrField[5]
        || astrField[5].isEmpty()
        || org.drip.service.stream.Serializer.NULL_SER_STRING.equalsIgnoreCase(astrField[5]))
      throw new java.lang.Exception(
          "EmbeddedOptionSchedule de-serializer: Cannot locate fix-to-float exercise date");

    _dblFixToFloatExerciseDate = new java.lang.Double(astrField[5]).doubleValue();

    if (null == astrField[6] || astrField[6].isEmpty())
      throw new java.lang.Exception(
          "EmbeddedOptionSchedule de-serializer: Cannot locate float index");

    if (org.drip.service.stream.Serializer.NULL_SER_STRING.equalsIgnoreCase(astrField[6]))
      _strFloatIndex = "";
    else _strFloatIndex = astrField[6];

    if (null == astrField[7]
        || astrField[7].isEmpty()
        || org.drip.service.stream.Serializer.NULL_SER_STRING.equalsIgnoreCase(astrField[7]))
      throw new java.lang.Exception("EmbeddedOptionSchedule de-serializer: Cannot decode state");

    java.util.List<java.lang.Double> lsdblDate = new java.util.ArrayList<java.lang.Double>();

    java.util.List<java.lang.Double> lsdblFactor = new java.util.ArrayList<java.lang.Double>();

    if (!org.drip.math.common.StringUtil.KeyValueListFromStringArray(
        lsdblDate,
        lsdblFactor,
        astrField[7],
        getCollectionRecordDelimiter(),
        getCollectionKeyValueDelimiter()))
      throw new java.lang.Exception(
          "EmbeddedOptionSchedule de-serializer: Cannot decode hazard state");

    if (0 == lsdblDate.size() || 0 == lsdblFactor.size() || lsdblDate.size() != lsdblFactor.size())
      throw new java.lang.Exception(
          "EmbeddedOptionSchedule de-serializer: Cannot decode hazard state");

    _adblDate = new double[lsdblDate.size()];

    _adblFactor = new double[lsdblFactor.size()];

    for (int i = 0; i < _adblFactor.length; ++i) {
      _adblDate[i] = lsdblDate.get(i);

      _adblFactor[i] = lsdblFactor.get(i);
    }
  }