CDSBasket.java

  1. package org.drip.product.credit;

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

  82. /**
  83.  * <i>CDSBasket</i> implements the basket default swap product contract details. It contains effective date,
  84.  * maturity date, coupon, coupon day count, coupon frequency, basket components, basket notional, loss pay
  85.  * lag, and optionally the outstanding notional schedule and the flat basket recovery. It also contains
  86.  * methods to serialize out of and de-serialize into byte arrays.
  87.  *
  88.  *  <br><br>
  89.  *  <ul>
  90.  *      <li><b>Module </b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/ProductCore.md">Product Core Module</a></li>
  91.  *      <li><b>Library</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/FixedIncomeAnalyticsLibrary.md">Fixed Income Analytics</a></li>
  92.  *      <li><b>Project</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/product/README.md">Product Components/Baskets for Credit, FRA, FX, Govvie, Rates, and Option AssetClasses</a></li>
  93.  *      <li><b>Package</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/product/credit/README.md">Credit Products - Components and Baskets</a></li>
  94.  *  </ul>
  95.  * <br><br>
  96.  *
  97.  * @author Lakshmi Krishnamurthy
  98.  */

  99. public class CDSBasket extends org.drip.product.definition.BasketProduct {
  100.     private double[] _adblWeight = null;
  101.     private java.lang.String _strName = "";
  102.     private org.drip.product.definition.Component[] _aComp = null;

  103.     /**
  104.      * Construct a CDS Basket from the components and their weights
  105.      *
  106.      * @param aComp Array of components
  107.      * @param adblWeight Weights of the components
  108.      * @param strName Name of the basket
  109.      *
  110.      * @throws java.lang.Exception Thrown if the inputs are invalid
  111.      */

  112.     public CDSBasket (
  113.         final org.drip.product.definition.Component[] aComp,
  114.         final double[] adblWeight,
  115.         final java.lang.String strName)
  116.         throws java.lang.Exception
  117.     {
  118.         if (null == aComp || 0 == aComp.length || null == adblWeight || 0 == adblWeight.length ||
  119.             aComp.length != adblWeight.length || null == strName || strName.isEmpty())
  120.             throw new java.lang.Exception ("CDSBasket ctr: Invalid inputs!");

  121.         _strName = strName;
  122.         double dblCumulativeWeight = 0.;
  123.         _adblWeight = new double[adblWeight.length];
  124.         _aComp = new org.drip.product.definition.Component[aComp.length];

  125.         for (int i = 0; i < aComp.length; ++i)
  126.             dblCumulativeWeight += _adblWeight[i];

  127.         for (int i = 0; i < aComp.length; ++i) {
  128.             if (null == (_aComp[i] = aComp[i]))
  129.                 throw new java.lang.Exception ("CDSBasket ctr: Invalid Inputs!");

  130.             _adblWeight[i] = adblWeight[i] / dblCumulativeWeight;
  131.         }
  132.     }

  133.     @Override public java.lang.String name()
  134.     {
  135.         return _strName;
  136.     }

  137.     @Override public org.drip.product.definition.Component[] components()
  138.     {
  139.         return _aComp;
  140.     }

  141.     @Override public int measureAggregationType (
  142.         final java.lang.String strMeasureName)
  143.     {
  144.         if ("AccrualDays".equalsIgnoreCase (strMeasureName))
  145.             return org.drip.product.definition.BasketProduct.MEASURE_AGGREGATION_TYPE_UNIT_ACCUMULATE;

  146.         if ("Accrued".equalsIgnoreCase (strMeasureName))
  147.             return org.drip.product.definition.BasketProduct.MEASURE_AGGREGATION_TYPE_CUMULATIVE;

  148.         if ("Accrued01".equalsIgnoreCase (strMeasureName))
  149.             return org.drip.product.definition.BasketProduct.MEASURE_AGGREGATION_TYPE_CUMULATIVE;

  150.         if ("CleanDV01".equalsIgnoreCase (strMeasureName))
  151.             return org.drip.product.definition.BasketProduct.MEASURE_AGGREGATION_TYPE_CUMULATIVE;

  152.         if ("CleanPV".equalsIgnoreCase (strMeasureName))
  153.             return org.drip.product.definition.BasketProduct.MEASURE_AGGREGATION_TYPE_CUMULATIVE;

  154.         if ("DirtyDV01".equalsIgnoreCase (strMeasureName))
  155.             return org.drip.product.definition.BasketProduct.MEASURE_AGGREGATION_TYPE_CUMULATIVE;

  156.         if ("DirtyPV".equalsIgnoreCase (strMeasureName))
  157.             return org.drip.product.definition.BasketProduct.MEASURE_AGGREGATION_TYPE_CUMULATIVE;

  158.         if ("DV01".equalsIgnoreCase (strMeasureName))
  159.             return org.drip.product.definition.BasketProduct.MEASURE_AGGREGATION_TYPE_CUMULATIVE;

  160.         if ("ExpLoss".equalsIgnoreCase (strMeasureName))
  161.             return org.drip.product.definition.BasketProduct.MEASURE_AGGREGATION_TYPE_CUMULATIVE;

  162.         if ("ExpLossNoRec".equalsIgnoreCase (strMeasureName))
  163.             return org.drip.product.definition.BasketProduct.MEASURE_AGGREGATION_TYPE_CUMULATIVE;

  164.         if ("FairAccrualDays".equalsIgnoreCase (strMeasureName))
  165.             return org.drip.product.definition.BasketProduct.MEASURE_AGGREGATION_TYPE_UNIT_ACCUMULATE;

  166.         if ("FairAccrued".equalsIgnoreCase (strMeasureName))
  167.             return org.drip.product.definition.BasketProduct.MEASURE_AGGREGATION_TYPE_CUMULATIVE;

  168.         if ("FairAccrued01".equalsIgnoreCase (strMeasureName))
  169.             return org.drip.product.definition.BasketProduct.MEASURE_AGGREGATION_TYPE_CUMULATIVE;

  170.         if ("FairCleanDV01".equalsIgnoreCase (strMeasureName))
  171.             return org.drip.product.definition.BasketProduct.MEASURE_AGGREGATION_TYPE_CUMULATIVE;

  172.         if ("FairCleanPV".equalsIgnoreCase (strMeasureName))
  173.             return org.drip.product.definition.BasketProduct.MEASURE_AGGREGATION_TYPE_CUMULATIVE;

  174.         if ("FairDirtyDV01".equalsIgnoreCase (strMeasureName))
  175.             return org.drip.product.definition.BasketProduct.MEASURE_AGGREGATION_TYPE_CUMULATIVE;

  176.         if ("FairDirtyPV".equalsIgnoreCase (strMeasureName))
  177.             return org.drip.product.definition.BasketProduct.MEASURE_AGGREGATION_TYPE_CUMULATIVE;

  178.         if ("FairDV01".equalsIgnoreCase (strMeasureName))
  179.             return org.drip.product.definition.BasketProduct.MEASURE_AGGREGATION_TYPE_CUMULATIVE;

  180.         if ("FairExpLoss".equalsIgnoreCase (strMeasureName))
  181.             return org.drip.product.definition.BasketProduct.MEASURE_AGGREGATION_TYPE_CUMULATIVE;

  182.         if ("FairExpLossNoRec".equalsIgnoreCase (strMeasureName))
  183.             return org.drip.product.definition.BasketProduct.MEASURE_AGGREGATION_TYPE_CUMULATIVE;

  184.         if ("FairFairPremium".equalsIgnoreCase (strMeasureName))
  185.             return org.drip.product.definition.BasketProduct.MEASURE_AGGREGATION_TYPE_WEIGHTED_CUMULATIVE;

  186.         if ("FairLossNoRecPV".equalsIgnoreCase (strMeasureName))
  187.             return org.drip.product.definition.BasketProduct.MEASURE_AGGREGATION_TYPE_CUMULATIVE;

  188.         if ("FairLossPV".equalsIgnoreCase (strMeasureName))
  189.             return org.drip.product.definition.BasketProduct.MEASURE_AGGREGATION_TYPE_CUMULATIVE;

  190.         if ("FairParSpread".equalsIgnoreCase (strMeasureName))
  191.             return org.drip.product.definition.BasketProduct.MEASURE_AGGREGATION_TYPE_WEIGHTED_CUMULATIVE;

  192.         if ("FairPremium".equalsIgnoreCase (strMeasureName))
  193.             return org.drip.product.definition.BasketProduct.MEASURE_AGGREGATION_TYPE_WEIGHTED_CUMULATIVE;

  194.         if ("FairPremiumPV".equalsIgnoreCase (strMeasureName))
  195.             return org.drip.product.definition.BasketProduct.MEASURE_AGGREGATION_TYPE_CUMULATIVE;

  196.         if ("FairPV".equalsIgnoreCase (strMeasureName))
  197.             return org.drip.product.definition.BasketProduct.MEASURE_AGGREGATION_TYPE_CUMULATIVE;

  198.         if ("FairUpfront".equalsIgnoreCase (strMeasureName))
  199.             return org.drip.product.definition.BasketProduct.MEASURE_AGGREGATION_TYPE_WEIGHTED_CUMULATIVE;

  200.         if ("LossNoRecPV".equalsIgnoreCase (strMeasureName))
  201.             return org.drip.product.definition.BasketProduct.MEASURE_AGGREGATION_TYPE_CUMULATIVE;

  202.         if ("LossPV".equalsIgnoreCase (strMeasureName))
  203.             return org.drip.product.definition.BasketProduct.MEASURE_AGGREGATION_TYPE_CUMULATIVE;

  204.         if ("MarketAccrualDays".equalsIgnoreCase (strMeasureName))
  205.             return org.drip.product.definition.BasketProduct.MEASURE_AGGREGATION_TYPE_UNIT_ACCUMULATE;

  206.         if ("MarketAccrued".equalsIgnoreCase (strMeasureName))
  207.             return org.drip.product.definition.BasketProduct.MEASURE_AGGREGATION_TYPE_CUMULATIVE;

  208.         if ("MarketAccrued01".equalsIgnoreCase (strMeasureName))
  209.             return org.drip.product.definition.BasketProduct.MEASURE_AGGREGATION_TYPE_CUMULATIVE;

  210.         if ("MarketCleanDV01".equalsIgnoreCase (strMeasureName))
  211.             return org.drip.product.definition.BasketProduct.MEASURE_AGGREGATION_TYPE_CUMULATIVE;

  212.         if ("MarketCleanPV".equalsIgnoreCase (strMeasureName))
  213.             return org.drip.product.definition.BasketProduct.MEASURE_AGGREGATION_TYPE_CUMULATIVE;

  214.         if ("MarketDirtyDV01".equalsIgnoreCase (strMeasureName))
  215.             return org.drip.product.definition.BasketProduct.MEASURE_AGGREGATION_TYPE_CUMULATIVE;

  216.         if ("MarketDirtyPV".equalsIgnoreCase (strMeasureName))
  217.             return org.drip.product.definition.BasketProduct.MEASURE_AGGREGATION_TYPE_CUMULATIVE;

  218.         if ("MarketDV01".equalsIgnoreCase (strMeasureName))
  219.             return org.drip.product.definition.BasketProduct.MEASURE_AGGREGATION_TYPE_CUMULATIVE;

  220.         if ("MarketExpLoss".equalsIgnoreCase (strMeasureName))
  221.             return org.drip.product.definition.BasketProduct.MEASURE_AGGREGATION_TYPE_CUMULATIVE;

  222.         if ("MarketExpLossNoRec".equalsIgnoreCase (strMeasureName))
  223.             return org.drip.product.definition.BasketProduct.MEASURE_AGGREGATION_TYPE_CUMULATIVE;

  224.         if ("MarketFairPremium".equalsIgnoreCase (strMeasureName))
  225.             return org.drip.product.definition.BasketProduct.MEASURE_AGGREGATION_TYPE_WEIGHTED_CUMULATIVE;

  226.         if ("MarketLossNoRecPV".equalsIgnoreCase (strMeasureName))
  227.             return org.drip.product.definition.BasketProduct.MEASURE_AGGREGATION_TYPE_CUMULATIVE;

  228.         if ("MarketLossPV".equalsIgnoreCase (strMeasureName))
  229.             return org.drip.product.definition.BasketProduct.MEASURE_AGGREGATION_TYPE_CUMULATIVE;

  230.         if ("MarketParSpread".equalsIgnoreCase (strMeasureName))
  231.             return org.drip.product.definition.BasketProduct.MEASURE_AGGREGATION_TYPE_WEIGHTED_CUMULATIVE;

  232.         if ("MarketPremiumPV".equalsIgnoreCase (strMeasureName))
  233.             return org.drip.product.definition.BasketProduct.MEASURE_AGGREGATION_TYPE_CUMULATIVE;

  234.         if ("MarketPV".equalsIgnoreCase (strMeasureName))
  235.             return org.drip.product.definition.BasketProduct.MEASURE_AGGREGATION_TYPE_CUMULATIVE;

  236.         if ("MarketUpfront".equalsIgnoreCase (strMeasureName))
  237.             return org.drip.product.definition.BasketProduct.MEASURE_AGGREGATION_TYPE_WEIGHTED_CUMULATIVE;

  238.         if ("ParSpread".equalsIgnoreCase (strMeasureName))
  239.             return org.drip.product.definition.BasketProduct.MEASURE_AGGREGATION_TYPE_WEIGHTED_CUMULATIVE;

  240.         if ("PremiumPV".equalsIgnoreCase (strMeasureName))
  241.             return org.drip.product.definition.BasketProduct.MEASURE_AGGREGATION_TYPE_CUMULATIVE;

  242.         if ("PV".equalsIgnoreCase (strMeasureName))
  243.             return org.drip.product.definition.BasketProduct.MEASURE_AGGREGATION_TYPE_CUMULATIVE;

  244.         if ("Upfront".equalsIgnoreCase (strMeasureName))
  245.             return org.drip.product.definition.BasketProduct.MEASURE_AGGREGATION_TYPE_WEIGHTED_CUMULATIVE;

  246.         return org.drip.product.definition.BasketProduct.MEASURE_AGGREGATION_TYPE_IGNORE;
  247.     }
  248. }