FundingGroup.java

  1. package org.drip.xva.topology;

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

  75. /**
  76.  * <i>FundingGroup</i> represents an Aggregation of Credit Debt Groups with a common Funding Group
  77.  * Specification. The References are:
  78.  *
  79.  *  <br><br>
  80.  *  <ul>
  81.  *      <li>
  82.  *          Albanese, C., L. Andersen, and, S. Iabichino (2015): The FVA Puzzle: Accounting, Risk Management,
  83.  *              and Collateral Trading https://papers.ssrn.com/sol3/paper.cfm?abstract_id_2517301
  84.  *              <b>eSSRN</b>
  85.  *      </li>
  86.  *      <li>
  87.  *          Burgard, C., and M. Kjaer (2014): PDE Representations of Derivatives with Bilateral Counter-party
  88.  *              Risk and Funding Costs <i>Journal of Credit Risk</i> <b>7 (3)</b> 1-19
  89.  *      </li>
  90.  *      <li>
  91.  *          Burgard, C., and M. Kjaer (2014): In the Balance <i>Risk</i> <b>24 (11)</b> 72-75
  92.  *      </li>
  93.  *      <li>
  94.  *          Gregory, J. (2009): Being Two-faced over Counter-party Credit Risk <i>Risk</i> <b>20 (2)</b>
  95.  *              86-90
  96.  *      </li>
  97.  *      <li>
  98.  *          Piterbarg, V. (2010): Funding Beyond Discounting: Collateral Agreements and Derivatives Pricing
  99.  *              <i>Risk</i> <b>21 (2)</b> 97-102
  100.  *      </li>
  101.  *  </ul>
  102.  *
  103.  *  <br><br>
  104.  *  <ul>
  105.  *      <li><b>Module </b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/PortfolioCore.md">Portfolio Core Module</a></li>
  106.  *      <li><b>Library</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/XVAAnalyticsLibrary.md">XVA Analytics Library</a></li>
  107.  *      <li><b>Project</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/xva/README.md">Valuation Adjustments that account for Collateral, CC Credit/Debt and Funding Overhead</a></li>
  108.  *      <li><b>Package</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/xva/topology/README.md">Collateral, Credit/Debt, Funding Topologies</a></li>
  109.  *  </ul>
  110.  * <br><br>
  111.  *
  112.  * @author Lakshmi Krishnamurthy
  113.  */

  114. public class FundingGroup extends org.drip.xva.proto.ObjectSpecification
  115. {
  116.     private org.drip.xva.proto.FundingGroupSpecification _fundingGroupSpecification = null;
  117.     private java.util.Map<java.lang.String, org.drip.xva.topology.CreditDebtGroup> _creditDebtGroupMap =
  118.         null;

  119.     /**
  120.      * FundingGroup Constructor
  121.      *
  122.      * @param id FundingGroup ID
  123.      * @param name FundingGroup Name
  124.      * @param fundingGroupSpecification Funding Group Specification
  125.      *
  126.      * @throws java.lang.Exception Thrown if the Inputs are Invalid
  127.      */

  128.     public FundingGroup (
  129.         final java.lang.String id,
  130.         final java.lang.String name,
  131.         final org.drip.xva.proto.FundingGroupSpecification fundingGroupSpecification)
  132.         throws java.lang.Exception
  133.     {
  134.         super (
  135.             id,
  136.             name
  137.         );

  138.         if (null == (_fundingGroupSpecification = fundingGroupSpecification))
  139.         {
  140.             throw new java.lang.Exception ("FundingGroup Constructor => Invalid Inputs");
  141.         }

  142.         _creditDebtGroupMap = new
  143.             org.drip.analytics.support.CaseInsensitiveHashMap<org.drip.xva.topology.CreditDebtGroup>();
  144.     }

  145.     /**
  146.      * Retrieve the Funding Group Specification
  147.      *
  148.      * @return The Funding Group Specification
  149.      */

  150.     public org.drip.xva.proto.FundingGroupSpecification fundingGroupSpecification()
  151.     {
  152.         return _fundingGroupSpecification;
  153.     }

  154.     /**
  155.      * Retrieve the Credit Debt Group Map
  156.      *
  157.      * @return The Credit Debt Group Map
  158.      */

  159.     public java.util.Map<java.lang.String, org.drip.xva.topology.CreditDebtGroup> creditDebtGroupMap()
  160.     {
  161.         return _creditDebtGroupMap;
  162.     }

  163.     /**
  164.      * Add the specified CreditDebtGroup Instance
  165.      *
  166.      * @param creditDebtGroup The CreditDebtGroup Instance
  167.      *
  168.      * @return TRUE - The CreditDebtGroup Instance successfully added
  169.      */

  170.     public boolean addCreditDebtGroup (
  171.         final org.drip.xva.topology.CreditDebtGroup creditDebtGroup)
  172.     {
  173.         if (null == creditDebtGroup)
  174.         {
  175.             return false;
  176.         }

  177.         _creditDebtGroupMap.put (
  178.             creditDebtGroup.id(),
  179.             creditDebtGroup
  180.         );

  181.         return true;
  182.     }

  183.     /**
  184.      * Indicate the specified CreditDebtGroup ID is available
  185.      *
  186.      * @param creditDebtGroupID The CreditDebtGroup ID
  187.      *
  188.      * @return TRUE - The CreditDebtGroup is available
  189.      */

  190.     public boolean containsCreditDebtGroup (
  191.         final java.lang.String creditDebtGroupID)
  192.     {
  193.         return null == creditDebtGroupID || creditDebtGroupID.isEmpty() ? false :
  194.             _creditDebtGroupMap.containsKey (creditDebtGroupID);
  195.     }

  196.     /**
  197.      * Retrieve the CreditDebtGroup
  198.      *
  199.      * @param creditDebtGroupID The CreditDebtGroup ID
  200.      *
  201.      * @return The CreditDebtGroup Instance
  202.      */

  203.     public org.drip.xva.topology.CreditDebtGroup creditDebtGroup (
  204.         final java.lang.String creditDebtGroupID)
  205.     {
  206.         return containsCreditDebtGroup (creditDebtGroupID) ? _creditDebtGroupMap.get (creditDebtGroupID) :
  207.             null;
  208.     }

  209.     /**
  210.      * Retrieve the Dealer Senior Funding Label
  211.      *
  212.      * @return The Dealer Senior Funding Label
  213.      */

  214.     public org.drip.state.identifier.EntityFundingLabel dealerSeniorFundingLabel()
  215.     {
  216.         return _fundingGroupSpecification.dealerSeniorFundingLabel();
  217.     }

  218.     /**
  219.      * Retrieve the Client Funding Label
  220.      *
  221.      * @return The Client Funding Label
  222.      */

  223.     public org.drip.state.identifier.EntityFundingLabel clientFundingLabel()
  224.     {
  225.         return _fundingGroupSpecification.clientFundingLabel();
  226.     }

  227.     /**
  228.      * Retrieve the Dealer Subordinate Funding Label
  229.      *
  230.      * @return The Dealer Subordinate Funding Label
  231.      */

  232.     public org.drip.state.identifier.EntityFundingLabel dealerSubordinateFundingLabel()
  233.     {
  234.         return _fundingGroupSpecification.dealerSubordinateFundingLabel();
  235.     }

  236.     /**
  237.      * Retrieve the Overnight Label Map
  238.      *
  239.      * @return The Overnight Label Map
  240.      */

  241.     public java.util.Map<java.lang.String, org.drip.state.identifier.OvernightLabel> overnightLabelMap()
  242.     {
  243.         java.util.Map<java.lang.String, org.drip.state.identifier.OvernightLabel> overnightLabelMap = new
  244.             org.drip.analytics.support.CaseInsensitiveHashMap<org.drip.state.identifier.OvernightLabel>();

  245.         for (java.util.Map.Entry<java.lang.String, org.drip.xva.topology.CreditDebtGroup>
  246.             creditDebtGroupEntry : _creditDebtGroupMap.entrySet())
  247.         {
  248.             java.util.Map<java.lang.String, org.drip.xva.topology.CollateralGroup> collateralGroupMap =
  249.                 creditDebtGroupEntry.getValue().collateralGroupMap();

  250.             for (java.util.Map.Entry<java.lang.String, org.drip.xva.topology.CollateralGroup>
  251.                 collateralGroupMapEntry : collateralGroupMap.entrySet())
  252.             {
  253.                 org.drip.state.identifier.OvernightLabel overnightLabel =
  254.                     collateralGroupMapEntry.getValue().overnightLabel();

  255.                 java.lang.String overnightLabelFQN = overnightLabel.fullyQualifiedName();

  256.                 if (!overnightLabelMap.containsKey (overnightLabelFQN))
  257.                 {
  258.                     overnightLabelMap.put (
  259.                         overnightLabelFQN,
  260.                         overnightLabel
  261.                     );
  262.                 }
  263.             }
  264.         }

  265.         return overnightLabelMap;
  266.     }

  267.     /**
  268.      * Retrieve the CSA Label Map
  269.      *
  270.      * @return The CSA Label Map
  271.      */

  272.     public java.util.Map<java.lang.String, org.drip.state.identifier.CSALabel> csaLabelMap()
  273.     {
  274.         java.util.Map<java.lang.String, org.drip.state.identifier.CSALabel> csaLabelMap = new
  275.             org.drip.analytics.support.CaseInsensitiveHashMap<org.drip.state.identifier.CSALabel>();

  276.         for (java.util.Map.Entry<java.lang.String, org.drip.xva.topology.CreditDebtGroup>
  277.             creditDebtGroupEntry : _creditDebtGroupMap.entrySet())
  278.         {
  279.             java.util.Map<java.lang.String, org.drip.xva.topology.CollateralGroup> collateralGroupMap =
  280.                 creditDebtGroupEntry.getValue().collateralGroupMap();

  281.             for (java.util.Map.Entry<java.lang.String, org.drip.xva.topology.CollateralGroup>
  282.                 collateralGroupMapEntry : collateralGroupMap.entrySet())
  283.             {
  284.                 org.drip.state.identifier.CSALabel csaLabel = collateralGroupMapEntry.getValue().csaLabel();

  285.                 java.lang.String csaLabelFQN = csaLabel.fullyQualifiedName();

  286.                 if (!csaLabelMap.containsKey (csaLabelFQN))
  287.                 {
  288.                     csaLabelMap.put (
  289.                         csaLabelFQN,
  290.                         csaLabel
  291.                     );
  292.                 }
  293.             }
  294.         }

  295.         return csaLabelMap;
  296.     }

  297.     /**
  298.      * Retrieve the Dealer Hazard Label Map
  299.      *
  300.      * @return The Dealer Hazard Label Map
  301.      */

  302.     public java.util.Map<java.lang.String, org.drip.state.identifier.EntityHazardLabel>
  303.         dealerHazardLabelMap()
  304.     {
  305.         java.util.Map<java.lang.String, org.drip.state.identifier.EntityHazardLabel> dealerHazardLabelMap = new
  306.             org.drip.analytics.support.CaseInsensitiveHashMap<org.drip.state.identifier.EntityHazardLabel>();

  307.         for (java.util.Map.Entry<java.lang.String, org.drip.xva.topology.CreditDebtGroup>
  308.             creditDebtGroupMapEntry : _creditDebtGroupMap.entrySet())
  309.         {
  310.             org.drip.state.identifier.EntityHazardLabel dealerHazardLabel =
  311.                 creditDebtGroupMapEntry.getValue().dealerHazardLabel();

  312.             java.lang.String dealerHazardLabelFQN = dealerHazardLabel.fullyQualifiedName();

  313.             if (!dealerHazardLabelMap.containsKey (dealerHazardLabelFQN))
  314.             {
  315.                 dealerHazardLabelMap.put (
  316.                     dealerHazardLabelFQN,
  317.                     dealerHazardLabel
  318.                 );
  319.             }
  320.         }

  321.         return dealerHazardLabelMap;
  322.     }

  323.     /**
  324.      * Retrieve the Client Hazard Label Map
  325.      *
  326.      * @return The Client Hazard Label Map
  327.      */

  328.     public java.util.Map<java.lang.String, org.drip.state.identifier.EntityHazardLabel>
  329.         clientHazardLabelMap()
  330.     {
  331.         java.util.Map<java.lang.String, org.drip.state.identifier.EntityHazardLabel> clientHazardLabelMap =
  332.             new org.drip.analytics.support.CaseInsensitiveHashMap<org.drip.state.identifier.EntityHazardLabel>();

  333.         for (java.util.Map.Entry<java.lang.String, org.drip.xva.topology.CreditDebtGroup>
  334.             creditDebtGroupMapEntry : _creditDebtGroupMap.entrySet())
  335.         {
  336.             org.drip.state.identifier.EntityHazardLabel clientHazardLabel =
  337.                 creditDebtGroupMapEntry.getValue().clientPartyHazardLabel();

  338.             java.lang.String clientHazardLabelFQN = clientHazardLabel.fullyQualifiedName();

  339.             if (!clientHazardLabelMap.containsKey (clientHazardLabelFQN))
  340.             {
  341.                 clientHazardLabelMap.put (
  342.                     clientHazardLabelFQN,
  343.                     clientHazardLabel
  344.                 );
  345.             }
  346.         }

  347.         return clientHazardLabelMap;
  348.     }

  349.     /**
  350.      * Retrieve the Dealer Senior Recovery Label Map
  351.      *
  352.      * @return The Dealer Senior Recovery Label Map
  353.      */

  354.     public java.util.Map<java.lang.String, org.drip.state.identifier.EntityRecoveryLabel>
  355.         dealerSeniorRecoveryLabelMap()
  356.     {
  357.         java.util.Map<java.lang.String, org.drip.state.identifier.EntityRecoveryLabel>
  358.             dealerSeniorRecoveryLabelMap = new
  359.                 org.drip.analytics.support.CaseInsensitiveHashMap<org.drip.state.identifier.EntityRecoveryLabel>();

  360.         for (java.util.Map.Entry<java.lang.String, org.drip.xva.topology.CreditDebtGroup>
  361.             creditDebtGroupMapEntry : _creditDebtGroupMap.entrySet())
  362.         {
  363.             org.drip.state.identifier.EntityRecoveryLabel dealerSeniorRecoveryLabel =
  364.                 creditDebtGroupMapEntry.getValue().dealerSeniorRecoveryLabel();

  365.             java.lang.String dealerSeniorRecoveryLabelFQN = dealerSeniorRecoveryLabel.fullyQualifiedName();

  366.             if (!dealerSeniorRecoveryLabelMap.containsKey (dealerSeniorRecoveryLabelFQN))
  367.             {
  368.                 dealerSeniorRecoveryLabelMap.put (
  369.                     dealerSeniorRecoveryLabelFQN,
  370.                     dealerSeniorRecoveryLabel
  371.                 );
  372.             }
  373.         }

  374.         return dealerSeniorRecoveryLabelMap;
  375.     }

  376.     /**
  377.      * Retrieve the Client Recovery Label Map
  378.      *
  379.      * @return The Client Recovery Label Map
  380.      */

  381.     public java.util.Map<java.lang.String, org.drip.state.identifier.EntityRecoveryLabel>
  382.         clientRecoveryLabelMap()
  383.     {
  384.         java.util.Map<java.lang.String, org.drip.state.identifier.EntityRecoveryLabel> clientRecoveryLabelMap
  385.             = new
  386.                 org.drip.analytics.support.CaseInsensitiveHashMap<org.drip.state.identifier.EntityRecoveryLabel>();

  387.         for (java.util.Map.Entry<java.lang.String, org.drip.xva.topology.CreditDebtGroup>
  388.             creditDebtGroupMapEntry : _creditDebtGroupMap.entrySet())
  389.         {
  390.             org.drip.state.identifier.EntityRecoveryLabel clientRecoveryLabel =
  391.                 creditDebtGroupMapEntry.getValue().clientRecoveryLabel();

  392.             java.lang.String clientRecoveryLabelFQN = clientRecoveryLabel.fullyQualifiedName();

  393.             if (!clientRecoveryLabelMap.containsKey (clientRecoveryLabelFQN))
  394.             {
  395.                 clientRecoveryLabelMap.put (
  396.                     clientRecoveryLabelFQN,
  397.                     clientRecoveryLabel
  398.                 );
  399.             }
  400.         }

  401.         return clientRecoveryLabelMap;
  402.     }

  403.     /**
  404.      * Retrieve the Dealer Subordinate Recovery Label Map
  405.      *
  406.      * @return The Dealer Subordinate Recovery Label Map
  407.      */

  408.     public java.util.Map<java.lang.String, org.drip.state.identifier.EntityRecoveryLabel>
  409.         dealerSubordinateRecoveryLabelMap()
  410.     {
  411.         java.util.Map<java.lang.String, org.drip.state.identifier.EntityRecoveryLabel>
  412.             dealerSubordinateRecoveryLabelMap = new
  413.                 org.drip.analytics.support.CaseInsensitiveHashMap<org.drip.state.identifier.EntityRecoveryLabel>();

  414.         for (java.util.Map.Entry<java.lang.String, org.drip.xva.topology.CreditDebtGroup>
  415.             creditDebtGroupMapEntry : _creditDebtGroupMap.entrySet())
  416.         {
  417.             org.drip.state.identifier.EntityRecoveryLabel dealerSubordinateRecoveryLabel =
  418.                 creditDebtGroupMapEntry.getValue().dealerSubordinateRecoveryLabel();

  419.             if (null != dealerSubordinateRecoveryLabel)
  420.             {
  421.                 java.lang.String dealerSubordinateRecoveryLabelFQN =
  422.                     dealerSubordinateRecoveryLabel.fullyQualifiedName();

  423.                 if (!dealerSubordinateRecoveryLabelMap.containsKey (dealerSubordinateRecoveryLabelFQN))
  424.                 {
  425.                     dealerSubordinateRecoveryLabelMap.put (
  426.                         dealerSubordinateRecoveryLabelFQN,
  427.                         dealerSubordinateRecoveryLabel
  428.                     );
  429.                 }
  430.             }
  431.         }

  432.         return dealerSubordinateRecoveryLabelMap;
  433.     }
  434. }