예제 #1
0
  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()));
  }
  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")));
    }
  }
  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()));
  }
예제 #4
0
  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()));
  }
  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 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.));
  }
  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]));
  }