public static final void main(final java.lang.String[] astrArgs) throws java.lang.Exception {
    FloatingStream fs =
        new org.drip.product.rates.FloatingStream(
            org.drip.analytics.date.JulianDate.Today().getJulian(),
            org.drip.analytics.date.JulianDate.Today().addTenor("4Y").getJulian(),
            0.03,
            org.drip.product.params.FloatingRateIndex.Create("JPY-LIBOR-6M"),
            2,
            "30/360",
            "30/360",
            false,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            null,
            100.,
            "JPY",
            "JPY");

    byte[] abFS = fs.serialize();

    System.out.println(new java.lang.String(abFS));

    FloatingStream fsDeser = new FloatingStream(abFS);

    System.out.println(new java.lang.String(fsDeser.serialize()));
  }
  /**
   * 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 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;
  }
  private static final void CreditCurveEODAPISample() throws Exception {
    JulianDate dt = JulianDate.CreateFromYMD(2011, 7, 21);

    /*
     * Retrieves all the CDS curves available for the given EOD
     */

    Set<String> setstrCDSCurves = CreditAnalytics.GetEODCDSCurveNames(dt);

    for (String strCDSCurveName : setstrCDSCurves) System.out.println(strCDSCurveName);

    /*
     * Retrieves the calibrated credit curve from the CDS instruments for the given CDS curve name,
     * 		IR curve name, and EOD. Also shows the 10Y survival probability and hazard rate.
     */

    CreditCurve ccEOD = CreditAnalytics.LoadEODCDSCreditCurve("813796", "USD", dt);

    JulianDate dt10Y = JulianDate.Today().addYears(10);

    System.out.println(
        "CCFromEOD["
            + dt10Y.toString()
            + "]; Survival="
            + ccEOD.getSurvival("10Y")
            + "; Hazard="
            + ccEOD.calcHazard("10Y"));

    /*
     * Displays the CDS quotes used to construct the closing credit curve
     */

    CalibratableComponent[] aCompCDS = ccEOD.calibComp();

    for (int i = 0; i < aCompCDS.length; ++i)
      System.out.println(
          aCompCDS[i].getPrimaryCode()
              + " => "
              + (int) (ccEOD.manifestMeasure(aCompCDS[i].getPrimaryCode())));

    /*
     * Loads all available credit curves for the given curve ID built from CDS instruments between 2 dates
     */

    Map<JulianDate, CreditCurve> mapCC =
        CreditAnalytics.LoadEODCDSCreditCurves(
            "813796", "USD", JulianDate.CreateFromYMD(2011, 7, 14), dt);

    /*
     * Displays their 5Y CDS quote
     */

    for (Map.Entry<JulianDate, CreditCurve> meCC : mapCC.entrySet()) {
      JulianDate dtME = meCC.getKey();

      CreditCurve ccCOB = meCC.getValue();

      System.out.println(dtME + "[CDS.5Y] => " + (int) (ccCOB.manifestMeasure("CDS.5Y")));
    }
  }
  @Override
  public org.drip.analytics.date.JulianDate getMaturityDate() {
    org.drip.analytics.date.JulianDate dtFloatReferenceMaturity = _floatReference.getMaturityDate();

    org.drip.analytics.date.JulianDate dtFloatDerivedMaturity = _floatDerived.getMaturityDate();

    if (null == dtFloatReferenceMaturity || null == dtFloatDerivedMaturity) return null;

    return dtFloatReferenceMaturity.getJulian() > dtFloatDerivedMaturity.getJulian()
        ? dtFloatReferenceMaturity
        : dtFloatDerivedMaturity;
  }
  @Override
  public org.drip.analytics.date.JulianDate getEffectiveDate() {
    org.drip.analytics.date.JulianDate dtFloatReferenceEffective =
        _floatReference.getEffectiveDate();

    org.drip.analytics.date.JulianDate dtFloatDerivedEffective = _floatDerived.getEffectiveDate();

    if (null == dtFloatReferenceEffective || null == dtFloatDerivedEffective) return null;

    return dtFloatReferenceEffective.getJulian() < dtFloatDerivedEffective.getJulian()
        ? dtFloatReferenceEffective
        : dtFloatDerivedEffective;
  }
  /**
   * Get the first coupon date
   *
   * @return First Coupon Date
   */
  public org.drip.analytics.date.JulianDate getFirstCouponDate() {
    org.drip.product.definition.Component[] aComp = getComponents();

    int iNumComp = aComp.length;

    org.drip.analytics.date.JulianDate dtFirstCoupon = aComp[0].getFirstCouponDate();

    for (int i = 1; i < iNumComp; ++i) {
      if (dtFirstCoupon.getJulian() > aComp[i].getFirstCouponDate().getJulian())
        dtFirstCoupon = aComp[i].getFirstCouponDate();
    }

    return dtFirstCoupon;
  }
  @Override
  public org.drip.analytics.date.JulianDate getFirstCouponDate() {
    org.drip.analytics.date.JulianDate dtFloatReferenceFirstCoupon =
        _floatReference.getFirstCouponDate();

    org.drip.analytics.date.JulianDate dtFloatDerivedFirstCoupon =
        _floatDerived.getFirstCouponDate();

    if (null == dtFloatReferenceFirstCoupon || null == dtFloatDerivedFirstCoupon) return null;

    return dtFloatReferenceFirstCoupon.getJulian() < dtFloatDerivedFirstCoupon.getJulian()
        ? dtFloatReferenceFirstCoupon
        : dtFloatDerivedFirstCoupon;
  }
  /**
   * Return the maturity date of the basket product
   *
   * @return Maturity date of the basket product
   */
  public org.drip.analytics.date.JulianDate getMaturityDate() {
    org.drip.product.definition.Component[] aComp = getComponents();

    int iNumComp = aComp.length;

    org.drip.analytics.date.JulianDate dtMaturity = aComp[0].getMaturityDate();

    for (int i = 1; i < iNumComp; ++i) {
      org.drip.analytics.date.JulianDate dtCompMaturity = aComp[i].getMaturityDate();

      if (dtCompMaturity.getJulian() < dtMaturity.getJulian()) dtMaturity = dtCompMaturity;
    }

    return dtMaturity;
  }
  public static final void main(final java.lang.String[] astrArgs) throws java.lang.Exception {
    double dblScheduleStart = org.drip.analytics.date.JulianDate.Today().getJulian();

    double[] adblDate = new double[3];
    double[] adblFactor = new double[3];
    adblFactor[0] = 1.20;
    adblFactor[1] = 1.10;
    adblFactor[2] = 1.00;
    adblDate[0] = dblScheduleStart + 30.;
    adblDate[1] = dblScheduleStart + 396.;
    adblDate[2] = dblScheduleStart + 761.;

    EmbeddedOptionSchedule eos =
        EmbeddedOptionSchedule.fromAmerican(
            dblScheduleStart,
            adblDate,
            adblFactor,
            true,
            30,
            false,
            java.lang.Double.NaN,
            "CRAP",
            java.lang.Double.NaN);

    byte[] abEOS = eos.serialize();

    System.out.println(new java.lang.String(abEOS));

    EmbeddedOptionSchedule eosDeser = new EmbeddedOptionSchedule(abEOS);

    System.out.println(new java.lang.String(eosDeser.serialize()));
  }
  public static final void main(final java.lang.String[] astrArgs) throws java.lang.Exception {
    CashComponent cash =
        new CashComponent(
            org.drip.analytics.date.JulianDate.Today(),
            org.drip.analytics.date.JulianDate.Today().addTenor("1Y"),
            "AUD",
            "Act/360",
            "BMA");

    byte[] abCash = cash.serialize();

    System.out.println(new java.lang.String(abCash));

    CashComponent cashDeser = new CashComponent(abCash);

    System.out.println(new java.lang.String(cashDeser.serialize()));
  }
  /**
   * 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();
  }
  /**
   * Loads the map of the holiday calendars from the database settings set in the XML Configuration
   * file
   *
   * @param strConfigFile XML Configuration file
   * @return Map of the holiday calendars
   */
  public static final org.drip.analytics.support.CaseInsensitiveTreeMap<
          org.drip.analytics.holiday.Locale>
      LoadHolidayCalendarsFromDB(final java.lang.String strConfigFile) {
    org.drip.analytics.support.CaseInsensitiveTreeMap<org.drip.analytics.holiday.Locale> mapHols =
        new org.drip.analytics.support.CaseInsensitiveTreeMap<org.drip.analytics.holiday.Locale>();

    java.sql.Statement stmt = OracleInit(strConfigFile);

    if (null == stmt) return null;

    long lStart = System.nanoTime();

    try {
      java.sql.ResultSet rs = stmt.executeQuery("SELECT Location, Holiday FROM Holidays");

      while (null != rs && rs.next()) {
        java.lang.String strLocation = rs.getString("Location");

        java.util.Date dtSQLHoliday = rs.getDate("Holiday");

        if (null != dtSQLHoliday) {
          org.drip.analytics.holiday.Locale lh = mapHols.get(strLocation);

          if (null == lh) lh = new org.drip.analytics.holiday.Locale();

          lh.addStaticHoliday(
              org.drip.analytics.date.JulianDate.CreateFromYMD(
                  org.drip.analytics.support.GenericUtil.GetYear(dtSQLHoliday),
                  org.drip.analytics.support.GenericUtil.GetMonth(dtSQLHoliday),
                  org.drip.analytics.support.GenericUtil.GetYear(dtSQLHoliday)),
              "");

          mapHols.put(strLocation, lh);
        }
      }
    } catch (java.lang.Exception e) {
      e.printStackTrace();

      return null;
    }

    int[] aiWeekend = new int[2];
    aiWeekend[1] = org.drip.analytics.date.JulianDate.SUNDAY;
    aiWeekend[0] = org.drip.analytics.date.JulianDate.SATURDAY;

    for (java.util.Map.Entry<java.lang.String, org.drip.analytics.holiday.Locale> me :
        mapHols.entrySet()) me.getValue().addWeekend(aiWeekend);

    System.out.println(
        "Loading hols from DB took " + (System.nanoTime() - lStart) * 1.e-06 + " m-sec\n");

    return mapHols;
  }
  private static final void CreditCurveAPISample() throws Exception {
    JulianDate dtStart = JulianDate.Today();

    JulianDate dt10Y = dtStart.addYears(10);

    /*
     * Create Credit Curve from flat Hazard Rate
     */

    CreditCurve ccFlatHazard =
        CreditCurveBuilder.FromFlatHazard(dtStart.getJulian(), "CC", "USD", 0.02, 0.4);

    System.out.println(
        "CCFromFlatHazard["
            + dt10Y.toString()
            + "]; Survival="
            + ccFlatHazard.getSurvival("10Y")
            + "; Hazard="
            + ccFlatHazard.calcHazard("10Y"));

    double[] adblDate = new double[5];
    double[] adblSurvival = new double[5];

    for (int i = 0; i < 5; ++i) {
      adblDate[i] = dtStart.addYears(2 * i + 2).getJulian();

      adblSurvival[i] = 1. - 0.1 * (i + 1);
    }

    /*
     * Create Credit Curve from an array of dates and their corresponding survival probabilities
     */

    CreditCurve ccFromSurvival =
        CreditCurveBuilder.FromSurvival(
            dtStart.getJulian(), "CC", "USD", adblDate, adblSurvival, 0.4);

    System.out.println(
        "CCFromSurvival["
            + dt10Y.toString()
            + "]; Survival="
            + ccFromSurvival.getSurvival("10Y")
            + "; Hazard="
            + ccFromSurvival.calcHazard("10Y"));
  }
  private static final void CDSEODMeasuresAPISample() {
    JulianDate dtEOD = JulianDate.CreateFromYMD(2011, 7, 21); // EOD

    /*
     * Create a spot starting CDS based off of a specific credit curve
     */

    CreditDefaultSwap cds = CDSBuilder.CreateSNAC(JulianDate.Today(), "5Y", 0.1, "813796");

    /*
     * Calculate the EOD CDS measures
     */

    CaseInsensitiveTreeMap<Double> mapEODCDSMeasures =
        CreditAnalytics.GetEODCDSMeasures(cds, dtEOD);

    /*
     * Display the EOD CDS measures
     */

    for (Map.Entry<String, Double> me : mapEODCDSMeasures.entrySet())
      System.out.println(me.getKey() + " => " + me.getValue());
  }
 private static final void ForwardJack(
     final JulianDate dt,
     final Map<String, ForwardCurve> mapForward,
     final String strStartDateTenor) {
   for (Map.Entry<String, ForwardCurve> me : mapForward.entrySet())
     System.out.println(
         me.getKey()
             + " | "
             + strStartDateTenor
             + ": "
             + me.getValue()
                 .jackDForwardDManifestMeasure("PV", dt.addTenor(strStartDateTenor))
                 .displayString());
 }
  /**
   * Construct an DerivedFXBasis instance from the currency pair, FX Spot, and FX basis parameters
   *
   * @param cp Currency Pair
   * @param dtSpot Spot Date
   * @param dblFXSpot FX Spot
   * @param adblDate Array of dates
   * @param adblFXBasis Array of FX Basis
   * @param bIsFXBasisBootstrapped True if the inputs are for bootstrapped FX basis
   * @throws java.lang.Exception Thrown if the FXBasis instance cannot be created
   */
  public DerivedFXBasis(
      final org.drip.product.params.CurrencyPair cp,
      final org.drip.analytics.date.JulianDate dtSpot,
      final double dblFXSpot,
      final double[] adblDate,
      final double[] adblFXBasis,
      final boolean bIsFXBasisBootstrapped)
      throws java.lang.Exception {
    if (null == cp
        || null == dtSpot
        || !org.drip.quant.common.NumberUtil.IsValid(dblFXSpot)
        || null == adblDate
        || 0 == adblDate.length
        || null == adblFXBasis
        || 0 == adblFXBasis.length
        || adblDate.length != adblFXBasis.length)
      throw new java.lang.Exception("DerivedFXBasis ctr: Invalid Params");

    _dblSpotDate = dtSpot.julian();

    _cp = cp;
    _dblFXSpot = dblFXSpot;
    _adblDate = new double[adblDate.length];
    _adblFXBasis = new double[adblFXBasis.length];
    _bIsFXBasisBootstrapped = bIsFXBasisBootstrapped;

    for (int i = 0; i < adblFXBasis.length; ++i) {
      if (!org.drip.quant.common.NumberUtil.IsValid(adblDate[i]) || adblDate[i] <= _dblSpotDate)
        throw new java.lang.Exception(
            "DerivedFXBasis ctr: Invalid params: Node date "
                + org.drip.analytics.date.DateUtil.FromJulian(adblDate[i])
                + " before spot "
                + dtSpot);

      _adblDate[i] = adblDate[i];
      _adblFXBasis[i] = adblFXBasis[i];
    }
  }
  private static final CalibratableFixedIncomeComponent[] DepositInstrumentsFromMaturityDays(
      final JulianDate dtEffective,
      final int[] aiDay,
      final int iNumFutures,
      final String strCurrency)
      throws Exception {
    CalibratableFixedIncomeComponent[] aCalibComp =
        new CalibratableFixedIncomeComponent[aiDay.length + iNumFutures];

    for (int i = 0; i < aiDay.length; ++i)
      aCalibComp[i] =
          SingleStreamComponentBuilder.Deposit(
              dtEffective,
              dtEffective.addBusDays(aiDay[i], strCurrency),
              ForwardLabel.Create(strCurrency, aiDay[i] + "D"));

    CalibratableFixedIncomeComponent[] aEDF =
        SingleStreamComponentBuilder.FuturesPack(dtEffective, iNumFutures, strCurrency);

    for (int i = aiDay.length; i < aiDay.length + iNumFutures; ++i)
      aCalibComp[i] = aEDF[i - aiDay.length];

    return aCalibComp;
  }
  private static final Map<String, ForwardCurve> xM6MBasisSample(
      final JulianDate dtSpot,
      final String strCurrency,
      final DiscountCurve dc,
      final int iTenorInMonths,
      final String[] astrxM6MFwdTenor,
      final double[] adblxM6MBasisSwapQuote)
      throws Exception {
    System.out.println("------------------------------------------------------------");

    System.out.println(" SPL =>              n=4               |         |         |");

    System.out.println("---------------------------------------|  LOG DF |  LIBOR  |");

    System.out.println(" MSR =>  RECALC  |  REFEREN |  DERIVED |         |         |");

    System.out.println("------------------------------------------------------------");

    /*
     * Construct the 6M-xM float-float basis swap.
     */

    FloatFloatComponent[] aFFC =
        MakexM6MBasisSwap(dtSpot, strCurrency, astrxM6MFwdTenor, iTenorInMonths);

    String strBasisTenor = iTenorInMonths + "M";

    ValuationParams valParams = new ValuationParams(dtSpot, dtSpot, strCurrency);

    /*
     * Calculate the starting forward rate off of the discount curve.
     */

    double dblStartingFwd = dc.forward(dtSpot.julian(), dtSpot.addTenor(strBasisTenor).julian());

    /*
     * Set the discount curve based component market parameters.
     */

    CurveSurfaceQuoteSet mktParams =
        MarketParamsBuilder.Create(dc, null, null, null, null, null, null);

    Map<String, ForwardCurve> mapForward = new HashMap<String, ForwardCurve>();

    /*
     * Construct the shape preserving forward curve off of Quartic Polynomial Basis Spline.
     */

    ForwardCurve fcxMQuartic =
        ScenarioForwardCurveBuilder.ShapePreservingForwardCurve(
            "QUARTIC_FWD" + strBasisTenor,
            ForwardLabel.Create(strCurrency, strBasisTenor),
            valParams,
            null,
            mktParams,
            null,
            MultiSegmentSequenceBuilder.BASIS_SPLINE_POLYNOMIAL,
            new PolynomialFunctionSetParams(5),
            aFFC,
            "ReferenceParBasisSpread",
            adblxM6MBasisSwapQuote,
            dblStartingFwd);

    mapForward.put(" QUARTIC_FWD" + strBasisTenor, fcxMQuartic);

    /*
     * Set the discount curve + quartic polynomial forward curve based component market parameters.
     */

    CurveSurfaceQuoteSet mktParamsQuarticFwd =
        MarketParamsBuilder.Create(dc, fcxMQuartic, null, null, null, null, null, null);

    int i = 0;
    int iFreq = 12 / iTenorInMonths;

    /*
     * Compute the following forward curve metrics for each of cubic polynomial forward, quartic
     * 	polynomial forward, and KLK Hyperbolic tension forward curves:
     * 	- Reference Basis Par Spread
     * 	- Derived Basis Par Spread
     *
     * Further compare these with a) the forward rate off of the discount curve, b) the LIBOR rate, and
     * 	c) Input Basis Swap Quote.
     */

    for (String strMaturityTenor : astrxM6MFwdTenor) {
      double dblFwdEndDate = dtSpot.addTenor(strMaturityTenor).julian();

      double dblFwdStartDate =
          dtSpot.addTenor(strMaturityTenor).subtractTenor(strBasisTenor).julian();

      FloatFloatComponent ffc = aFFC[i++];

      CaseInsensitiveTreeMap<Double> mapQuarticValue =
          ffc.value(valParams, null, mktParamsQuarticFwd, null);

      System.out.println(
          " "
              + strMaturityTenor
              + " =>  "
              + FormatUtil.FormatDouble(fcxMQuartic.forward(strMaturityTenor), 2, 2, 100.)
              + "  |  "
              + FormatUtil.FormatDouble(mapQuarticValue.get("ReferenceParBasisSpread"), 2, 2, 1.)
              + "  |  "
              + FormatUtil.FormatDouble(mapQuarticValue.get("DerivedParBasisSpread"), 2, 2, 1.)
              + "  |  "
              + FormatUtil.FormatDouble(
                  iFreq * java.lang.Math.log(dc.df(dblFwdStartDate) / dc.df(dblFwdEndDate)),
                  1,
                  2,
                  100.)
              + "  |  "
              + FormatUtil.FormatDouble(dc.libor(dblFwdStartDate, dblFwdEndDate), 1, 2, 100.)
              + "  |  ");
    }

    return mapForward;
  }
  /**
   * Return the stringified set of parameters in a java call that can be statically used to
   * re-construct the index.
   *
   * @return Set of Stringified parameters as a java call.
   */
  public java.lang.String setConstructionString() {
    java.lang.StringBuffer sb = new java.lang.StringBuffer();

    java.lang.String strCDXCode =
        _strIndexClass
            + "."
            + _strIndexGroupName
            + "."
            + _iIndexLifeSpan
            + "Y."
            + _iIndexSeries
            + "."
            + _iIndexVersion;

    sb.append(
        "\t\tUpdateCDXRefDataMap ("
            + org.drip.quant.common.StringUtil.MakeStringArg(strCDXCode)
            + ",\n\t\t\torg.drip.product.creator.CDXRefDataBuilder.CreateCDXRefDataBuilder (");

    sb.append(org.drip.quant.common.StringUtil.MakeStringArg(_strCurveID) + ", ");

    sb.append(org.drip.quant.common.StringUtil.MakeStringArg(_strSPN) + ",\n\t\t\t\t");

    sb.append(org.drip.quant.common.StringUtil.MakeStringArg(_strIndexLabel) + ", ");

    sb.append(org.drip.quant.common.StringUtil.MakeStringArg(_strIndexName) + ",\n\t\t\t\t\t");

    sb.append(org.drip.quant.common.StringUtil.MakeStringArg(_strCurveName) + ", ");

    sb.append(_dtIssue.getJulian() + ", ");

    sb.append(_dtMaturity.getJulian() + ", ");

    sb.append(_dblCoupon + ", ");

    sb.append(org.drip.quant.common.StringUtil.MakeStringArg(_strCurrency) + ",\n\t\t\t\t\t\t");

    sb.append(org.drip.quant.common.StringUtil.MakeStringArg(_strDayCount) + ", ");

    sb.append(_bFullFirstStub + ", ");

    sb.append(_dblRecovery + ", ");

    sb.append(_iFrequency + ", ");

    sb.append(org.drip.quant.common.StringUtil.MakeStringArg(_strRedID) + ", ");

    sb.append(org.drip.quant.common.StringUtil.MakeStringArg(_strIndexClass) + ", ");

    sb.append(_iIndexSeries + ", ");

    sb.append(org.drip.quant.common.StringUtil.MakeStringArg(_strIndexGroupName) + ", ");

    sb.append(org.drip.quant.common.StringUtil.MakeStringArg(_strIndexShortName) + ", ");

    sb.append(org.drip.quant.common.StringUtil.MakeStringArg(_strIndexShortGroupName) + ", ");

    sb.append(_iIndexVersion + ", ");

    sb.append(_iIndexLifeSpan + ",\n\t\t\t\t\t\t\t");

    sb.append(org.drip.quant.common.StringUtil.MakeStringArg(_strCurvyCurveID) + ", ");

    sb.append(_dblIndexFactor + ", ");

    sb.append(_iOriginalComponentCount + ", ");

    sb.append(_iDefaultedComponentCount + ", ");

    sb.append(org.drip.quant.common.StringUtil.MakeStringArg(_strLocation) + ", ");

    sb.append(_bPayAccrued + ", ");

    sb.append(_bKnockOutOnDefault + ", ");

    sb.append(_bQuoteAsCDS + ", ");

    sb.append(org.drip.quant.common.StringUtil.MakeStringArg(_strBBGTicker) + ", ");

    sb.append(org.drip.quant.common.StringUtil.MakeStringArg(_strShortName) + "));\n\n");

    return sb.toString();
  }
  public static final void main(final String[] astrArgs) throws Exception {
    /*
     * Initialize the Credit Analytics Library
     */

    CreditAnalytics.Init("");

    JulianDate dtToday = DateUtil.Today();

    String[] astrTenor =
        new String[] {
          "1Y", "2Y", "3Y", "4Y", "5Y", "6Y", "7Y", "8Y", "9Y", "10Y", "11Y", "12Y", "15Y", "20Y",
          "25Y", "30Y"
        };

    double[] adblBasis =
        new double[] {
          0.00186, //  1Y
          0.00127, //  2Y
          0.00097, //  3Y
          0.00080, //  4Y
          0.00067, //  5Y
          0.00058, //  6Y
          0.00051, //  7Y
          0.00046, //  8Y
          0.00042, //  9Y
          0.00038, // 10Y
          0.00035, // 11Y
          0.00033, // 12Y
          0.00028, // 15Y
          0.00022, // 20Y
          0.00020, // 25Y
          0.00018 // 30Y
        };

    BasisCurve bcCubicPolynomial =
        ScenarioBasisCurveBuilder.CubicPolynomialBasisCurve(
            "USD3M6MBasis_CubicPolynomial",
            dtToday,
            ForwardLabel.Create("USD", "6M"),
            ForwardLabel.Create("USD", "3M"),
            false,
            new CollateralizationParams("OVERNIGHT", "USD"),
            astrTenor,
            adblBasis);

    BasisCurve bcQuinticPolynomial =
        ScenarioBasisCurveBuilder.QuarticPolynomialBasisCurve(
            "USD3M6MBasis_QuinticPolynomial",
            dtToday,
            ForwardLabel.Create("USD", "6M"),
            ForwardLabel.Create("USD", "3M"),
            false,
            new CollateralizationParams("OVERNIGHT", "USD"),
            astrTenor,
            adblBasis);

    BasisCurve bcKaklisPandelis =
        ScenarioBasisCurveBuilder.KaklisPandelisBasisCurve(
            "USD3M6MBasis_KaklisPandelis",
            dtToday,
            ForwardLabel.Create("USD", "6M"),
            ForwardLabel.Create("USD", "3M"),
            false,
            new CollateralizationParams("OVERNIGHT", "USD"),
            astrTenor,
            adblBasis);

    BasisCurve bcKLKHyperbolic =
        ScenarioBasisCurveBuilder.KLKHyperbolicBasisCurve(
            "USD3M6MBasis_KLKHyperbolic",
            dtToday,
            ForwardLabel.Create("USD", "6M"),
            ForwardLabel.Create("USD", "3M"),
            false,
            new CollateralizationParams("OVERNIGHT", "USD"),
            astrTenor,
            adblBasis,
            1.);

    BasisCurve bcKLKRationalLinear =
        ScenarioBasisCurveBuilder.KLKRationalLinearBasisCurve(
            "USD3M6MBasis_KLKRationalLinear",
            dtToday,
            ForwardLabel.Create("USD", "6M"),
            ForwardLabel.Create("USD", "3M"),
            false,
            new CollateralizationParams("OVERNIGHT", "USD"),
            astrTenor,
            adblBasis,
            0.1);

    BasisCurve bcKLKRationalQuadratic =
        ScenarioBasisCurveBuilder.KLKRationalLinearBasisCurve(
            "USD3M6MBasis_KLKRationalQuadratic",
            dtToday,
            ForwardLabel.Create("USD", "6M"),
            ForwardLabel.Create("USD", "3M"),
            false,
            new CollateralizationParams("OVERNIGHT", "USD"),
            astrTenor,
            adblBasis,
            2.);

    System.out.println("\tPrinting the Basis Node Values in Order (Left -> Right):");

    System.out.println("\t\tCalculated Cubic Polynomial Basis (%)");

    System.out.println("\t\tCalculated Quintic Polynomial Basis (%)");

    System.out.println("\t\tCalculated Kaklis Pandelis Basis (%)");

    System.out.println("\t\tCalculated KLK Hyperbolic Basis (%)");

    System.out.println("\t\tCalculated KLK Rational Linear Basis (%)");

    System.out.println("\t\tCalculated KLK Rational Quadratic Basis (%)");

    System.out.println("\t\tInput Quote (bp)");

    System.out.println("\t-------------------------------------------------------------");

    System.out.println("\t-------------------------------------------------------------");

    for (int i = 0; i < adblBasis.length; ++i)
      System.out.println(
          "\t"
              + astrTenor[i]
              + " => "
              + FormatUtil.FormatDouble(bcCubicPolynomial.basis(astrTenor[i]), 1, 2, 10000.)
              + " | "
              + FormatUtil.FormatDouble(bcQuinticPolynomial.basis(astrTenor[i]), 1, 2, 10000.)
              + " | "
              + FormatUtil.FormatDouble(bcKaklisPandelis.basis(astrTenor[i]), 1, 2, 10000.)
              + " | "
              + FormatUtil.FormatDouble(bcKLKHyperbolic.basis(astrTenor[i]), 1, 2, 10000.)
              + " | "
              + FormatUtil.FormatDouble(bcKLKRationalLinear.basis(astrTenor[i]), 1, 2, 10000.)
              + " | "
              + FormatUtil.FormatDouble(bcKLKRationalQuadratic.basis(astrTenor[i]), 1, 2, 10000.)
              + " | "
              + FormatUtil.FormatDouble(adblBasis[i], 1, 2, 10000.));

    System.out.println(
        "\n\t|----------------------------------------------------------------------------|");

    System.out.println(
        "\t|  DATE    =>  CUBIC | QUINTIC  | KAKPAND | KLKHYPER | KLKRATLNR | KLKRATQUA |");

    System.out.println(
        "\t|----------------------------------------------------------------------------|\n");

    for (int i = 3; i < 30; ++i) {
      JulianDate dt = dtToday.addTenor(i + "Y");

      System.out.println(
          "\t"
              + dt
              + " => "
              + FormatUtil.FormatDouble(bcCubicPolynomial.basis(dt), 1, 2, 10000.)
              + "  |  "
              + FormatUtil.FormatDouble(bcQuinticPolynomial.basis(dt), 1, 2, 10000.)
              + "   |  "
              + FormatUtil.FormatDouble(bcKaklisPandelis.basis(dt), 1, 2, 10000.)
              + "  |  "
              + FormatUtil.FormatDouble(bcKLKHyperbolic.basis(dt), 1, 2, 10000.)
              + "   |  "
              + FormatUtil.FormatDouble(bcKLKRationalLinear.basis(dt), 1, 2, 10000.)
              + "    |  "
              + FormatUtil.FormatDouble(bcKLKRationalQuadratic.basis(dt), 1, 2, 10000.)
              + "    |  ");
    }

    System.out.println(
        "\n\t|----------------------------------------------------------------------------|");
  }
  private static void CreateCreditCurveFromCDSInstruments() throws Exception {
    JulianDate dtStart = JulianDate.Today();

    /*
     * Populate the instruments, the calibration measures, and the calibration quotes
     */

    double[] adblQuotes = new double[5];
    String[] astrCalibMeasure = new String[5];
    CreditDefaultSwap[] aCDS = new CreditDefaultSwap[5];

    for (int i = 0; i < 5; ++i) {
      /*
       * The Calibration CDS
       */

      aCDS[i] = CDSBuilder.CreateSNAC(dtStart, (i + 1) + "Y", 0.01, "CORP");

      /*
       * Calibration Quote
       */

      adblQuotes[i] = 100.;

      /*
       * Calibration Measure
       */

      astrCalibMeasure[i] = "FairPremium";
    }

    /*
     * Flat Discount Curve
     */

    DiscountCurve dc = DiscountCurveBuilder.CreateFromFlatRate(dtStart, "USD", 0.05);

    /*
     * Create the Credit Curve from the give CDS instruments
     */

    CreditCurve cc =
        CreditScenarioCurveBuilder.CreateCreditCurve(
            "CORP", dtStart, aCDS, dc, adblQuotes, astrCalibMeasure, 0.4, false);

    /*
     * Valuation Parameters
     */

    ValuationParams valParams =
        ValuationParams.CreateValParams(dtStart, 0, "", Convention.DR_ACTUAL);

    /*
     * Standard Credit Pricer Parameters (check javadoc for details)
     */

    PricerParams pricerParams = PricerParams.MakeStdPricerParams();

    /*
     * Re-calculate the input calibration measures for the input CDSes
     */

    for (int i = 0; i < aCDS.length; ++i)
      System.out.println(
          "\t"
              + astrCalibMeasure[i]
              + "["
              + i
              + "] = "
              + aCDS[i].calcMeasureValue(
                  valParams,
                  pricerParams,
                  ComponentMarketParamsBuilder.CreateComponentMarketParams(
                      dc, null, null, cc, null, null, null),
                  null,
                  astrCalibMeasure[i]));
  }
  private static final void CDSAPISample() throws Exception {
    JulianDate dtStart = JulianDate.Today();

    /*
     * Flat Discount Curve
     */

    DiscountCurve dc = DiscountCurveBuilder.CreateFromFlatRate(dtStart, "USD", 0.05);

    /*
     * Flat Credit Curve
     */

    CreditCurve cc = CreditCurveBuilder.FromFlatHazard(dtStart.getJulian(), "CC", "USD", 0.02, 0.4);

    /*
     * Component Market Parameters built from the Discount and the Credit Curves
     */

    ComponentMarketParams cmp = ComponentMarketParamsBuilder.MakeCreditCMP(dc, cc);

    /*
     * Create an SNAC CDS
     */

    CreditDefaultSwap cds = CDSBuilder.CreateSNAC(dtStart, "5Y", 0.1, "CC");

    /*
     * Valuation Parameters
     */

    ValuationParams valParams =
        ValuationParams.CreateValParams(dtStart, 0, "", Convention.DR_ACTUAL);

    /*
     * Standard Credit Pricer Parameters (check javadoc for details)
     */

    PricerParams pricerParams = PricerParams.MakeStdPricerParams();

    System.out.println(
        "Acc Start       Acc End     Pay Date    Index   Spread   Cpn DCF    Pay01    Surv01");

    System.out.println(
        "---------      ---------    ---------   ------  ------   -------- --------- --------");

    /*
     * CDS Coupon Cash Flow
     */

    for (CashflowPeriodCurveFactors p : cds.getCouponFlow(valParams, pricerParams, cmp))
      System.out.println(
          JulianDate.fromJulian(p.getAccrualStartDate())
              + FIELD_SEPARATOR
              + JulianDate.fromJulian(p.getAccrualEndDate())
              + FIELD_SEPARATOR
              + JulianDate.fromJulian(p.getPayDate())
              + FIELD_SEPARATOR
              + FormatUtil.FormatDouble(p.getIndexRate(), 1, 4, 1.)
              + FIELD_SEPARATOR
              + FormatUtil.FormatDouble(p.getSpread(), 1, 4, 1.)
              + FIELD_SEPARATOR
              + FormatUtil.FormatDouble(p.getCouponDCF(), 1, 4, 1.)
              + FIELD_SEPARATOR
              + FormatUtil.FormatDouble(dc.df(p.getPayDate()), 1, 4, 1.)
              + FIELD_SEPARATOR
              + FormatUtil.FormatDouble(cc.getSurvival(p.getPayDate()), 1, 4, 1.));

    System.out.println(
        "Loss Start     Loss End      Pay Date      Cpn    Notl     Rec    EffDF    StartSurv  EndSurv");

    System.out.println(
        "----------     --------      --------      ---    ----     ---    -----    ---------  -------");

    /*
     * CDS Loss Cash Flow
     */

    for (LossPeriodCurveFactors dp : cds.getLossFlow(valParams, pricerParams, cmp))
      System.out.println(
          JulianDate.fromJulian(dp.getStartDate())
              + FIELD_SEPARATOR
              + JulianDate.fromJulian(dp.getEndDate())
              + FIELD_SEPARATOR
              + JulianDate.fromJulian(dp.getPayDate())
              + FIELD_SEPARATOR
              + FormatUtil.FormatDouble(dp.getCouponDCF(), 1, 4, 1.)
              + FIELD_SEPARATOR
              + FormatUtil.FormatDouble(dp.effectiveNotional(), 1, 0, 1.)
              + FIELD_SEPARATOR
              + FormatUtil.FormatDouble(dp.effectiveRecovery(), 1, 2, 1.)
              + FIELD_SEPARATOR
              + FormatUtil.FormatDouble(dp.effectiveDF(), 1, 4, 1.)
              + FIELD_SEPARATOR
              + FormatUtil.FormatDouble(dp.startSurvival(), 1, 4, 1.)
              + FIELD_SEPARATOR
              + FormatUtil.FormatDouble(dp.endSurvival(), 1, 4, 1.));
  }
  /**
   * Construct NonlinearDiscountFactorDiscountCurve instance from an array of dates and forward
   * rates
   *
   * @param dtStart Epoch Date
   * @param strCurrency Currency
   * @param collatParams Collateralization Parameters
   * @param adblDate Array of Dates
   * @param adblRate Array of Forward Rates
   * @throws java.lang.Exception Thrown if the curve cannot be created
   */
  public NonlinearDiscountFactorDiscountCurve(
      final org.drip.analytics.date.JulianDate dtStart,
      final java.lang.String strCurrency,
      final org.drip.param.valuation.CollateralizationParams collatParams,
      final double[] adblDate,
      final double[] adblRate)
      throws java.lang.Exception {
    super(dtStart.julian(), strCurrency, collatParams);

    if (null == adblDate
        || 0 == adblDate.length
        || null == adblRate
        || adblDate.length != adblRate.length
        || null == dtStart)
      throw new java.lang.Exception("NonlinearDiscountFactorDiscountCurve ctr: Invalid inputs");

    _dblEpochDate = dtStart.julian();

    org.drip.spline.params.SegmentCustomBuilderControl sbp =
        new org.drip.spline.params.SegmentCustomBuilderControl(
            org.drip.spline.stretch.MultiSegmentSequenceBuilder.BASIS_SPLINE_POLYNOMIAL,
            new org.drip.spline.basis.PolynomialFunctionSetParams(2),
            org.drip.spline.params.SegmentInelasticDesignControl.Create(0, 2),
            null,
            null);

    int iNumSegment = adblDate.length;
    _adblDate = new double[iNumSegment];
    double[] adblDF = new double[iNumSegment];
    org.drip.spline.params.SegmentCustomBuilderControl[] aSBP =
        new org.drip.spline.params.SegmentCustomBuilderControl[adblDate.length - 1];

    for (int i = 0; i < iNumSegment; ++i) {
      _adblDate[i] = adblDate[i];

      if (0 == i)
        adblDF[0] = java.lang.Math.exp(adblRate[0] * (_dblEpochDate - _adblDate[0]) / 365.25);
      else {
        aSBP[i - 1] = sbp;

        adblDF[i] =
            java.lang.Math.exp(adblRate[i] * (_adblDate[i - 1] - _adblDate[i]) / 365.25)
                * adblDF[i - 1];
      }
    }

    _dblLeftFlatForwardRate =
        -365.25 * java.lang.Math.log(adblDF[0]) / (_adblDate[0] - _dblEpochDate);

    _dblRightFlatForwardRate =
        -365.25
            * java.lang.Math.log(adblDF[iNumSegment - 1])
            / (_adblDate[iNumSegment - 1] - _dblEpochDate);

    _msr =
        org.drip.spline.stretch.MultiSegmentSequenceBuilder.CreateCalibratedStretchEstimator(
            "POLY_SPLINE_DF_REGIME",
            adblDate,
            adblDF,
            aSBP,
            null,
            org.drip.spline.stretch.BoundarySettings.NaturalStandard(),
            org.drip.spline.stretch.MultiSegmentSequence.CALIBRATE);
  }
 @Override
 public java.lang.String getComponentName() {
   return "FloatingStream=" + org.drip.analytics.date.JulianDate.fromJulian(_dblMaturity);
 }