HighQualityLiquidAsset.java

  1. package org.drip.capital.bcbs;

  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>HighQualityLiquidAsset</i> contains the Amounts and the Settings associated with Levels 1, 2A, and 2B.
  76.  * The References are:
  77.  *
  78.  * <br><br>
  79.  *  <ul>
  80.  *      <li>
  81.  *          Basel Committee on Banking Supervision (2017): Basel III Leverage Ratio Framework and Disclosure
  82.  *              Requirements https://www.bis.org/publ/bcbs270.pdf
  83.  *      </li>
  84.  *      <li>
  85.  *          Central Banking (2013): Fed and FDIC agree 6% Leverage Ratio for US SIFIs
  86.  *              https://www.centralbanking.com/central-banking/news/2280726/fed-and-fdic-agree-6-leverage-ratio-for-us-sifis
  87.  *      </li>
  88.  *      <li>
  89.  *          European Banking Agency (2013): Implementing Basel III in Europe: CRD IV Package
  90.  *              https://eba.europa.eu/regulation-and-policy/implementing-basel-iii-europe
  91.  *      </li>
  92.  *      <li>
  93.  *          Federal Reserve (2013): Liquidity Coverage Ratio – Liquidity Risk Measurements, Standards, and
  94.  *              Monitoring
  95.  *              https://web.archive.org/web/20131102074614/http:/www.federalreserve.gov/FR_notice_lcr_20131024.pdf
  96.  *      </li>
  97.  *      <li>
  98.  *          Wikipedia (2018): Basel III https://en.wikipedia.org/wiki/Basel_III
  99.  *      </li>
  100.  *  </ul>
  101.  *
  102.  *  <br><br>
  103.  *  <ul>
  104.  *      <li><b>Module </b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/PortfolioCore.md">Portfolio Core Module</a></li>
  105.  *      <li><b>Library</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/CapitalAnalyticsLibrary.md">Capital Analytics</a></li>
  106.  *      <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>
  107.  *      <li><b>Package</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/capital/bcbs/README.md">BCBS and Jurisdictional Capital Ratios</a></li>
  108.  *  </ul>
  109.  *
  110.  * @author Lakshmi Krishnamurthy
  111.  */

  112. public class HighQualityLiquidAsset
  113. {
  114.     private double _level1 = java.lang.Double.NaN;
  115.     private double _level2A = java.lang.Double.NaN;
  116.     private double _level2B = java.lang.Double.NaN;

  117.     /**
  118.      * HighQualityLiquidAsset Constructor
  119.      *
  120.      * @param level1 Level 1 HQLA
  121.      * @param level2A Level 2A HQLA
  122.      * @param level2B Level 2B HQLA
  123.      *
  124.      * @throws java.lang.Exception Thrown if the Inputs are Invalid
  125.      */

  126.     public HighQualityLiquidAsset (
  127.         final double level1,
  128.         final double level2A,
  129.         final double level2B)
  130.         throws java.lang.Exception
  131.     {
  132.         if (!org.drip.numerical.common.NumberUtil.IsValid (_level1 = level1) ||
  133.             !org.drip.numerical.common.NumberUtil.IsValid (_level2A = level2A) ||
  134.             !org.drip.numerical.common.NumberUtil.IsValid (_level2B = level2B))
  135.         {
  136.             throw new java.lang.Exception ("HighQualityLiquidAsset Constructor => Invalid Inputs");
  137.         }
  138.     }

  139.     /**
  140.      * Retrieve the Amount of Level 1 Assets
  141.      *
  142.      * @return The Amount of Level 1 Assets
  143.      */

  144.     public double level1()
  145.     {
  146.         return _level1;
  147.     }

  148.     /**
  149.      * Retrieve the Amount of Level 2A Assets
  150.      *
  151.      * @return The Amount of Level 2A Assets
  152.      */

  153.     public double level2A()
  154.     {
  155.         return _level2A;
  156.     }

  157.     /**
  158.      * Retrieve the Amount of Level 2B Assets
  159.      *
  160.      * @return The Amount of Level 2B Assets
  161.      */

  162.     public double level2B()
  163.     {
  164.         return _level2B;
  165.     }

  166.     /**
  167.      * Retrieve the Total HQLA
  168.      *
  169.      * @return The Total HQLA
  170.      */

  171.     public double total()
  172.     {
  173.         return _level1 + _level2A + _level2B;
  174.     }

  175.     /**
  176.      * Retrieve the Level 2 Shares to the Total HQLA
  177.      *
  178.      * @return The Level 2 Shares to the Total HQLA
  179.      */

  180.     public double level2Ratio()
  181.     {
  182.         return (_level2A + _level2B) / (_level1 + _level2A + _level2B);
  183.     }

  184.     /**
  185.      * Retrieve the Level 2B Share to the Total HQLA
  186.      *
  187.      * @return The Level 2B Shares to the Total HQLA
  188.      */

  189.     public double level2BRatio()
  190.     {
  191.         return _level2B / (_level1 + _level2A + _level2B);
  192.     }

  193.     /**
  194.      * Apply the appropriate Risk Weight and Hair cut to each of the Level x Assets
  195.      *  
  196.      * @param hqlaSettings THe HQLA Settings
  197.      *
  198.      * @return The Risk Weight and Hair cut to each of the Level x Assets
  199.      */

  200.     public HighQualityLiquidAsset applyRiskWeightAndHaircut (
  201.         final org.drip.capital.bcbs.HighQualityLiquidAssetSettings hqlaSettings)
  202.     {
  203.         if (null == hqlaSettings)
  204.         {
  205.             return null;
  206.         }

  207.         try
  208.         {
  209.             return new HighQualityLiquidAsset (
  210.                 _level1,
  211.                 _level2A * (1. - hqlaSettings.level2AHaircut()) / (1. + hqlaSettings.level2ARiskWeight()),
  212.                 _level2B * (1. - hqlaSettings.level2BHaircut()) / (1. + hqlaSettings.level2BRiskWeight())
  213.             );
  214.         }
  215.         catch (java.lang.Exception e)
  216.         {
  217.             e.printStackTrace();
  218.         }

  219.         return null;
  220.     }

  221.     /**
  222.      * Verify if the HQLA is Compliant with the Level 2 and 2B Standards
  223.      *
  224.      * @param hqlaStandard The HQLA Standard
  225.      *
  226.      * @return TRUE - The HQLA is Compliant with the Level 2 and 2B Standards
  227.      */

  228.     public boolean isCompliant (
  229.         final org.drip.capital.bcbs.HighQualityLiquidAssetStandard hqlaStandard)
  230.     {
  231.         return null == hqlaStandard ? false :
  232.             level2Ratio() <= hqlaStandard.level2Ratio() &&
  233.             level2BRatio() <= hqlaStandard.level2BRatio();
  234.     }

  235.     /**
  236.      * Compute the Risk Weight and Hair cut HQLA Total
  237.      *  
  238.      * @param hqlaSettings THe HQLA Settings
  239.      *
  240.      * @return The Risk Weight and Hair cut HQLA Total
  241.      *
  242.      * @throws java.lang.Exception Thrown if the Inputs are Invalid
  243.      */

  244.     public double totalRiskWeightAndHaircut (
  245.         final org.drip.capital.bcbs.HighQualityLiquidAssetSettings hqlaSettings)
  246.         throws java.lang.Exception
  247.     {
  248.         HighQualityLiquidAsset hqla = applyRiskWeightAndHaircut (hqlaSettings);

  249.         if (null == hqla)
  250.         {
  251.             throw new java.lang.Exception
  252.                 ("HighQualityLiquidAsset::totalRiskWeightAndHaircut => Invalid Inputs");
  253.         }

  254.         return hqla.total();
  255.     }
  256. }