Exemplo n.º 1
1
  /**
   * Print the Contents of the 2D Array Triplet
   *
   * @param strLeftLabel Left Label
   * @param strMiddleLabel Middle Label
   * @param strRightLabel Right Label
   * @param aadblLeft The Left 2D array
   * @param aadblMiddle The Middle 2D array
   * @param aadblRight The Right 2D array
   * @param bBailOnNaN Bail on encountering an NaN
   * @return TRUE => Print Successful
   */
  public static final boolean Print2DArrayTriplet(
      final java.lang.String strLeftLabel,
      final java.lang.String strMiddleLabel,
      final java.lang.String strRightLabel,
      final double[][] aadblLeft,
      final double[][] aadblMiddle,
      final double[][] aadblRight,
      final boolean bBailOnNaN) {
    if (null == aadblLeft || null == aadblMiddle || null == aadblRight) return false;

    int iSize = aadblLeft.length;

    if (0 == iSize || iSize != aadblMiddle.length || iSize != aadblRight.length) return false;

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

        System.out.println(
            strLeftLabel
                + "["
                + i
                + "]["
                + j
                + "] = "
                + org.drip.quant.common.FormatUtil.FormatDouble(aadblLeft[i][j], 1, 6, 1.)
                + "  |  "
                + strMiddleLabel
                + "["
                + i
                + "]["
                + j
                + "] = "
                + org.drip.quant.common.FormatUtil.FormatDouble(aadblMiddle[i][j], 1, 6, 1.)
                + "  |  "
                + strRightLabel
                + "["
                + i
                + "]["
                + j
                + "] = "
                + org.drip.quant.common.FormatUtil.FormatDouble(aadblRight[i][j], 1, 6, 1.));
      }
    }

    return true;
  }
  /**
   * Apply the Turns' DF Adjustment
   *
   * @param dblStartDate Turn Start Date
   * @param dblFinishDate Turn Finish Date
   * @return Turns' DF Adjustment
   * @throws java.lang.Exception Thrown if the Inputs are invalid
   */
  public double turnAdjust(final double dblStartDate, final double dblFinishDate)
      throws java.lang.Exception {
    if (null == _lsTurn || 0 == _lsTurn.size()) return 1.;

    if (!org.drip.quant.common.NumberUtil.IsValid(dblStartDate)
        || !org.drip.quant.common.NumberUtil.IsValid(dblFinishDate))
      throw new java.lang.Exception(
          "TurnListDiscountFactor::turnAdjust => Invalid Adjustment Date");

    if (dblStartDate >= dblFinishDate) return 1.;

    double dblTurnAdjust = 1.;

    for (org.drip.analytics.rates.Turn turn : _lsTurn) {
      if (null == turn || dblStartDate >= turn.finish() || dblFinishDate <= turn.start()) continue;

      double dblEffectiveStart = turn.start() > dblStartDate ? turn.start() : dblStartDate;

      double dblEffectiveFinish = turn.finish() < dblFinishDate ? turn.finish() : dblFinishDate;

      dblTurnAdjust *=
          java.lang.Math.exp(turn.spread() * (dblEffectiveStart - dblEffectiveFinish) / 365.25);
    }

    return dblTurnAdjust;
  }
  /**
   * 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;
  }
  /**
   * Create a CreditCurve instance from a single node hazard rate
   *
   * @param dblStartDate Curve epoch date
   * @param strName Credit Curve Name
   * @param strCurrency Currency
   * @param dblHazardRate Curve hazard rate
   * @param dblRecovery Curve recovery
   * @return CreditCurve instance
   */
  public static final org.drip.analytics.definition.ExplicitBootCreditCurve FromFlatHazard(
      final double dblStartDate,
      final java.lang.String strName,
      final java.lang.String strCurrency,
      final double dblHazardRate,
      final double dblRecovery) {
    if (!org.drip.quant.common.NumberUtil.IsValid(dblStartDate)
        || !org.drip.quant.common.NumberUtil.IsValid(dblHazardRate)
        || !org.drip.quant.common.NumberUtil.IsValid(dblRecovery)) return null;

    double[] adblHazard = new double[1];
    double[] adblRecovery = new double[1];
    double[] adblHazardDate = new double[1];
    double[] adblRecoveryDate = new double[1];
    adblHazard[0] = dblHazardRate;
    adblRecovery[0] = dblRecovery;
    adblHazardDate[0] = dblStartDate;
    adblRecoveryDate[0] = dblStartDate;

    try {
      return new org.drip.state.curve.ForwardHazardCreditCurve(
          dblStartDate,
          org.drip.state.identifier.CreditLabel.Standard(strName),
          strCurrency,
          adblHazard,
          adblHazardDate,
          adblRecovery,
          adblRecoveryDate,
          java.lang.Double.NaN);
    } catch (java.lang.Exception e) {
      e.printStackTrace();
    }

    return null;
  }
Exemplo n.º 5
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.º 6
0
  /**
   * Constructs the ExerciseInfo from the work-out date, type, and the exercise factor
   *
   * @param dblDate Work-out Date
   * @param dblExerciseFactor Work-out Factor
   * @param iWOType Work out Type
   * @throws java.lang.Exception Thrown if input is invalid
   */
  public ExerciseInfo(final double dblDate, final double dblExerciseFactor, final int iWOType)
      throws java.lang.Exception {
    if (!org.drip.quant.common.NumberUtil.IsValid(_dblDate = dblDate)
        || !org.drip.quant.common.NumberUtil.IsValid(_dblExerciseFactor = dblExerciseFactor))
      throw new java.lang.Exception("ExerciseInfo ctr: Invalid Inputs!");

    _iWOType = iWOType;
  }
  @Override
  public double integrate(final double dblBegin, final double dblEnd) throws java.lang.Exception {
    if (!org.drip.quant.common.NumberUtil.IsValid(dblBegin)
        || !org.drip.quant.common.NumberUtil.IsValid(dblEnd))
      throw new java.lang.Exception("NaturalLogSeriesElement::integrate => Invalid Inputs");

    return (java.lang.Math.pow(dblEnd, _iExponent) - java.lang.Math.pow(dblBegin, _iExponent))
        / org.drip.quant.common.NumberUtil.Factorial(_iExponent + 1);
  }
  @Override
  public double integrate(final double dblBegin, final double dblEnd) throws java.lang.Exception {
    if (!org.drip.quant.common.NumberUtil.IsValid(dblBegin)
        || !org.drip.quant.common.NumberUtil.IsValid(dblEnd))
      throw new java.lang.Exception(
          "CalibratableMultiSegmentSequence::integrate => Invalid Inputs");

    return org.drip.quant.calculus.R1ToR1Integrator.Boole(this, dblBegin, dblEnd);
  }
Exemplo n.º 9
0
  @Override
  public double getNotional(final double dblDate1, final double dblDate2)
      throws java.lang.Exception {
    if (null == _notlSchedule
        || !org.drip.quant.common.NumberUtil.IsValid(dblDate1)
        || !org.drip.quant.common.NumberUtil.IsValid(dblDate2))
      throw new java.lang.Exception("FloatingStream::getNotional => Bad date into getNotional");

    return _notlSchedule.getFactor(dblDate1, dblDate2);
  }
 /**
  * Construct CreditCurveScenarioContainer from the array of calibration instruments, the coupon
  * bump parameter, and the recovery bump parameter
  *
  * @param aCalibInst Array of calibration instruments
  * @param dblCouponBump Coupon Bump
  * @param dblRecoveryBump Recovery Bump
  * @throws java.lang.Exception Thrown if inputs are invalid
  */
 public CreditCurveScenarioContainer(
     final org.drip.product.definition.CalibratableComponent[] aCalibInst,
     final double dblCouponBump,
     final double dblRecoveryBump)
     throws java.lang.Exception {
   if (null == aCalibInst
       || 0 == aCalibInst.length
       || !org.drip.quant.common.NumberUtil.IsValid(_dblCouponBump = dblCouponBump)
       || !org.drip.quant.common.NumberUtil.IsValid(_dblRecoveryBump = dblRecoveryBump)
       || null == (_ccsg = new org.drip.state.estimator.CreditCurveScenarioGenerator(aCalibInst)))
     throw new java.lang.Exception("CreditCurveScenarioContainer ctr => Invalid Inputs!");
 }
  @Override
  public double forward(final double dblDate1, final double dblDate2) throws java.lang.Exception {
    if (!org.drip.quant.common.NumberUtil.IsValid(dblDate1)
        || !org.drip.quant.common.NumberUtil.IsValid(dblDate2))
      throw new java.lang.Exception(
          "NonlinearDiscountFactorDiscountCurve::forward => Invalid input");

    double dblStartDate = epoch().julian();

    if (dblDate1 < dblStartDate || dblDate2 < dblStartDate) return 0.;

    return 365.25 / (dblDate2 - dblDate1) * java.lang.Math.log(df(dblDate1) / df(dblDate2));
  }
Exemplo n.º 12
0
  @Override
  public double getCoupon(
      final double dblValueDate, final org.drip.param.definition.ComponentMarketParams mktParams)
      throws java.lang.Exception {
    if (!org.drip.quant.common.NumberUtil.IsValid(dblValueDate) || null == mktParams)
      throw new java.lang.Exception("FloatingStream::getCoupon => Invalid Inputs");

    org.drip.analytics.period.Period currentPeriod = null;

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

      if (dblValueDate >= period.getStartDate() && dblValueDate < period.getEndDate()) {
        currentPeriod = period;
        break;
      }
    }

    if (null == currentPeriod)
      throw new java.lang.Exception("FloatingStream::getCoupon => Invalid Inputs");

    java.util.Map<
            org.drip.analytics.date.JulianDate,
            org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double>>
        mapFixings = mktParams.getFixings();

    if (null != mapFixings) {
      double dblCurrentResetDate = currentPeriod.getResetDate();

      if (org.drip.quant.common.NumberUtil.IsValid(dblCurrentResetDate)) {
        org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double> mapIndexFixing =
            mapFixings.get(new org.drip.analytics.date.JulianDate(dblCurrentResetDate));

        if (null != mapIndexFixing) {
          java.lang.Double dblFixing = mapIndexFixing.get(_fri.fullyQualifiedName());

          if (null != dblFixing) return dblFixing + _dblSpread;
        }
      }
    }

    org.drip.analytics.rates.DiscountCurve dc = mktParams.getDiscountCurve();

    if (null == dc)
      throw new java.lang.Exception("FloatingStream::getCoupon => cant determine index");

    return dc.libor(currentPeriod.getStartDate(), currentPeriod.getEndDate()) + _dblSpread;
  }
Exemplo n.º 13
0
  @Override
  public org.drip.analytics.definition.Curve shiftManifestMeasure(
      final int iSpanIndex, final java.lang.String strManifestMeasure, final double dblShift) {
    int iNumBasis = _adblFXBasis.length;

    if (iSpanIndex >= iNumBasis || !org.drip.quant.common.NumberUtil.IsValid(dblShift)) return null;

    double[] adblFXBasisBumped = new double[iNumBasis];

    for (int i = 0; i < iNumBasis; ++i)
      adblFXBasisBumped[i] = _adblFXBasis[i] + (i == iSpanIndex ? dblShift : 0.);

    try {
      return new DerivedFXBasis(
          _cp,
          new org.drip.analytics.date.JulianDate(_dblSpotDate),
          _dblFXSpot,
          _adblDate,
          adblFXBasisBumped,
          _bIsFXBasisBootstrapped);
    } catch (java.lang.Exception e) {
      e.printStackTrace();
    }

    return null;
  }
  /**
   * Create a credit curve from an array of dates and hazard rates
   *
   * @param dtStart Curve epoch date
   * @param strName Credit Curve Name
   * @param strCurrency Currency
   * @param adblDate Array of dates
   * @param adblHazardRate Array of hazard rates
   * @param dblRecovery Recovery
   * @return CreditCurve instance
   */
  public static final org.drip.analytics.definition.ExplicitBootCreditCurve CreateCreditCurve(
      final org.drip.analytics.date.JulianDate dtStart,
      final java.lang.String strName,
      final java.lang.String strCurrency,
      final double[] adblDate,
      final double[] adblHazardRate,
      final double dblRecovery) {
    if (null == dtStart
        || null == adblHazardRate
        || null == adblDate
        || adblHazardRate.length != adblDate.length
        || !org.drip.quant.common.NumberUtil.IsValid(dblRecovery)) return null;

    try {
      double[] adblRecovery = new double[1];
      double[] adblRecoveryDate = new double[1];
      adblRecovery[0] = dblRecovery;

      adblRecoveryDate[0] = dtStart.julian();

      return new org.drip.state.curve.ForwardHazardCreditCurve(
          dtStart.julian(),
          org.drip.state.identifier.CreditLabel.Standard(strName),
          strCurrency,
          adblHazardRate,
          adblDate,
          adblRecovery,
          adblRecoveryDate,
          java.lang.Double.NaN);
    } catch (java.lang.Exception e) {
      e.printStackTrace();
    }

    return null;
  }
  @Override
  public boolean setNodeValue(final int iNodeIndex, final double dblNodeDF) {
    if (!org.drip.quant.common.NumberUtil.IsValid(dblNodeDF)) return false;

    int iNumDate = _adblDate.length;

    if (iNodeIndex > iNumDate) return false;

    if (0 == iNodeIndex) {
      _dblLeftFlatForwardRate =
          -365.25 * java.lang.Math.log(_dblLeftNodeDF = dblNodeDF) / (_adblDate[0] - _dblEpochDate);

      return true;
    }

    if (1 == iNodeIndex)
      return _msr.setLeftNode(_dblLeftNodeDF, _dblLeftNodeDFSlope, dblNodeDF, null);

    if (iNumDate - 1 == iNodeIndex) {
      try {
        _dblRightFlatForwardRate =
            -365.25
                * java.lang.Math.log(_msr.responseValue(_adblDate[iNodeIndex]))
                / (_adblDate[iNodeIndex] - _dblEpochDate);
      } catch (java.lang.Exception e) {
        e.printStackTrace();

        return false;
      }
    }

    return _msr.resetNode(iNodeIndex, dblNodeDF);
  }
  @Override
  public org.drip.quant.calculus.WengertJacobian jackDDFDManifestMeasure(
      final double dblDate, final java.lang.String strManifestMeasure) {
    if (!org.drip.quant.common.NumberUtil.IsValid(dblDate)) return null;

    org.drip.quant.calculus.WengertJacobian wj = null;

    try {
      wj = new org.drip.quant.calculus.WengertJacobian(1, _adblDate.length);
    } catch (java.lang.Exception e) {
      e.printStackTrace();

      return null;
    }

    for (int i = 0; i < _adblDate.length; ++i) {
      if (!wj.accumulatePartialFirstDerivative(0, i, 0.)) return null;
    }

    if (dblDate <= _dblEpochDate) return wj;

    if (dblDate <= _adblDate[0]) {
      try {
        return wj.accumulatePartialFirstDerivative(
                0,
                0,
                (dblDate - _dblEpochDate)
                    / (_adblDate[0] - _dblEpochDate)
                    * java.lang.Math.exp(
                        _dblLeftFlatForwardRate * (_adblDate[0] - dblDate) / 365.25))
            ? wj
            : null;
      } catch (java.lang.Exception e) {
        e.printStackTrace();

        return null;
      }
    }

    if (dblDate <= _adblDate[_adblDate.length - 1])
      return _msr.jackDResponseDCalibrationInput(dblDate, 1);

    try {
      return wj.accumulatePartialFirstDerivative(
              0,
              _adblDate.length - 1,
              (dblDate - _dblEpochDate)
                  / (_adblDate[_adblDate.length - 1] - _dblEpochDate)
                  * java.lang.Math.exp(
                      _dblRightFlatForwardRate
                          * (_adblDate[_adblDate.length - 1] - dblDate)
                          / 365.25))
          ? wj
          : null;
    } catch (java.lang.Exception e) {
      e.printStackTrace();
    }

    return null;
  }
Exemplo n.º 17
0
  /**
   * MultiSidedQuote Constructor: Constructs a Quote object from the quote size/value and the side
   * string.
   *
   * @param strSide bid/ask/mid
   * @param dblQuote Quote Value
   * @param dblSize Size
   * @throws java.lang.Exception Thrown on invalid inputs
   */
  public MultiSidedQuote(final String strSide, final double dblQuote, final double dblSize)
      throws java.lang.Exception {
    if (null == strSide || strSide.isEmpty() || !org.drip.quant.common.NumberUtil.IsValid(dblQuote))
      throw new java.lang.Exception("MultiSidedQuote ctr: Invalid Side/Quote/Size!");

    _mapSidedQuote.put(strSide, new SidedQuote(dblQuote, dblSize));
  }
  /**
   * Create a Calibrated Stretch Instance from the Array of Predictor Ordinates and a flat Response
   * Value
   *
   * @param strName Name of the Stretch
   * @param adblPredictorOrdinate Predictor Ordinate Array
   * @param dblResponseValue Response Value
   * @param scbc Segment Builder Parameters - One per Segment
   * @param sbfr Stretch Fitness Weighted Response
   * @param bs The Calibration Boundary Condition
   * @param iCalibrationDetail The Calibration Detail
   * @return Stretch Instance
   */
  public static final org.drip.spline.stretch.MultiSegmentSequence CreateCalibratedStretchEstimator(
      final java.lang.String strName,
      final double[] adblPredictorOrdinate,
      final double dblResponseValue,
      final org.drip.spline.params.SegmentCustomBuilderControl scbc,
      final org.drip.spline.params.StretchBestFitResponse sbfr,
      final org.drip.spline.stretch.BoundarySettings bs,
      final int iCalibrationDetail) {
    if (!org.drip.quant.common.NumberUtil.IsValid(dblResponseValue)
        || null == adblPredictorOrdinate
        || null == scbc) return null;

    int iNumPredictorOrdinate = adblPredictorOrdinate.length;

    if (1 >= iNumPredictorOrdinate) return null;

    double[] adblResponseValue = new double[iNumPredictorOrdinate];
    org.drip.spline.params.SegmentCustomBuilderControl[] aSCBC =
        new org.drip.spline.params.SegmentCustomBuilderControl[iNumPredictorOrdinate - 1];

    for (int i = 0; i < iNumPredictorOrdinate; ++i) {
      adblResponseValue[i] = dblResponseValue;

      if (0 != i) aSCBC[i - 1] = scbc;
    }

    return CreateCalibratedStretchEstimator(
        strName, adblPredictorOrdinate, adblResponseValue, aSCBC, sbfr, bs, iCalibrationDetail);
  }
  /**
   * Create a CreditCurve instance from the input array of survival probabilities
   *
   * @param dblStartDate Start Date
   * @param strName Credit Curve Name
   * @param strCurrency Currency
   * @param adblSurvivalDate Array of dates
   * @param adblSurvivalProbability Array of survival probabilities
   * @param dblRecovery Recovery
   * @return CreditCurve instance
   */
  public static final org.drip.analytics.definition.ExplicitBootCreditCurve FromSurvival(
      final double dblStartDate,
      final java.lang.String strName,
      final java.lang.String strCurrency,
      final double[] adblSurvivalDate,
      final double[] adblSurvivalProbability,
      final double dblRecovery) {
    if (!org.drip.quant.common.NumberUtil.IsValid(dblRecovery)) return null;

    try {
      double dblSurvivalBegin = 1.;
      double dblPeriodBegin = dblStartDate;
      double[] adblHazard = new double[adblSurvivalProbability.length];
      double[] adblRecovery = new double[1];
      double[] adblRecoveryDate = new double[1];
      adblRecovery[0] = dblRecovery;
      adblRecoveryDate[0] = dblStartDate;

      for (int i = 0; i < adblSurvivalProbability.length; ++i) {
        if (!org.drip.quant.common.NumberUtil.IsValid(adblSurvivalProbability[i])
            || adblSurvivalDate[i] <= dblPeriodBegin
            || dblSurvivalBegin <= adblSurvivalProbability[i]) return null;

        adblHazard[i] =
            365.25
                / (adblSurvivalDate[i] - dblPeriodBegin)
                * java.lang.Math.log(dblSurvivalBegin / adblSurvivalProbability[i]);

        dblPeriodBegin = adblSurvivalDate[i];
        dblSurvivalBegin = adblSurvivalProbability[i];
      }

      return new org.drip.state.curve.ForwardHazardCreditCurve(
          dblStartDate,
          org.drip.state.identifier.CreditLabel.Standard(strName),
          strCurrency,
          adblHazard,
          adblSurvivalDate,
          adblRecovery,
          adblRecoveryDate,
          java.lang.Double.NaN);
    } catch (java.lang.Exception e) {
      e.printStackTrace();
    }

    return null;
  }
  @Override
  public boolean setup(
      final org.drip.spline.stretch.SegmentSequenceBuilder ssb, final int iCalibrationDetail) {
    if (null == (_ssb = ssb) || !_ssb.setStretch(this)) return false;

    if (org.drip.spline.stretch.BoundarySettings.BOUNDARY_CONDITION_FLOATING
        == _ssb.getCalibrationBoundaryCondition().boundaryCondition()) {
      if (!_ssb.calibStartingSegment(0.)
          || !_ssb.calibSegmentSequence(1)
          || !_ssb.manifestMeasureSensitivity(0.)) return false;
    } else if (0 != (org.drip.spline.stretch.MultiSegmentSequence.CALIBRATE & iCalibrationDetail)) {
      org.drip.function.solverR1ToR1.FixedPointFinderOutput fpop = null;

      if (null == fpop || !fpop.containsRoot()) {
        try {
          fpop =
              new org.drip.function.solverR1ToR1.FixedPointFinderZheng(0., this, true).findRoot();
        } catch (java.lang.Exception e) {
          e.printStackTrace();

          return false;
        }
      }

      if (null == fpop
          || !org.drip.quant.common.NumberUtil.IsValid(fpop.getRoot())
          || !_ssb.manifestMeasureSensitivity(0.)) {
        System.out.println("FPOP: " + fpop);

        return false;
      }
    }

    if (0
        != (org.drip.spline.stretch.MultiSegmentSequence.CALIBRATE_JACOBIAN & iCalibrationDetail)) {
      int iNumSegment = _aLSRM.length;

      try {
        if (null
            == (_wjDCoeffDEdgeParams =
                new org.drip.quant.calculus.WengertJacobian(
                    _aLSRM[0].basisEvaluator().numBasis(), iNumSegment + 1))) return false;
      } catch (java.lang.Exception e) {
        e.printStackTrace();

        return false;
      }

      org.drip.quant.calculus.WengertJacobian wjHead = _aLSRM[0].jackDCoeffDEdgeInputs();

      if (!setDCoeffDEdgeParams(0, wjHead) || !setDCoeffDEdgeParams(1, wjHead)) return false;

      for (int i = 1; i < iNumSegment; ++i) {
        if (!setDCoeffDEdgeParams(i + 1, _aLSRM[i].jackDCoeffDEdgeInputs())) return false;
      }
    }

    return true;
  }
Exemplo n.º 21
0
    SidedQuote(final double dblQuote, final double dblSize) throws java.lang.Exception {
      if (!org.drip.quant.common.NumberUtil.IsValid(_dblQuote = dblQuote))
        throw new java.lang.Exception("MultiSidedQuote::SidedQuote ctr: Invalid Inputs!");

      _dblSize = dblSize;

      _dt = new org.drip.analytics.date.DateTime();
    }
Exemplo n.º 22
0
  /**
   * IteratedVariate constructor
   *
   * @param eiop Execution Initialization Output
   * @param dblOF Objective Function Value
   * @throws java.lang.Exception Thrown if inputs are invalid
   */
  public IteratedVariate(
      final org.drip.quant.solver1D.ExecutionInitializationOutput eiop, final double dblOF)
      throws java.lang.Exception {
    if (null == eiop || !org.drip.quant.common.NumberUtil.IsValid(_dblOF = dblOF))
      throw new java.lang.Exception("IteratedVariate constructor: Invalid Inputs");

    _dblVariate = eiop.getStartingVariate();
  }
  @Override
  public boolean in(final double dblPredictorOrdinate) throws java.lang.Exception {
    if (!org.drip.quant.common.NumberUtil.IsValid(dblPredictorOrdinate))
      throw new java.lang.Exception("CalibratableMultiSegmentSequence::in => Invalid inputs");

    return dblPredictorOrdinate >= getLeftPredictorOrdinateEdge()
        && dblPredictorOrdinate <= getRightPredictorOrdinateEdge();
  }
  /**
   * Calculate and return the variate infinitesimal
   *
   * @param dblVariate Variate Input
   * @return Variate Infinitesimal
   */
  public double getVariateInfinitesimal(final double dblVariate) throws java.lang.Exception {
    if (!org.drip.quant.common.NumberUtil.IsValid(dblVariate))
      throw new java.lang.Exception("DerivativeControl::getVariateInfinitesimal => Invalid input");

    double dblVariateInfinitesimal = dblVariate * getBumpFactor();

    if (java.lang.Math.abs(dblVariateInfinitesimal) < ABSOLUTE_INCREMENT) return ABSOLUTE_INCREMENT;

    return dblVariateInfinitesimal;
  }
  /**
   * SegmentBasisFunctionSet constructor
   *
   * @param iNumBasisToUse Number of Basis in the Hat Basis Set to Use
   * @param dblTension Tension Parameter
   * @param aAUHat The Hat Representation Function Set
   * @throws java.lang.Exception Thrown if the inputs are invalid
   */
  public SegmentBasisFunctionSet(
      final int iNumBasisToUse,
      final double dblTension,
      final org.drip.quant.function1D.AbstractUnivariate[] aAUHat)
      throws java.lang.Exception {
    super(responseBasis(iNumBasisToUse, aAUHat));

    if (!org.drip.quant.common.NumberUtil.IsValid(_dblTension = dblTension))
      throw new java.lang.Exception("SegmentBasisFunctionSet ctr: Invalid Inputs!");
  }
  @Override
  public boolean resetNode(final int iPredictorOrdinateIndex, final double dblResponseReset) {
    if (0 == iPredictorOrdinateIndex
        || 1 == iPredictorOrdinateIndex
        || _aLSRM.length < iPredictorOrdinateIndex
        || !org.drip.quant.common.NumberUtil.IsValid(dblResponseReset)) return false;

    return _aLSRM[iPredictorOrdinateIndex - 1].calibrate(
        _aLSRM[iPredictorOrdinateIndex - 2], dblResponseReset, null);
  }
  /**
   * Compute the Chernoff-Poisson Binomial Upper Bound
   *
   * @param dblLevel The Level at which the Bound is sought
   * @return The Chernoff-Poisson Binomial Upper Bound
   * @throws java.lang.Exception Thrown if the Chernoff-Poisson Binomial Upper Bound cannot be
   *     computed
   */
  public double chernoffPoissonUpperBound(final double dblLevel) throws java.lang.Exception {
    if (!org.drip.quant.common.NumberUtil.IsValid(dblLevel) || 1. < dblLevel)
      throw new java.lang.Exception(
          "UnitSequenceAgnosticMetrics::ChernoffBinomialUpperBound => Invalid Inputs");

    int iNumEntry = sequence().length;

    double dblPopulationMean =
        org.drip.quant.common.NumberUtil.IsValid(_dblPopulationMean)
            ? _dblPopulationMean
            : empiricalExpectation();

    double dblBound =
        java.lang.Math.pow(dblPopulationMean / dblLevel, iNumEntry * dblLevel)
            * java.lang.Math.exp(iNumEntry * (dblLevel - dblPopulationMean));

    if (!org.drip.quant.common.NumberUtil.IsValid(dblBound)) return 0.;

    return dblBound > 1. ? 1. : dblBound;
  }
Exemplo n.º 28
0
 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");
 }
  @Override
  public double zero(final double dblDate) throws java.lang.Exception {
    if (!org.drip.quant.common.NumberUtil.IsValid(dblDate))
      throw new java.lang.Exception("NonlinearDiscountFactorDiscountCurve::zero => Invalid Date");

    double dblStartDate = epoch().julian();

    if (dblDate < dblStartDate) return 0.;

    return -365.25 / (dblDate - dblStartDate) * java.lang.Math.log(df(dblDate));
  }
  /**
   * Compute the Karp/Hagerup/Rub Pivot Departure Bounds outlined below:
   *
   * <p>- Karp, R. M. (1988): Probabilistic Analysis of Algorithms, University of California,
   * Berkeley. - Hagerup, T., and C. Rub (1990): A Guided Tour of Chernoff Bounds, Information
   * Processing Letters, 33:305-308.
   *
   * @param dblLevel The Level at which the Bound is sought
   * @return The Karp/Hagerup/Rub Pivot Departure Bounds
   */
  public org.drip.sequence.metrics.PivotedDepartureBounds karpHagerupRubBounds(
      final double dblLevel) {
    if (!org.drip.quant.common.NumberUtil.IsValid(dblLevel) || 1. < dblLevel) return null;

    int iNumEntry = sequence().length;

    double dblPopulationMean =
        org.drip.quant.common.NumberUtil.IsValid(_dblPopulationMean)
            ? _dblPopulationMean
            : empiricalExpectation();

    double dblScaledLevel = dblLevel / dblPopulationMean;

    double dblLowerBound =
        java.lang.Math.exp(-0.5 * dblPopulationMean * iNumEntry * dblScaledLevel * dblScaledLevel);

    if (!org.drip.quant.common.NumberUtil.IsValid(dblLowerBound)) dblLowerBound = 0.;

    double dblUpperBound =
        java.lang.Math.exp(
            -1.
                    * dblPopulationMean
                    * iNumEntry
                    * (1. + dblScaledLevel)
                    * java.lang.Math.log(1. + dblScaledLevel)
                - dblScaledLevel);

    if (!org.drip.quant.common.NumberUtil.IsValid(dblUpperBound)) dblUpperBound = 0.;

    try {
      return new org.drip.sequence.metrics.PivotedDepartureBounds(
          org.drip.sequence.metrics.PivotedDepartureBounds.PIVOT_ANCHOR_TYPE_MEAN,
          java.lang.Double.NaN,
          dblLowerBound > 1. ? 1. : dblLowerBound,
          dblUpperBound > 1. ? 1. : dblUpperBound);
    } catch (java.lang.Exception e) {
      e.printStackTrace();
    }

    return null;
  }