Exemplo n.º 1
0
  @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();
  }
Exemplo n.º 2
0
  @Override
  public double getNotional(final double dblDate) throws java.lang.Exception {
    if (null == _notlSchedule || !org.drip.quant.common.NumberUtil.IsValid(dblDate))
      throw new java.lang.Exception("FloatingStream::getNotional => Bad date into getNotional");

    return _notlSchedule.getFactor(dblDate);
  }
Exemplo n.º 3
0
  /**
   * 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");
  }
Exemplo n.º 4
0
  @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);
  }
Exemplo n.º 5
0
  /**
   * 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();
  }
Exemplo n.º 6
0
  @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();
  }