コード例 #1
1
  /**
   * Sample demonstrating the calculation of the bond's full EOD measures from price, TSY spread, or
   * yield
   *
   * <p>USE WITH CARE: This sample ignores errors and does not handle exceptions.
   */
  public static final void BondEODSample() {
    JulianDate dtEOD = JulianDate.CreateFromYMD(2012, 1, 13);

    String strISIN = "US78490FUS63"; // Short dated floater 9/15/2012
    // String strISIN = "US78442GGV23"; // Long dated floater
    // String strISIN = "US44180Y2046"; // Plain old fixed coupon

    Map<String, Double> mapPriceMeasures = FI.BondEODMeasuresFromPrice(strISIN, dtEOD, 1.);

    System.out.println("\n--------------\nPrice Measures\n--------------");

    for (Map.Entry<String, Double> me : mapPriceMeasures.entrySet())
      System.out.println(me.getKey() + "=" + me.getValue());

    Map<String, Double> mapTSYSpreadMeasures =
        FI.BondEODMeasuresFromTSYSpread(strISIN, dtEOD, 0.0486);

    System.out.println("\n---------------\nSpread Measures\n---------------");

    for (Map.Entry<String, Double> me : mapTSYSpreadMeasures.entrySet())
      System.out.println(me.getKey() + "=" + me.getValue());

    Map<String, Double> mapYieldMeasures = FI.BondEODMeasuresFromYield(strISIN, dtEOD, 0.0749);

    System.out.println("\n--------------\nYield Measures\n--------------");

    for (Map.Entry<String, Double> me : mapYieldMeasures.entrySet())
      System.out.println(me.getKey() + "=" + me.getValue());
  }
コード例 #2
0
  /**
   * Sample demonstrating the calculation of analytics for the set of bonds associated with the
   * ticker
   *
   * <p>USE WITH CARE: This sample ignores errors and does not handle exceptions.
   */
  public static final void BondTickerAPISample() throws Exception {
    int iNumBonds = 0;
    String strTicker = "SLMA";

    JulianDate dtToday = JulianDate.Today();

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

    DiscountCurve dcTSY = DiscountCurve.CreateFromFlatRate(dtToday, "USD", 0.04);

    CreditCurve cc = CreditCurve.FromFlatHazard(dtToday.getJulian(), "CC", 0.02, 0.4);

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

    List<String> lsstrISIN = FI.GetISINsForTicker(strTicker);

    System.out.println(
        "Dumping: ISIN, FLOAT/FIXED, Bond, Yield, Z Spread, Opt Adj Spread, TSY Spread, Credit Basis, Credit Price");

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

    for (String strISIN : lsstrISIN) {
      Bond bond = FI.GetBond(strISIN);

      if (null != bond
          && !bond.hasVariableCoupon()
          && !bond.hasBeenExercised()
          && !bond.hasDefaulted()
          && bond.getMaturityDate().getJulian() > dtToday.getJulian()) {
        double dblZSpreadFromPrice = Double.NaN;
        double dblOASpreadFromPrice = Double.NaN;

        double dblYieldFromPrice = FI.BondYieldFromPrice(strISIN, dtToday, dc, 1.);

        if (!FI.IsBondFloater(strISIN)) {
          dblZSpreadFromPrice = FI.BondZSpreadFromPrice(strISIN, dtToday, dc, 1.);

          dblOASpreadFromPrice = FI.BondOASFromPrice(strISIN, dtToday, dc, 1.);
        }

        double dblTSYSpreadFromPrice = FI.BondTSYSpreadFromPrice(strISIN, dtToday, dc, dcTSY, 1.);

        double dblCreditBasisFromPrice = FI.BondCreditBasisFromPrice(strISIN, dtToday, dc, cc, 1.);

        double dblBondCreditPrice = FI.BondCreditPrice(strISIN, dtToday, dc, cc);

        ++iNumBonds;

        System.out.println(
            strISIN
                + FIELD_SEPARATOR
                + (bond.isFloater() ? "FLOAT   " : "FIXED   ")
                + bond.getTicker()
                + FIELD_SEPARATOR
                + FIGen.FormatPrice(bond.getCoupon(dtToday.getJulian(), cmp, null))
                + FIELD_SEPARATOR
                + bond.getMaturityDate()
                + FIELD_SEPARATOR
                + FIGen.FormatPrice(dblYieldFromPrice)
                + FIELD_SEPARATOR
                + FIGen.FormatSpread(dblZSpreadFromPrice)
                + FIELD_SEPARATOR
                + FIGen.FormatSpread(dblOASpreadFromPrice)
                + FIELD_SEPARATOR
                + FIGen.FormatSpread(dblTSYSpreadFromPrice)
                + FIELD_SEPARATOR
                + FIGen.FormatSpread(dblCreditBasisFromPrice)
                + FIELD_SEPARATOR
                + FIGen.FormatPrice(dblBondCreditPrice));
      }
    }

    System.out.println("Processed " + iNumBonds + " " + strTicker + " bonds!");

    for (String strISIN : lsstrISIN) {
      Bond bond = FI.GetBond(strISIN);

      System.out.println(
          strISIN
              + FIELD_SEPARATOR
              + bond.getTicker()
              + FIELD_SEPARATOR
              + FIGen.FormatPrice(bond.getCoupon(JulianDate.Today().getJulian(), null, null))
              + FIELD_SEPARATOR
              + bond.getMaturityDate()
              + FIELD_SEPARATOR
              + FIGen.FormatPrice(FI.GetBondDoubleField(strISIN, "OutstandingAmount"), 10, 0, 1.));
    }

    /*
     * Calculate the bucketed outstanding notional for all the bonds of this ticker
     */

    JulianDate[] adtAscending = new JulianDate[5];

    adtAscending[0] = dtToday.addYears(3);

    adtAscending[1] = dtToday.addYears(5);

    adtAscending[2] = dtToday.addYears(10);

    adtAscending[3] = dtToday.addYears(30);

    adtAscending[4] = dtToday.addYears(60);

    Map<JulianDate, Double> mapOutstandingNotional =
        FI.GetIssuerAggregateOutstandingNotional(dtToday, strTicker, adtAscending);

    for (Map.Entry<JulianDate, Double> me : mapOutstandingNotional.entrySet())
      System.out.println("[" + JulianDate.Today() + "=>" + me.getKey() + "] = " + me.getValue());
  }