CreditIndexConvention.java

  1. package org.drip.market.otc;

  2. /*
  3.  * -*- mode: java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  4.  */

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

  77. /**
  78.  * <i>CreditIndexConvention</i> contains the details of the Credit Index of an OTC Index CDS Contract.
  79.  *
  80.  *  <br><br>
  81.  *  <ul>
  82.  *      <li><b>Module </b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/ProductCore.md">Product Core Module</a></li>
  83.  *      <li><b>Library</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/FixedIncomeAnalyticsLibrary.md">Fixed Income Analytics Library</a></li>
  84.  *      <li><b>Project</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/market">Static Market Fields - the Definitions, the OTC/Exchange Traded Products, and Treasury Settings</a></li>
  85.  *      <li><b>Package</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/market/otc">OTC Dual Stream Option Container</a></li>
  86.  *  </ul>
  87.  *
  88.  * @author Lakshmi Krishnamurthy
  89.  */

  90. public class CreditIndexConvention {
  91.     private int _iFreq = -1;
  92.     private int _iNumConstituent = -1;
  93.     private java.lang.String _strTenor = "";
  94.     private java.lang.String _strCurrency = "";
  95.     private java.lang.String _strDayCount = "";
  96.     private java.lang.String _strIndexType = "";
  97.     private java.lang.String _strSeriesName = "";
  98.     private java.lang.String _strIndexSubType = "";
  99.     private double _dblFixedCoupon = java.lang.Double.NaN;
  100.     private double _dblRecoveryRate = java.lang.Double.NaN;
  101.     private org.drip.analytics.date.JulianDate _dtMaturity = null;
  102.     private org.drip.analytics.date.JulianDate _dtEffective = null;

  103.     /**
  104.      * CreditIndexConvention Constructor
  105.      *
  106.      * @param strIndexType Index Type
  107.      * @param strIndexSubType Index Sub-Type
  108.      * @param strSeriesName Series Name
  109.      * @param strTenor Index Tenor
  110.      * @param strCurrency Index Currency
  111.      * @param dtEffective Effective Date
  112.      * @param dtMaturity Maturity Date
  113.      * @param iFreq Coupon/Pay Frequency
  114.      * @param strDayCount Index Day Count
  115.      * @param dblFixedCoupon Index Fixed Coupon
  116.      * @param dblRecoveryRate Fixed Recovery Rate
  117.      * @param iNumConstituent Number of Constituents
  118.      *
  119.      * @throws java.lang.Exception Thrown if Inputs are Invalid
  120.      */

  121.     public CreditIndexConvention (
  122.         final java.lang.String strIndexType,
  123.         final java.lang.String strIndexSubType,
  124.         final java.lang.String strSeriesName,
  125.         final java.lang.String strTenor,
  126.         final java.lang.String strCurrency,
  127.         final org.drip.analytics.date.JulianDate dtEffective,
  128.         final org.drip.analytics.date.JulianDate dtMaturity,
  129.         final int iFreq,
  130.         final java.lang.String strDayCount,
  131.         final double dblFixedCoupon,
  132.         final double dblRecoveryRate,
  133.         final int iNumConstituent)
  134.         throws java.lang.Exception
  135.     {
  136.         if (null == (_strIndexType = strIndexType) || _strIndexType.isEmpty() || null == (_strIndexSubType =
  137.             strIndexSubType) || _strIndexType.isEmpty() || null == (_strSeriesName = strSeriesName) ||
  138.                 _strSeriesName.isEmpty() || null == (_strTenor = strTenor) || _strTenor.isEmpty() || null ==
  139.                     (_strCurrency = strCurrency) || _strCurrency.isEmpty() || null == (_dtEffective =
  140.                         dtEffective) || null == (_dtMaturity = dtMaturity) || 0 >= (_iFreq = iFreq) || null
  141.                             == (_strDayCount = strDayCount) || _strDayCount.isEmpty() ||
  142.                                 !org.drip.numerical.common.NumberUtil.IsValid (_dblFixedCoupon = dblFixedCoupon)
  143.                                     || !org.drip.numerical.common.NumberUtil.IsValid (_dblRecoveryRate =
  144.                                         dblRecoveryRate) || 0 >= (_iNumConstituent = iNumConstituent))
  145.             throw new java.lang.Exception ("CreditIndexConvention Constructor => Invalid Inputs");
  146.     }

  147.     /**
  148.      * Retrieve the Index Type
  149.      *
  150.      * @return The Index Type
  151.      */

  152.     public java.lang.String indexType()
  153.     {
  154.         return _strIndexType;
  155.     }

  156.     /**
  157.      * Retrieve the Index Sub-Type
  158.      *
  159.      * @return The Index Sub-Type
  160.      */

  161.     public java.lang.String indexSubType()
  162.     {
  163.         return _strIndexSubType;
  164.     }

  165.     /**
  166.      * Retrieve the Series Name
  167.      *
  168.      * @return The Series Name
  169.      */

  170.     public java.lang.String seriesName()
  171.     {
  172.         return _strSeriesName;
  173.     }

  174.     /**
  175.      * Retrieve the Tenor
  176.      *
  177.      * @return The Tenor
  178.      */

  179.     public java.lang.String tenor()
  180.     {
  181.         return _strTenor;
  182.     }

  183.     /**
  184.      * Retrieve the Currency
  185.      *
  186.      * @return The Currency
  187.      */

  188.     public java.lang.String currency()
  189.     {
  190.         return _strCurrency;
  191.     }

  192.     /**
  193.      * Retrieve the Effective Date
  194.      *
  195.      * @return The Effective Date
  196.      */

  197.     public org.drip.analytics.date.JulianDate effectiveDate()
  198.     {
  199.         return _dtEffective;
  200.     }

  201.     /**
  202.      * Retrieve the Maturity Date
  203.      *
  204.      * @return The Maturity Date
  205.      */

  206.     public org.drip.analytics.date.JulianDate maturityDate()
  207.     {
  208.         return _dtMaturity;
  209.     }

  210.     /**
  211.      * Retrieve the Coupon Frequency
  212.      *
  213.      * @return The Coupon Frequency
  214.      */

  215.     public int frequency()
  216.     {
  217.         return _iFreq;
  218.     }

  219.     /**
  220.      * Retrieve the Day Count
  221.      *
  222.      * @return The Day Count
  223.      */

  224.     public java.lang.String dayCount()
  225.     {
  226.         return _strDayCount;
  227.     }

  228.     /**
  229.      * Retrieve the Fixed Coupon
  230.      *
  231.      * @return The Fixed Coupon
  232.      */

  233.     public double fixedCoupon()
  234.     {
  235.         return _dblFixedCoupon;
  236.     }

  237.     /**
  238.      * Retrieve the Recovery Rate
  239.      *
  240.      * @return The Recovery Rate
  241.      */

  242.     public double recoveryRate()
  243.     {
  244.         return _dblRecoveryRate;
  245.     }

  246.     /**
  247.      * Retrieve the Number of Constituents
  248.      *
  249.      * @return The Number of Constituents
  250.      */

  251.     public int numberOfConstituents()
  252.     {
  253.         return _iNumConstituent;
  254.     }

  255.     /**
  256.      * Retrieve the Full Name of the Credit Index
  257.      *
  258.      * @return The Full Name of the Credit Index
  259.      */

  260.     public java.lang.String fullName()
  261.     {
  262.         return _strIndexType + "." + _strIndexSubType + "." + _strSeriesName + "." + _strTenor;
  263.     }

  264.     /**
  265.      * Create an Instance of the Specified Index CDS Product
  266.      *
  267.      * @return Instance of the Specified Index CDS Product
  268.      */

  269.     public org.drip.product.definition.CreditDefaultSwap indexCDS()
  270.     {
  271.         org.drip.product.params.CreditSetting cs = new org.drip.product.params.CreditSetting (30,
  272.             _dblRecoveryRate, false, _strIndexType + "." + _strIndexSubType + "." + _strSeriesName, true);

  273.         return cs.validate() ? org.drip.product.creator.CDSBuilder.CreateCDS (_dtEffective, _dtMaturity,
  274.             _dblFixedCoupon, _strCurrency, cs, _strCurrency, true) : null;
  275.     }
  276. }