CorrelationCategoryBetaManager.java

  1. package org.drip.capital.allocation;

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

  74. /**
  75.  * <i>CorrelationCategoryBetaManager</i> holds the Beta Loading Map Scheme for the different Correlation
  76.  *  Categories. The References are:
  77.  *
  78.  * <br><br>
  79.  *  <ul>
  80.  *      <li>
  81.  *          Bank for International Supervision(2005): Stress Testing at Major Financial Institutions: Survey
  82.  *              Results and Practice https://www.bis.org/publ/cgfs24.htm
  83.  *      </li>
  84.  *      <li>
  85.  *          Glasserman, P. (2004): <i>Monte Carlo Methods in Financial Engineering</i> <b>Springer</b>
  86.  *      </li>
  87.  *      <li>
  88.  *          Kupiec, P. H. (2000): Stress Tests and Risk Capital <i>Risk</i> <b>2 (4)</b> 27-39
  89.  *      </li>
  90.  *  </ul>
  91.  *
  92.  *  <br><br>
  93.  *  <ul>
  94.  *      <li><b>Module </b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/PortfolioCore.md">Portfolio Core Module</a></li>
  95.  *      <li><b>Library</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/CapitalAnalyticsLibrary.md">Capital Analytics</a></li>
  96.  *      <li><b>Project</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/capital/README.md">Basel Market Risk and Operational Capital</a></li>
  97.  *      <li><b>Package</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/capital/allocation/README.md">Economic Risk Capital Entity Allocation</a></li>
  98.  *  </ul>
  99.  *
  100.  * @author Lakshmi Krishnamurthy
  101.  */

  102. public class CorrelationCategoryBetaManager
  103. {

  104.     private java.util.Map<java.lang.Integer, org.drip.capital.allocation.CorrelationCategoryBeta>
  105.         _correlationCategoryBetaMap = null;

  106.     /**
  107.      * Construct the Three-Beta Fixed-High Float-Medium Float-Low Instance of CorrelationCategoryBetaManager
  108.      *
  109.      * @param highCorrelationFixedBetaLoading High Correlation Beta FIXED Loading
  110.      * @param mediumCorrelationFloatBetaLoading Medium Correlation Beta FLOAT Loading
  111.      *
  112.      * @return The Three-Beta Fixed-High Float-Medium Float-Low Instance of CorrelationCategoryBetaManager
  113.      */

  114.     public static final CorrelationCategoryBetaManager ThreeBetaFixedFloatFloat (
  115.         final double highCorrelationFixedBetaLoading,
  116.         final double mediumCorrelationFloatBetaLoading)
  117.     {
  118.         CorrelationCategoryBetaManager correlationCategoryBetaManager =
  119.             new CorrelationCategoryBetaManager();

  120.         try
  121.         {
  122.             if (!correlationCategoryBetaManager.addCorrelationCategoryBeta (
  123.                 org.drip.capital.allocation.EntityComponentCorrelationCategory.HIGH_CORRELATION,
  124.                 new org.drip.capital.allocation.CorrelationCategoryBeta (
  125.                     org.drip.capital.allocation.CorrelationCategoryBeta.ELASTICITY_FIXED,
  126.                     highCorrelationFixedBetaLoading
  127.                 )
  128.             ))
  129.             {
  130.                 return null;
  131.             }

  132.             if (!correlationCategoryBetaManager.addCorrelationCategoryBeta (
  133.                 org.drip.capital.allocation.EntityComponentCorrelationCategory.MEDIUM_CORRELATION,
  134.                 new org.drip.capital.allocation.CorrelationCategoryBeta (
  135.                     org.drip.capital.allocation.CorrelationCategoryBeta.ELASTICITY_FLOAT,
  136.                     mediumCorrelationFloatBetaLoading
  137.                 )
  138.             ))
  139.             {
  140.                 return null;
  141.             }

  142.             if (!correlationCategoryBetaManager.addCorrelationCategoryBeta (
  143.                 org.drip.capital.allocation.EntityComponentCorrelationCategory.LOW_CORRELATION,
  144.                 new org.drip.capital.allocation.CorrelationCategoryBeta (
  145.                     org.drip.capital.allocation.CorrelationCategoryBeta.ELASTICITY_FLOAT,
  146.                     1.
  147.                 )
  148.             ))
  149.             {
  150.                 return null;
  151.             }

  152.             if (!correlationCategoryBetaManager.addCorrelationCategoryBeta (
  153.                 org.drip.capital.allocation.EntityComponentCorrelationCategory.HEDGE,
  154.                 new org.drip.capital.allocation.CorrelationCategoryBeta (
  155.                     org.drip.capital.allocation.CorrelationCategoryBeta.ELASTICITY_FIXED,
  156.                     -1.
  157.                 )
  158.             ))
  159.             {
  160.                 return null;
  161.             }

  162.         }
  163.         catch (java.lang.Exception e)
  164.         {
  165.             e.printStackTrace();

  166.             return null;
  167.         }

  168.         return correlationCategoryBetaManager;
  169.     }

  170.     /**
  171.      * Construct the Fixed-High Float-Low Two-Beta Instance of CorrelationCategoryBetaManager
  172.      *
  173.      * @param highCorrelationFixedBetaLoading High Correlation Beta FIXED Loading
  174.      *
  175.      * @return The Fixed-High Float-Low Two-Beta Instance of CorrelationCategoryBetaManager
  176.      */

  177.     public static final CorrelationCategoryBetaManager TwoBetaFixedFloat (
  178.         final double highCorrelationFixedBetaLoading)
  179.     {
  180.         CorrelationCategoryBetaManager correlationCategoryBetaManager =
  181.             new CorrelationCategoryBetaManager();

  182.         try
  183.         {
  184.             if (!correlationCategoryBetaManager.addCorrelationCategoryBeta (
  185.                 org.drip.capital.allocation.EntityComponentCorrelationCategory.HIGH_CORRELATION,
  186.                 new org.drip.capital.allocation.CorrelationCategoryBeta (
  187.                     org.drip.capital.allocation.CorrelationCategoryBeta.ELASTICITY_FIXED,
  188.                     highCorrelationFixedBetaLoading
  189.                 )
  190.             ))
  191.             {
  192.                 return null;
  193.             }

  194.             if (!correlationCategoryBetaManager.addCorrelationCategoryBeta (
  195.                 org.drip.capital.allocation.EntityComponentCorrelationCategory.LOW_CORRELATION,
  196.                 new org.drip.capital.allocation.CorrelationCategoryBeta (
  197.                     org.drip.capital.allocation.CorrelationCategoryBeta.ELASTICITY_FLOAT,
  198.                     1.
  199.                 )
  200.             ))
  201.             {
  202.                 return null;
  203.             }

  204.             if (!correlationCategoryBetaManager.addCorrelationCategoryBeta (
  205.                 org.drip.capital.allocation.EntityComponentCorrelationCategory.HEDGE,
  206.                 new org.drip.capital.allocation.CorrelationCategoryBeta (
  207.                     org.drip.capital.allocation.CorrelationCategoryBeta.ELASTICITY_FIXED,
  208.                     -1.
  209.                 )
  210.             ))
  211.             {
  212.                 return null;
  213.             }
  214.         }
  215.         catch (java.lang.Exception e)
  216.         {
  217.             e.printStackTrace();

  218.             return null;
  219.         }

  220.         return correlationCategoryBetaManager;
  221.     }

  222.     /**
  223.      * Construct the Float-High Float-Low Two-Beta Instance of CorrelationCategoryBetaManager
  224.      *
  225.      * @param highCorrelationFloatBetaLoading High Correlation Beta FLOAT Loading
  226.      *
  227.      * @return The Float-High Float-Low Two-Beta Instance of CorrelationCategoryBetaManager
  228.      */

  229.     public static final CorrelationCategoryBetaManager TwoBetaFloatFloat (
  230.         final double highCorrelationFloatBetaLoading)
  231.     {
  232.         CorrelationCategoryBetaManager correlationCategoryBetaManager =
  233.             new CorrelationCategoryBetaManager();

  234.         try
  235.         {
  236.             if (!correlationCategoryBetaManager.addCorrelationCategoryBeta (
  237.                 org.drip.capital.allocation.EntityComponentCorrelationCategory.HIGH_CORRELATION,
  238.                 new org.drip.capital.allocation.CorrelationCategoryBeta (
  239.                     org.drip.capital.allocation.CorrelationCategoryBeta.ELASTICITY_FLOAT,
  240.                     highCorrelationFloatBetaLoading
  241.                 )
  242.             ))
  243.             {
  244.                 return null;
  245.             }

  246.             if (!correlationCategoryBetaManager.addCorrelationCategoryBeta (
  247.                 org.drip.capital.allocation.EntityComponentCorrelationCategory.LOW_CORRELATION,
  248.                 new org.drip.capital.allocation.CorrelationCategoryBeta (
  249.                     org.drip.capital.allocation.CorrelationCategoryBeta.ELASTICITY_FLOAT,
  250.                     1.
  251.                 )
  252.             ))
  253.             {
  254.                 return null;
  255.             }

  256.             if (!correlationCategoryBetaManager.addCorrelationCategoryBeta (
  257.                 org.drip.capital.allocation.EntityComponentCorrelationCategory.HEDGE,
  258.                 new org.drip.capital.allocation.CorrelationCategoryBeta (
  259.                     org.drip.capital.allocation.CorrelationCategoryBeta.ELASTICITY_FIXED,
  260.                     -1.
  261.                 )
  262.             ))
  263.             {
  264.                 return null;
  265.             }
  266.         }
  267.         catch (java.lang.Exception e)
  268.         {
  269.             e.printStackTrace();

  270.             return null;
  271.         }

  272.         return correlationCategoryBetaManager;
  273.     }

  274.     /**
  275.      * Empty CorrelationCategoryBetaManager Constructor
  276.      */

  277.     public CorrelationCategoryBetaManager()
  278.     {
  279.     }

  280.     /**
  281.      * Retrieve the Historical Correlation Category Beta Map
  282.      *
  283.      * @return The Historical Correlation Category Beta Map
  284.      */

  285.     public java.util.Map<java.lang.Integer, org.drip.capital.allocation.CorrelationCategoryBeta>
  286.         correlationCategoryBetaMap()
  287.     {
  288.         return _correlationCategoryBetaMap;
  289.     }

  290.     /**
  291.      * Add the Beta Loading corresponding to the Correlation Category
  292.      *
  293.      * @param correlationCategory The Correlation Category
  294.      * @param correlationCategoryBeta The Correlation Category Beta Loading
  295.      *
  296.      * @return TRUE - The Beta Loading successfully added
  297.      */

  298.     public boolean addCorrelationCategoryBeta (
  299.         final int correlationCategory,
  300.         final org.drip.capital.allocation.CorrelationCategoryBeta correlationCategoryBeta)
  301.     {
  302.         if (null == correlationCategoryBeta)
  303.         {
  304.             return false;
  305.         }

  306.         if (null == _correlationCategoryBetaMap)
  307.         {
  308.             _correlationCategoryBetaMap =
  309.                 new java.util.TreeMap<java.lang.Integer,
  310.                     org.drip.capital.allocation.CorrelationCategoryBeta>();
  311.         }

  312.         _correlationCategoryBetaMap.put (
  313.             correlationCategory,
  314.             correlationCategoryBeta
  315.         );

  316.         return true;
  317.     }

  318.     /**
  319.      * Indicate of the Correlation Category Exists
  320.      *
  321.      * @param correlationCategory The Correlation Category
  322.      *
  323.      * @return TRUE - The Correlation Category Exists
  324.      */

  325.     public boolean categoryExists (
  326.         final int correlationCategory)
  327.     {
  328.         return _correlationCategoryBetaMap.containsKey (
  329.             correlationCategory
  330.         );
  331.     }

  332.     /**
  333.      * Retrieve the Correlation Category Beta Loading for the Correlation Category
  334.      *
  335.      * @param correlationCategory The Correlation Category
  336.      *
  337.      * @return The Correlation Category Beta Loading
  338.      */

  339.     public org.drip.capital.allocation.CorrelationCategoryBeta correlationCategoryBeta (
  340.         final int correlationCategory)
  341.     {
  342.         return categoryExists (
  343.             correlationCategory
  344.         ) ? _correlationCategoryBetaMap.get (
  345.             correlationCategory
  346.         ) : null;
  347.     }
  348. }