BasketAggregateMeasuresGeneration.java

  1. package org.drip.sample.bond;

  2. /*
  3.  * Credit Product Imports
  4.  */

  5. import java.util.List;

  6. import org.drip.analytics.date.*;
  7. import org.drip.analytics.daycount.Convention;
  8. import org.drip.analytics.support.*;
  9. import org.drip.numerical.common.*;
  10. import org.drip.param.market.CurveSurfaceQuoteContainer;
  11. import org.drip.param.period.*;
  12. import org.drip.param.pricer.CreditPricerParams;
  13. import org.drip.param.valuation.*;
  14. import org.drip.product.creator.*;
  15. import org.drip.product.credit.*;
  16. import org.drip.product.definition.*;
  17. import org.drip.product.rates.*;
  18. import org.drip.service.env.EnvManager;
  19. import org.drip.state.creator.ScenarioDiscountCurveBuilder;
  20. import org.drip.state.discount.MergedDiscountForwardCurve;
  21. import org.drip.state.identifier.ForwardLabel;

  22. /*
  23.  * -*- mode: java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  24.  */

  25. /*!
  26.  * Copyright (C) 2020 Lakshmi Krishnamurthy
  27.  * Copyright (C) 2019 Lakshmi Krishnamurthy
  28.  * Copyright (C) 2018 Lakshmi Krishnamurthy
  29.  * Copyright (C) 2017 Lakshmi Krishnamurthy
  30.  * Copyright (C) 2016 Lakshmi Krishnamurthy
  31.  * Copyright (C) 2015 Lakshmi Krishnamurthy
  32.  * Copyright (C) 2014 Lakshmi Krishnamurthy
  33.  * Copyright (C) 2013 Lakshmi Krishnamurthy
  34.  *
  35.  *  This file is part of DROP, an open-source library targeting analytics/risk, transaction cost analytics,
  36.  *      asset liability management analytics, capital, exposure, and margin analytics, valuation adjustment
  37.  *      analytics, and portfolio construction analytics within and across fixed income, credit, commodity,
  38.  *      equity, FX, and structured products. It also includes auxiliary libraries for algorithm support,
  39.  *      numerical analysis, numerical optimization, spline builder, model validation, statistical learning,
  40.  *      and computational support.
  41.  *  
  42.  *      https://lakshmidrip.github.io/DROP/
  43.  *  
  44.  *  DROP is composed of three modules:
  45.  *  
  46.  *  - DROP Product Core - https://lakshmidrip.github.io/DROP-Product-Core/
  47.  *  - DROP Portfolio Core - https://lakshmidrip.github.io/DROP-Portfolio-Core/
  48.  *  - DROP Computational Core - https://lakshmidrip.github.io/DROP-Computational-Core/
  49.  *
  50.  *  DROP Product Core implements libraries for the following:
  51.  *  - Fixed Income Analytics
  52.  *  - Loan Analytics
  53.  *  - Transaction Cost Analytics
  54.  *
  55.  *  DROP Portfolio Core implements libraries for the following:
  56.  *  - Asset Allocation Analytics
  57.  *  - Asset Liability Management Analytics
  58.  *  - Capital Estimation Analytics
  59.  *  - Exposure Analytics
  60.  *  - Margin Analytics
  61.  *  - XVA Analytics
  62.  *
  63.  *  DROP Computational Core implements libraries for the following:
  64.  *  - Algorithm Support
  65.  *  - Computation Support
  66.  *  - Function Analysis
  67.  *  - Model Validation
  68.  *  - Numerical Analysis
  69.  *  - Numerical Optimizer
  70.  *  - Spline Builder
  71.  *  - Statistical Learning
  72.  *
  73.  *  Documentation for DROP is Spread Over:
  74.  *
  75.  *  - Main                     => https://lakshmidrip.github.io/DROP/
  76.  *  - Wiki                     => https://github.com/lakshmiDRIP/DROP/wiki
  77.  *  - GitHub                   => https://github.com/lakshmiDRIP/DROP
  78.  *  - Repo Layout Taxonomy     => https://github.com/lakshmiDRIP/DROP/blob/master/Taxonomy.md
  79.  *  - Javadoc                  => https://lakshmidrip.github.io/DROP/Javadoc/index.html
  80.  *  - Technical Specifications => https://github.com/lakshmiDRIP/DROP/tree/master/Docs/Internal
  81.  *  - Release Versions         => https://lakshmidrip.github.io/DROP/version.html
  82.  *  - Community Credits        => https://lakshmidrip.github.io/DROP/credits.html
  83.  *  - Issues Catalog           => https://github.com/lakshmiDRIP/DROP/issues
  84.  *  - JUnit                    => https://lakshmidrip.github.io/DROP/junit/index.html
  85.  *  - Jacoco                   => https://lakshmidrip.github.io/DROP/jacoco/index.html
  86.  *
  87.  *  Licensed under the Apache License, Version 2.0 (the "License");
  88.  *      you may not use this file except in compliance with the License.
  89.  *  
  90.  *  You may obtain a copy of the License at
  91.  *      http://www.apache.org/licenses/LICENSE-2.0
  92.  *  
  93.  *  Unless required by applicable law or agreed to in writing, software
  94.  *      distributed under the License is distributed on an "AS IS" BASIS,
  95.  *      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  96.  *  
  97.  *  See the License for the specific language governing permissions and
  98.  *      limitations under the License.
  99.  */

  100. /**
  101.  * <i>BasketAggregateMeasuresGeneration</i> contains a demo of the bond basket Measure generation Sample. It
  102.  * shows the following:
  103.  *  
  104.  * <br><br>
  105.  *  <ul>
  106.  *      <li>
  107.  *          Build the IR Curve from the Rates' instruments.
  108.  *      </li>
  109.  *      <li>
  110.  *          Build the Component Credit Curve from the CDS instruments.
  111.  *      </li>
  112.  *      <li>
  113.  *          Create the basket market parameters and add the named discount curve and the credit curves to it.
  114.  *      </li>
  115.  *      <li>
  116.  *          Create the bond basket from the component bonds and their weights.
  117.  *      </li>
  118.  *      <li>
  119.  *          Construct the Valuation and the Pricing Parameters.
  120.  *      </li>
  121.  *      <li>
  122.  *          Generate the bond basket measures from the valuation, the pricer, and the market parameters.
  123.  *      </li>
  124.  *  </ul>
  125.  * <br><br>
  126.  *  
  127.  * <br><br>
  128.  *  <ul>
  129.  *      <li><b>Module </b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/ProductCore.md">Product Core Module</a></li>
  130.  *      <li><b>Library</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/FixedIncomeAnalyticsLibrary.md">Fixed Income Analytics</a></li>
  131.  *      <li><b>Project</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/sample/README.md">DROP API Construction and Usage</a></li>
  132.  *      <li><b>Package</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/sample/bond/README.md">Bullet, EOS Bond Metrics + Curve</a></li>
  133.  *  </ul>
  134.  * <br><br>
  135.  *
  136.  * @author Lakshmi Krishnamurthy
  137.  */

  138. public class BasketAggregateMeasuresGeneration {

  139.     private static final FixFloatComponent IRS (
  140.         final JulianDate dtEffective,
  141.         final String strCurrency,
  142.         final String strMaturityTenor,
  143.         final double dblCoupon)
  144.         throws Exception
  145.     {
  146.         UnitCouponAccrualSetting ucasFixed = new UnitCouponAccrualSetting (
  147.             2,
  148.             "Act/360",
  149.             false,
  150.             "Act/360",
  151.             false,
  152.             strCurrency,
  153.             true,
  154.             CompositePeriodBuilder.ACCRUAL_COMPOUNDING_RULE_GEOMETRIC
  155.         );

  156.         ComposableFloatingUnitSetting cfusFloating = new ComposableFloatingUnitSetting (
  157.             "3M",
  158.             CompositePeriodBuilder.EDGE_DATE_SEQUENCE_REGULAR,
  159.             null,
  160.             ForwardLabel.Create (
  161.                 strCurrency,
  162.                 "3M"
  163.             ),
  164.             CompositePeriodBuilder.REFERENCE_PERIOD_IN_ADVANCE,
  165.             0.
  166.         );

  167.         ComposableFixedUnitSetting cfusFixed = new ComposableFixedUnitSetting (
  168.             "6M",
  169.             CompositePeriodBuilder.EDGE_DATE_SEQUENCE_REGULAR,
  170.             null,
  171.             dblCoupon,
  172.             0.,
  173.             strCurrency
  174.         );

  175.         CompositePeriodSetting cpsFloating = new CompositePeriodSetting (
  176.             4,
  177.             "3M",
  178.             strCurrency,
  179.             null,
  180.             -1.,
  181.             null,
  182.             null,
  183.             null,
  184.             null
  185.         );

  186.         CompositePeriodSetting cpsFixed = new CompositePeriodSetting (
  187.             2,
  188.             "6M",
  189.             strCurrency,
  190.             null,
  191.             1.,
  192.             null,
  193.             null,
  194.             null,
  195.             null
  196.         );

  197.         CashSettleParams csp = new CashSettleParams (
  198.             0,
  199.             strCurrency,
  200.             0
  201.         );

  202.         List<Integer> lsFixedStreamEdgeDate = CompositePeriodBuilder.RegularEdgeDates (
  203.             dtEffective,
  204.             "6M",
  205.             strMaturityTenor,
  206.             null
  207.         );

  208.         List<Integer> lsFloatingStreamEdgeDate = CompositePeriodBuilder.RegularEdgeDates (
  209.             dtEffective,
  210.             "3M",
  211.             strMaturityTenor,
  212.             null
  213.         );

  214.         Stream floatingStream = new Stream (
  215.             CompositePeriodBuilder.FloatingCompositeUnit (
  216.                 lsFloatingStreamEdgeDate,
  217.                 cpsFloating,
  218.                 cfusFloating
  219.             )
  220.         );

  221.         Stream fixedStream = new Stream (
  222.             CompositePeriodBuilder.FixedCompositeUnit (
  223.                 lsFixedStreamEdgeDate,
  224.                 cpsFixed,
  225.                 ucasFixed,
  226.                 cfusFixed
  227.             )
  228.         );

  229.         FixFloatComponent irs = new FixFloatComponent (
  230.             fixedStream,
  231.             floatingStream,
  232.             csp
  233.         );

  234.         irs.setPrimaryCode ("IRS." + strMaturityTenor + "." + strCurrency);

  235.         return irs;
  236.     }

  237.     /*
  238.      * Sample demonstrating creation of a rates curve from instruments
  239.      *
  240.      *      USE WITH CARE: This sample ignores errors and does not handle exceptions.
  241.      */

  242.     private static MergedDiscountForwardCurve BuildRatesCurveFromInstruments (
  243.         final JulianDate dtStart,
  244.         final String[] astrCashTenor,
  245.         final double[] adblCashRate,
  246.         final String[] astrIRSTenor,
  247.         final double[] adblIRSRate,
  248.         final double dblBump,
  249.         final String strCurrency)
  250.         throws Exception
  251.     {
  252.         int iNumDCInstruments = astrCashTenor.length + adblIRSRate.length;
  253.         int aiDate[] = new int[iNumDCInstruments];
  254.         double adblRate[] = new double[iNumDCInstruments];
  255.         String astrCalibMeasure[] = new String[iNumDCInstruments];
  256.         double adblCompCalibValue[] = new double[iNumDCInstruments];
  257.         CalibratableComponent aCompCalib[] = new CalibratableComponent[iNumDCInstruments];

  258.         // Cash Calibration

  259.         JulianDate dtCashEffective = dtStart.addBusDays (1, strCurrency);

  260.         for (int i = 0; i < astrCashTenor.length; ++i) {
  261.             astrCalibMeasure[i] = "Rate";
  262.             adblRate[i] = java.lang.Double.NaN;
  263.             adblCompCalibValue[i] = adblCashRate[i] + dblBump;

  264.             aCompCalib[i] = SingleStreamComponentBuilder.Deposit (
  265.                 dtCashEffective,
  266.                 new JulianDate (aiDate[i] = dtCashEffective.addTenor (astrCashTenor[i]).julian()),
  267.                 ForwardLabel.Create (
  268.                     strCurrency,
  269.                     astrCashTenor[i]
  270.                 )
  271.             );
  272.         }

  273.         // IRS Calibration

  274.         JulianDate dtIRSEffective = dtStart.addBusDays (
  275.             2,
  276.             strCurrency
  277.         );

  278.         for (int i = 0; i < astrIRSTenor.length; ++i) {
  279.             astrCalibMeasure[i + astrCashTenor.length] = "Rate";
  280.             adblRate[i + astrCashTenor.length] = java.lang.Double.NaN;
  281.             adblCompCalibValue[i + astrCashTenor.length] = adblIRSRate[i] + dblBump;

  282.             aiDate[i + astrCashTenor.length] = dtIRSEffective.addTenor (astrIRSTenor[i]).julian();

  283.             aCompCalib[i + astrCashTenor.length] = IRS (
  284.                 dtIRSEffective,
  285.                 strCurrency,
  286.                 astrIRSTenor[i],
  287.                 0.
  288.             );
  289.         }

  290.         /*
  291.          * Build the IR curve from the components, their calibration measures, and their calibration quotes.
  292.          */

  293.         return ScenarioDiscountCurveBuilder.NonlinearBuild (
  294.             dtStart,
  295.             strCurrency,
  296.             aCompCalib,
  297.             adblCompCalibValue,
  298.             astrCalibMeasure,
  299.             null
  300.         );
  301.     }

  302.     /*
  303.      * Sample demonstrating creation of simple fixed coupon treasury bond
  304.      *
  305.      *      USE WITH CARE: This sample ignores errors and does not handle exceptions.
  306.      */

  307.     private static final Bond CreateTSYBond (
  308.         final String strName,
  309.         final double dblCoupon,
  310.         final JulianDate dt,
  311.         final String strTenor)
  312.         throws Exception
  313.     {
  314.         return BondBuilder.CreateSimpleFixed (  // Simple Fixed Rate Bond
  315.             strName,                    // Name
  316.             "USD",                  // Fictitious Treasury Curve Name
  317.             "",                         // Credit Curve - Empty for now
  318.             dblCoupon,                  // Bond Coupon
  319.             2,                          // Frequency
  320.             "Act/Act",                  // Day Count
  321.             dt,                         // Effective
  322.             dt.addTenor (strTenor),     // Maturity
  323.             null,                       // Principal Schedule
  324.             null
  325.         );
  326.     }

  327.     /*
  328.      * Sample demonstrating creation of a set of the on-the-run treasury bonds
  329.      *
  330.      *      USE WITH CARE: This sample ignores errors and does not handle exceptions.
  331.      */

  332.     private static final Bond[] CreateOnTheRunTSYBondSet (
  333.         final JulianDate dt,
  334.         final String[] astrTenor,
  335.         final double[] adblCoupon)
  336.         throws Exception
  337.     {
  338.         Bond aTSYBond[] = new Bond[astrTenor.length];

  339.         for (int i = 0; i < astrTenor.length; ++i)
  340.             aTSYBond[i] = CreateTSYBond (
  341.                 "TSY" + astrTenor[i] + "ON",
  342.                 adblCoupon[i],
  343.                 dt,
  344.                 astrTenor[i]
  345.             );

  346.         return aTSYBond;
  347.     }

  348.     /*
  349.      * Sample demonstrating building of the treasury discount curve based off the on-the run instruments and their yields
  350.      *
  351.      *      USE WITH CARE: This sample ignores errors and does not handle exceptions.
  352.      */

  353.     private static final MergedDiscountForwardCurve BuildOnTheRunTSYDiscountCurve (
  354.         final JulianDate dt,
  355.         final Bond[] aTSYBond,
  356.         final double[] adblTSYYield)
  357.         throws Exception
  358.     {
  359.         String astrCalibMeasure[] = new String[aTSYBond.length];

  360.         for (int i = 0; i < aTSYBond.length; ++i)
  361.             astrCalibMeasure[i] = "Yield";

  362.         return ScenarioDiscountCurveBuilder.NonlinearBuild (
  363.             dt,
  364.             "USD", // Fake curve name to indicate it is a USD TSY curve, not the usual USD curve
  365.             aTSYBond,
  366.             adblTSYYield,
  367.             astrCalibMeasure,
  368.             null
  369.         );
  370.     }

  371.     /*
  372.      * Sample demonstrating creation of the principal factor schedule from date and factor array
  373.      *
  374.      *      USE WITH CARE: This sample ignores errors and does not handle exceptions.
  375.      */

  376.     private static final Array2D MakeFSPrincipal()
  377.         throws Exception
  378.     {
  379.         double[] aiDate = new double[5];
  380.         double[] adblFactor = new double[] {1., 1.0, 1.0, 1.0, 1.0};
  381.         // double[] adblFactor = new double[] {1., 0.9, 0.8, 0.7, 0.6};

  382.         JulianDate dtEOSStart = DateUtil.Today().addDays (2);

  383.         for (int i = 0; i < 5; ++i)
  384.             aiDate[i] = dtEOSStart.addYears (i + 2).julian();

  385.         return Array2D.FromArray (
  386.             aiDate,
  387.             adblFactor
  388.         );
  389.     }

  390.     /*
  391.      * Sample demonstrating creation of the coupon factor schedule from date and factor array
  392.      *
  393.      *      USE WITH CARE: This sample ignores errors and does not handle exceptions.
  394.      */

  395.     private static final Array2D MakeFSCoupon()
  396.         throws Exception
  397.     {
  398.         double[] aiDate = new double[5];
  399.         double[] adblFactor = new double[] {1., 1.0, 1.0, 1.0, 1.0};
  400.         // double[] adblFactor = new double[] {1., 0.9, 0.8, 0.7, 0.6};

  401.         JulianDate dtEOSStart = DateUtil.Today().addDays (2);

  402.         for (int i = 0; i < 5; ++i)
  403.             aiDate[i] = dtEOSStart.addYears (i + 2).julian();

  404.         return Array2D.FromArray (
  405.             aiDate,
  406.             adblFactor
  407.         );
  408.     }

  409.     /*
  410.      * Sample demonstrating the creation/usage of the bond basket API
  411.      *
  412.      *      USE WITH CARE: This sample ignores errors and does not handle exceptions.
  413.      */

  414.     private static final void BasketBondAPISample()
  415.         throws Exception
  416.     {
  417.         JulianDate dtCurve = DateUtil.CreateFromYMD (
  418.             2013,
  419.             6,
  420.             27
  421.         );

  422.         JulianDate dtSettle = DateUtil.CreateFromYMD (
  423.             2013,
  424.             7,
  425.             1
  426.         );

  427.         /*
  428.          * Build the IR Curve from the Rates' instruments
  429.          */

  430.         String[] astrCashTenor = new String[] {"3M"};
  431.         double[] adblCashRate = new double[] {0.00276};
  432.         String[] astrIRSTenor = new String[] {   "1Y",    "2Y",    "3Y",    "4Y",    "5Y",    "6Y",    "7Y",
  433.                "8Y",    "9Y",   "10Y",   "11Y",   "12Y",   "15Y",   "20Y",   "25Y",   "30Y",   "40Y",   "50Y"};
  434.         double[] adblIRSRate = new double[]  {0.00367, 0.00533, 0.00843, 0.01238, 0.01609, 0.01926, 0.02191,
  435.             0.02406, 0.02588, 0.02741, 0.02870, 0.02982, 0.03208, 0.03372, 0.03445, 0.03484, 0.03501, 0.03484};

  436.         MergedDiscountForwardCurve dc = BuildRatesCurveFromInstruments (dtCurve, astrCashTenor, adblCashRate, astrIRSTenor, adblIRSRate, 0., "USD");

  437.         /*
  438.          * Construct the set of Treasury instruments (in the case on-the-run set)
  439.          */

  440.         String[] astrTSYTenor = new String[] {
  441.             "1Y", "2Y", "3Y", "5Y", "7Y", "10Y", "30Y"
  442.         };
  443.         final double[] adblTSYCoupon = new double[] {
  444.             0.0000, 0.00375, 0.00500, 0.0100, 0.01375, 0.01375, 0.02875
  445.         };

  446.         Bond[] aTSYBond = CreateOnTheRunTSYBondSet (
  447.             dtCurve,
  448.             astrTSYTenor,
  449.             adblTSYCoupon
  450.         );

  451.         /*
  452.          * Build the Treasury Curve from the Treasury instruments and their yields
  453.          */

  454.         double[] adblTSYYield = new double[] {
  455.             0.00160, 0.00397, 0.00696, 0.01421, 0.01955, 0.02529, 0.03568
  456.         };

  457.         MergedDiscountForwardCurve dcTSY = BuildOnTheRunTSYDiscountCurve (
  458.             dtCurve,
  459.             aTSYBond,
  460.             adblTSYYield
  461.         );

  462.         /*
  463.          * Construct the set of bonds and load them onto the basket
  464.          */

  465.         BondComponent bond1 = BondBuilder.CreateSimpleFixed (
  466.             "TEST1",                                               // Name
  467.             "USD",                                  // Currency
  468.             "",                                     // Credit Curve - Empty for now
  469.             0.09,                                      // Bond Coupon
  470.             2,                                                            // Frequency
  471.             "30/360",                             // Day Count
  472.             DateUtil.CreateFromYMD (
  473.                 2011,
  474.                 2,
  475.                 23
  476.             ), // Effective
  477.             DateUtil.CreateFromYMD (
  478.                 2021,
  479.                 3,
  480.                 1
  481.             ),               // Maturity
  482.             null,                       // Principal Schedule
  483.             null
  484.         );

  485.         BondComponent bond2 = BondBuilder.CreateSimpleFixed (    // Simple Fixed Rate Bond
  486.             "TEST2",                                               // Name
  487.             "USD",                                  // Currency
  488.             "",                                     // Credit Curve - Empty for now
  489.             0.09,                                      // Bond Coupon
  490.             2,                                                            // Frequency
  491.             "30/360",                             // Day Count
  492.             DateUtil.CreateFromYMD (
  493.                 2011,
  494.                 2,
  495.                 23
  496.             ), // Effective
  497.             DateUtil.CreateFromYMD (
  498.                 2021,
  499.                 3,
  500.                 1
  501.             ),               // Maturity
  502.             null,                       // Principal Schedule
  503.             null
  504.         );

  505.         BondComponent bond3 = BondBuilder.CreateSimpleFixed (    // Simple Fixed Rate Bond
  506.             "TEST3",                                               // Name
  507.             "USD",                                  // Currency
  508.             "",                                     // Credit Curve - Empty for now
  509.             0.09,                                      // Bond Coupon
  510.             2,                                                            // Frequency
  511.             "30/360",                             // Day Count
  512.             DateUtil.CreateFromYMD (
  513.                 2011,
  514.                 2,
  515.                 23
  516.             ), // Effective
  517.             DateUtil.CreateFromYMD (
  518.                 2021,
  519.                 3,
  520.                 1
  521.             ),               // Maturity
  522.             null,                       // Principal Schedule
  523.             null
  524.         );

  525.         BondComponent bond4 = BondBuilder.CreateSimpleFloater ( // Simple Floating Rate Bond
  526.             "FLOATER1",     // Name
  527.             "USD",          // Currency
  528.             "USD-6M",   // Rate Index
  529.             "",             // Credit Curve - Empty for now
  530.             0.01,           // Floating Spread
  531.             2,              // Coupon Frequency
  532.             "30/360",       // Day Count
  533.             DateUtil.CreateFromYMD (
  534.                 2008,
  535.                 9,
  536.                 21
  537.             ), // Effective
  538.             DateUtil.CreateFromYMD (
  539.                 2023,
  540.                 9,
  541.                 20
  542.             ),  // Maturity
  543.             MakeFSPrincipal(),      // Principal Schedule
  544.             MakeFSCoupon()      // Coupon Schedule
  545.         );

  546.         BasketProduct bb = new BondBasket (
  547.             "TurtlePower",
  548.             new Bond[] {
  549.                 bond1, bond2, bond3, bond4
  550.             },
  551.             new double[] {
  552.                 0.1, 0.2, 0.3, 0.4
  553.             }
  554.         );

  555.         /*
  556.          * Create the basket market parameters and add the named discount curve and the treasury curves to it.
  557.          */

  558.         CurveSurfaceQuoteContainer mktParams = new CurveSurfaceQuoteContainer();

  559.         mktParams.setFundingState (dc);

  560.         mktParams.setFundingState (dcTSY);

  561.         /*
  562.          * Construct the Valuation and the Pricing Parameters
  563.          */

  564.         ValuationParams valParams = ValuationParams.Spot (
  565.             dtSettle,
  566.             0,
  567.             "USD",
  568.             Convention.DATE_ROLL_ACTUAL
  569.         );

  570.         CreditPricerParams pricerParams = new CreditPricerParams (
  571.             7,
  572.             null,
  573.             false,
  574.             CreditPricerParams.PERIOD_DISCRETIZATION_FULL_COUPON
  575.         );

  576.         /*
  577.          * Generate the bond basket measures from the valuation, the pricer, and the market parameters
  578.          */

  579.         CaseInsensitiveTreeMap<Double> mapResult = bb.value (
  580.             valParams,
  581.             pricerParams,
  582.             mktParams,
  583.             null
  584.         );

  585.         System.out.println ("Clean Price:      " + FormatUtil.FormatDouble (mapResult.get ("CleanPrice"), 0, 2, 100.));

  586.         System.out.println ("Fair Clean Price: " + FormatUtil.FormatDouble (mapResult.get ("FairCleanPrice"), 0, 2, 100.));

  587.         System.out.println ("Fair Yield:       " + FormatUtil.FormatDouble (mapResult.get ("FairYield"), 0, 2, 100.));

  588.         System.out.println ("Fair GSpread:     " + FormatUtil.FormatDouble (mapResult.get ("FairGSpread"), 0, 0, 10000.));

  589.         System.out.println ("Fair ZSpread:     " + FormatUtil.FormatDouble (mapResult.get ("FairZSpread"), 0, 0, 10000.));

  590.         System.out.println ("Fair ISpread:     " + FormatUtil.FormatDouble (mapResult.get ("FairISpread"), 0, 0, 10000.));

  591.         System.out.println ("Fair Duration:    " + FormatUtil.FormatDouble (mapResult.get ("FairDuration"), 0, 2, 10000.));

  592.         System.out.println ("Accrued:          " + FormatUtil.FormatDouble (mapResult.get ("Accrued"), 1, 2, 100.));
  593.     }

  594.     public static final void main (
  595.         final String astrArgs[])
  596.         throws Exception
  597.     {
  598.         // String strConfig = "c:\\Lakshmi\\BondAnal\\Config.xml";

  599.         EnvManager.InitEnv (
  600.             "",
  601.             true
  602.         );

  603.         BasketBondAPISample();

  604.         EnvManager.TerminateEnv();
  605.     }
  606. }