BuiltInCDSPortfolioDefinitions.java

  1. package org.drip.sample.credit;

  2. /*
  3.  * Generic imports
  4.  */

  5. import java.util.*;

  6. import org.drip.analytics.date.*;
  7. import org.drip.analytics.support.CaseInsensitiveTreeMap;
  8. import org.drip.product.definition.*;
  9. import org.drip.service.env.*;

  10. /*
  11.  * -*- mode: java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  12.  */

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

  89. /**
  90.  * <i>BuiltInCDSPortfolioDefinitions</i> displays the Built-in CDS Portfolios. It shows the following:
  91.  *  
  92.  * <br><br>
  93.  *  <ul>
  94.  *      <li>
  95.  *          Construct the CDX.NA.IG 5Y Series 17 index by name and series.
  96.  *      </li>
  97.  *      <li>
  98.  *          Construct the on-the-run CDX.NA.IG 5Y Series index.
  99.  *      </li>
  100.  *      <li>
  101.  *           List all the built-in CDX's - their names and descriptions.
  102.  *      </li>
  103.  *      <li>
  104.  *          Construct the on-the run CDX.EM 5Y corresponding to T - 1Y.
  105.  *      </li>
  106.  *      <li>
  107.  *          Construct the on-the run ITRAXX.ENERGY 5Y corresponding to T - 7Y.
  108.  *      </li>
  109.  *      <li>
  110.  *           Retrieve the full set of date/index series set for ITRAXX.ENERGY.
  111.  *      </li>
  112.  *  </ul>
  113.  *  
  114.  * <br><br>
  115.  *  <ul>
  116.  *      <li><b>Module </b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/ProductCore.md">Product Core Module</a></li>
  117.  *      <li><b>Library</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/FixedIncomeAnalyticsLibrary.md">Fixed Income Analytics</a></li>
  118.  *      <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>
  119.  *      <li><b>Package</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/sample/cashflow/README.md">Single Name Portfolio CDS Analytics</a></li>
  120.  *  </ul>
  121.  * <br><br>
  122.  *
  123.  * @author Lakshmi Krishnamurthy
  124.  */

  125. public class BuiltInCDSPortfolioDefinitions {

  126.     /*
  127.      * Sample demonstrating the creation/usage of the CDX API
  128.      *
  129.      *      USE WITH CARE: This sample ignores errors and does not handle exceptions.
  130.      */

  131.     private static final void BasketCDSAPISample()
  132.     {
  133.         JulianDate dtToday = DateUtil.CreateFromYMD (
  134.             2013,
  135.             DateUtil.MAY,
  136.             10
  137.         );

  138.         /*
  139.          * Construct the CDX.NA.IG 5Y Series 17 index by name and series
  140.          */

  141.         /* BasketProduct bpCDX = CreditAnalytics.MakeCDX (
  142.             "CDX.NA.IG",
  143.             17,
  144.             "5Y"
  145.         ); */

  146.         /*
  147.          * Construct the on-the-run CDX.NA.IG 5Y Series index
  148.          */

  149.         /* BasketProduct bpCDXOTR = CreditAnalytics.MakeCDX (
  150.             "CDX.NA.IG",
  151.             dtToday,
  152.             "5Y"
  153.         ); */

  154.         /*
  155.          * List of all the built-in CDX names
  156.          */

  157.         Set<String> setstrCDXNames = StandardCDXManager.GetCDXNames();

  158.         /*
  159.          * Descriptions of all the built-in CDX names
  160.          */

  161.         CaseInsensitiveTreeMap<String> mapCDXDescr = StandardCDXManager.GetCDXDescriptions();

  162.         /*
  163.          * Construct the on-the run CDX.EM 5Y corresponding to T - 1Y
  164.          */

  165.         BasketProduct bpPresetOTR = StandardCDXManager.GetOnTheRun (
  166.             "CDX.EM",
  167.             dtToday.subtractTenor ("1Y"),
  168.             "5Y"
  169.         );

  170.         /*
  171.          * Construct the on-the run ITRAXX.ENERGY 5Y corresponding to T - 7Y
  172.          */

  173.         BasketProduct bpPreLoadedOTR = StandardCDXManager.GetOnTheRun (
  174.             "ITRAXX.ENERGY",
  175.             dtToday.subtractTenor ("7Y"),
  176.             "5Y"
  177.         );

  178.         /*
  179.          * Retrieve the full set of date/index series set for ITRAXX.ENERGY
  180.          */

  181.         Map<JulianDate, Integer> mapCDXSeries = StandardCDXManager.GetCDXSeriesMap ("ITRAXX.ENERGY");

  182.         // System.out.println (bpCDX.name() + ": " + bpCDX.effective() + "=>" + bpCDX.maturity());

  183.         // System.out.println (bpCDXOTR.name() + ": " + bpCDXOTR.effective() + "=>" + bpCDXOTR.maturity());

  184.         int i = 0;

  185.         for (String strCDX : setstrCDXNames)
  186.             System.out.println ("CDX[" + i++ + "]: " + strCDX);

  187.         for (Map.Entry<String, String> meCDXDescr : mapCDXDescr.entrySet())
  188.             System.out.println ("[" + meCDXDescr.getKey() + "]: " + meCDXDescr.getValue());

  189.         System.out.println (bpPresetOTR.name() + ": " + bpPresetOTR.effective() + "=>" + bpPresetOTR.maturity());

  190.         System.out.println (bpPreLoadedOTR.name() + ": " + bpPreLoadedOTR.effective() + "=>" + bpPreLoadedOTR.maturity());

  191.         for (Map.Entry<JulianDate, Integer> me : mapCDXSeries.entrySet())
  192.             System.out.println ("ITRAXX.ENERGY[" + me.getValue() + "]: " + me.getKey());
  193.     }

  194.     public static final void main (
  195.         final String astrArgs[])
  196.         throws Exception
  197.     {
  198.         // String strConfig = "c:\\Lakshmi\\BondAnal\\Config.xml";

  199.         String strConfig = "";

  200.         EnvManager.InitEnv (strConfig);

  201.         BasketCDSAPISample();

  202.         EnvManager.TerminateEnv();
  203.     }
  204. }