EntityElasticityAttribution.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>EntityElasticityAttribution</i> holds the Attributions across all Entity Components into Fixed, Float,
  76.  *  and Pro-rata Elasticities. 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 EntityElasticityAttribution
  103. {
  104.     private org.drip.capital.allocation.EntityComponentElasticityAttribution _noStress = null;
  105.     private org.drip.capital.allocation.EntityComponentElasticityAttribution _systemic = null;
  106.     private org.drip.capital.allocation.EntityComponentElasticityAttribution _correlated = null;
  107.     private org.drip.capital.allocation.EntityComponentElasticityAttribution _idiosyncratic = null;

  108.     /**
  109.      * EntityElasticityAttribution Constructor
  110.      *
  111.      * @param correlationCategoryBetaManager The Correlation Category Beta Manager
  112.      * @param unitLoading The Unit Loading Flag
  113.      *
  114.      * @throws java.lang.Exception Thrown if the Inputs are Invalid
  115.      */

  116.     public EntityElasticityAttribution (
  117.         final org.drip.capital.allocation.CorrelationCategoryBetaManager correlationCategoryBetaManager,
  118.         final boolean unitLoading)
  119.         throws java.lang.Exception
  120.     {
  121.         _systemic = new org.drip.capital.allocation.EntityComponentElasticityAttribution (
  122.             correlationCategoryBetaManager,
  123.             unitLoading
  124.         );

  125.         _correlated = new org.drip.capital.allocation.EntityComponentElasticityAttribution (
  126.             correlationCategoryBetaManager,
  127.             unitLoading
  128.         );

  129.         _idiosyncratic = new org.drip.capital.allocation.EntityComponentElasticityAttribution (
  130.             correlationCategoryBetaManager,
  131.             unitLoading
  132.         );

  133.         _noStress = new org.drip.capital.allocation.EntityComponentElasticityAttribution (
  134.             correlationCategoryBetaManager,
  135.             unitLoading
  136.         );
  137.     }

  138.     /**
  139.      * Retrieve the Systemic Elasticity Attribution
  140.      *
  141.      * @return The Systemic Elasticity Attribution
  142.      */

  143.     public org.drip.capital.allocation.EntityComponentElasticityAttribution systemic()
  144.     {
  145.         return _systemic;
  146.     }

  147.     /**
  148.      * Retrieve the Correlated Elasticity Attribution
  149.      *
  150.      * @return The Correlated Elasticity Attribution
  151.      */

  152.     public org.drip.capital.allocation.EntityComponentElasticityAttribution correlated()
  153.     {
  154.         return _correlated;
  155.     }

  156.     /**
  157.      * Retrieve the Idiosyncratic Elasticity Attribution
  158.      *
  159.      * @return The Idiosyncratic Elasticity Attribution
  160.      */

  161.     public org.drip.capital.allocation.EntityComponentElasticityAttribution idiosyncratic()
  162.     {
  163.         return _idiosyncratic;
  164.     }

  165.     /**
  166.      * Retrieve the "No Stress" Elasticity Attribution
  167.      *
  168.      * @return The "No Stress" Elasticity Attribution
  169.      */

  170.     public org.drip.capital.allocation.EntityComponentElasticityAttribution noStress()
  171.     {
  172.         return _noStress;
  173.     }

  174.     /**
  175.      * Accumulate the Systemic Fixed Attribution
  176.      *
  177.      * @param systemicFixedAttribution Systemic Fixed Attribution
  178.      *
  179.      * @return TRUE - The Systemic Fixed Attribution successfully updated
  180.      */

  181.     public boolean accumulateSystemicFixed (
  182.         final double systemicFixedAttribution)
  183.     {
  184.         return _systemic.accumulateFixed (
  185.             systemicFixedAttribution
  186.         );
  187.     }

  188.     /**
  189.      * Accumulate the Correlated Fixed Attribution
  190.      *
  191.      * @param correlatedFixedAttribution Correlated Fixed Attribution
  192.      *
  193.      * @return TRUE - The Correlated Fixed Attribution successfully updated
  194.      */

  195.     public boolean accumulateCorrelatedFixed (
  196.         final double correlatedFixedAttribution)
  197.     {
  198.         return _correlated.accumulateFixed (
  199.             correlatedFixedAttribution
  200.         );
  201.     }

  202.     /**
  203.      * Accumulate the Idiosyncratic Fixed Attribution
  204.      *
  205.      * @param idiosyncraticFixedAttribution Idiosyncratic Fixed Attribution
  206.      *
  207.      * @return TRUE - The Idiosyncratic Fixed Attribution successfully updated
  208.      */

  209.     public boolean accumulateIdiosyncraticFixed (
  210.         final double idiosyncraticFixedAttribution)
  211.     {
  212.         return _idiosyncratic.accumulateFixed (
  213.             idiosyncraticFixedAttribution
  214.         );
  215.     }

  216.     /**
  217.      * Accumulate the No-Stress Fixed Attribution
  218.      *
  219.      * @param noStressFixedAttribution No-Stress Fixed Attribution
  220.      *
  221.      * @return TRUE - The No-Stress Fixed Attribution successfully updated
  222.      */

  223.     public boolean accumulateNoStressFixed (
  224.         final double noStressFixedAttribution)
  225.     {
  226.         return _noStress.accumulateFixed (
  227.             noStressFixedAttribution
  228.         );
  229.     }

  230.     /**
  231.      * Accumulate the Systemic Floating Attribution
  232.      *
  233.      * @param systemicFloatingAttribution Systemic Floating Attribution
  234.      *
  235.      * @return TRUE - The Systemic Floating Attribution successfully updated
  236.      */

  237.     public boolean accumulateSystemicFloating (
  238.         final double systemicFloatingAttribution)
  239.     {
  240.         return _systemic.accumulateFloating (
  241.             systemicFloatingAttribution
  242.         );
  243.     }

  244.     /**
  245.      * Accumulate the Correlated Floating Attribution
  246.      *
  247.      * @param correlatedFloatingAttribution Correlated Floating Attribution
  248.      *
  249.      * @return TRUE - The Correlated Floating Attribution successfully updated
  250.      */

  251.     public boolean accumulateCorrelatedFloating (
  252.         final double correlatedFloatingAttribution)
  253.     {
  254.         return _correlated.accumulateFloating (
  255.             correlatedFloatingAttribution
  256.         );
  257.     }

  258.     /**
  259.      * Accumulate the Idiosyncratic Floating Attribution
  260.      *
  261.      * @param idiosyncraticFloatingAttribution Idiosyncratic Floating Attribution
  262.      *
  263.      * @return TRUE - The Idiosyncratic Floating Attribution successfully updated
  264.      */

  265.     public boolean accumulateIdiosyncraticFloating (
  266.         final double idiosyncraticFloatingAttribution)
  267.     {
  268.         return _idiosyncratic.accumulateFloating (
  269.             idiosyncraticFloatingAttribution
  270.         );
  271.     }

  272.     /**
  273.      * Accumulate the No-Stress Floating Attribution
  274.      *
  275.      * @param noStressFloatingAttribution No-Stress Floating Attribution
  276.      *
  277.      * @return TRUE - The No-Stress Floating Attribution successfully updated
  278.      */

  279.     public boolean accumulateNoStressFloating (
  280.         final double noStressFloatingAttribution)
  281.     {
  282.         return _noStress.accumulateFloating (
  283.             noStressFloatingAttribution
  284.         );
  285.     }

  286.     /**
  287.      * Accumulate the Systemic Pro-Rata Attribution
  288.      *
  289.      * @param systemicProRataAttribution Systemic Pro-Rata Attribution
  290.      *
  291.      * @return TRUE - The Systemic Pro-Rata Attribution successfully updated
  292.      */

  293.     public boolean accumulateSystemicProRata (
  294.         final double systemicProRataAttribution)
  295.     {
  296.         return _systemic.accumulateProRata (
  297.             systemicProRataAttribution
  298.         );
  299.     }

  300.     /**
  301.      * Accumulate the Correlated Pro-Rata Attribution
  302.      *
  303.      * @param correlatedProRataAttribution Correlated Pro-Rata Attribution
  304.      *
  305.      * @return TRUE - The Correlated Pro-Rata Attribution successfully updated
  306.      */

  307.     public boolean accumulateCorrelatedProRata (
  308.         final double correlatedProRataAttribution)
  309.     {
  310.         return _correlated.accumulateProRata (
  311.             correlatedProRataAttribution
  312.         );
  313.     }

  314.     /**
  315.      * Accumulate the Idiosyncratic Pro-Rata Attribution
  316.      *
  317.      * @param idiosyncraticProRataAttribution Idiosyncratic Pro-Rata Attribution
  318.      *
  319.      * @return TRUE - The Idiosyncratic Pro-Rata Attribution successfully updated
  320.      */

  321.     public boolean accumulateIdiosyncraticProRata (
  322.         final double idiosyncraticProRataAttribution)
  323.     {
  324.         return _idiosyncratic.accumulateProRata (
  325.             idiosyncraticProRataAttribution
  326.         );
  327.     }

  328.     /**
  329.      * Accumulate the No-Stress Pro-Rata Attribution
  330.      *
  331.      * @param noStressProRataAttribution No-Stress Pro-Rata Attribution
  332.      *
  333.      * @return TRUE - The No-Stress Pro-Rata Attribution successfully updated
  334.      */

  335.     public boolean accumulateNoStressProRata (
  336.         final double noStressProRataAttribution)
  337.     {
  338.         return _noStress.accumulateProRata (
  339.             noStressProRataAttribution
  340.         );
  341.     }

  342.     /**
  343.      * Accumulate the Systemic Attribution with the Beta-Adjusted Component Attribution
  344.      *
  345.      * @param systemicAttribution The Systemic Attribution
  346.      * @param systemicAllocationCategory The Systemic Allocation Category
  347.      * @param systemicAllocationScheme The Systemic Allocation Scheme
  348.      *
  349.      * @return TRUE - The Systemic Partition with the Beta-Adjusted Increment
  350.      */

  351.     public boolean accumulateSystemic (
  352.         final double systemicAttribution,
  353.         final int systemicAllocationCategory,
  354.         final int systemicAllocationScheme)
  355.     {
  356.         return _systemic.accumulate (
  357.             systemicAttribution,
  358.             systemicAllocationCategory,
  359.             systemicAllocationScheme
  360.         );
  361.     }

  362.     /**
  363.      * Accumulate the Correlated Attribution with the Beta-Adjusted Component Attribution
  364.      *
  365.      * @param correlatedAttribution The Correlated Attribution
  366.      * @param correlatedAllocationCategory The Correlated Allocation Category
  367.      * @param correlatedAllocationScheme The Correlated Allocation Scheme
  368.      *
  369.      * @return TRUE - The Correlated Partition with the Beta-Adjusted Increment
  370.      */

  371.     public boolean accumulateCorrelated (
  372.         final double correlatedAttribution,
  373.         final int correlatedAllocationCategory,
  374.         final int correlatedAllocationScheme)
  375.     {
  376.         return _correlated.accumulate (
  377.             correlatedAttribution,
  378.             correlatedAllocationCategory,
  379.             correlatedAllocationScheme
  380.         );
  381.     }

  382.     /**
  383.      * Accumulate the Idiosyncratic Attribution with the Beta-Adjusted Component Attribution
  384.      *
  385.      * @param idiosyncraticAttribution The Idiosyncratic Attribution
  386.      * @param idiosyncraticAllocationCategory The Idiosyncratic Allocation Category
  387.      * @param idiosyncraticAllocationScheme The Idiosyncratic Allocation Scheme
  388.      *
  389.      * @return TRUE - The Idiosyncratic Partition with the Beta-Adjusted Increment
  390.      */

  391.     public boolean accumulateIdiosyncratic (
  392.         final double idiosyncraticAttribution,
  393.         final int idiosyncraticAllocationCategory,
  394.         final int idiosyncraticAllocationScheme)
  395.     {
  396.         return _idiosyncratic.accumulate (
  397.             idiosyncraticAttribution,
  398.             idiosyncraticAllocationCategory,
  399.             idiosyncraticAllocationScheme
  400.         );
  401.     }

  402.     /**
  403.      * Accumulate the No Stress Attribution with the Beta-Adjusted Component Attribution
  404.      *
  405.      * @param noStressAttribution The No Stress Attribution
  406.      * @param noStressAllocationCategory The No Stress Allocation Category
  407.      * @param noStressAllocationScheme The No Stress Allocation Scheme
  408.      *
  409.      * @return TRUE - The No Stress Partition with the Beta-Adjusted Increment
  410.      */

  411.     public boolean accumulateNoStress (
  412.         final double noStressAttribution,
  413.         final int noStressAllocationCategory,
  414.         final int noStressAllocationScheme)
  415.     {
  416.         return _noStress.accumulate (
  417.             noStressAttribution,
  418.             noStressAllocationCategory,
  419.             noStressAllocationScheme
  420.         );
  421.     }

  422.     /**
  423.      * Accumulate with the Beta-Adjusted Component Attribution
  424.      *
  425.      * @param pnlAttribution PnL Attribution
  426.      * @param entityCapitalAssignmentSetting Entity Capital Assignment Setting
  427.      *
  428.      * @return TRUE - The Accumulation is successful
  429.      */

  430.     public boolean accumulate (
  431.         final org.drip.capital.explain.PnLAttribution pnlAttribution,
  432.         final org.drip.capital.allocation.EntityCapitalAssignmentSetting entityCapitalAssignmentSetting)
  433.     {
  434.         if (null == pnlAttribution ||
  435.             null == entityCapitalAssignmentSetting)
  436.         {
  437.             return false;
  438.         }

  439.         if (!accumulateSystemic (
  440.             pnlAttribution.systemicPnL(),
  441.             entityCapitalAssignmentSetting.systemicAllocationCategory(),
  442.             entityCapitalAssignmentSetting.systemicAllocationScheme()
  443.         ))
  444.         {
  445.             return false;
  446.         }

  447.         if (!accumulateCorrelated (
  448.             pnlAttribution.correlatedPnL(),
  449.             entityCapitalAssignmentSetting.correlatedAllocationCategory(),
  450.             entityCapitalAssignmentSetting.correlatedAllocationScheme()
  451.         ))
  452.         {
  453.             return false;
  454.         }

  455.         if (!accumulateIdiosyncratic (
  456.             pnlAttribution.idiosyncraticGrossPnL(),
  457.             entityCapitalAssignmentSetting.idiosyncraticAllocationCategory(),
  458.             entityCapitalAssignmentSetting.idiosyncraticAllocationScheme()
  459.         ))
  460.         {
  461.             return false;
  462.         }

  463.         if (!accumulateNoStress (
  464.             pnlAttribution.fsGrossPnL(),
  465.             entityCapitalAssignmentSetting.noStressAllocationCategory(),
  466.             entityCapitalAssignmentSetting.noStressAllocationScheme()
  467.         ))
  468.         {
  469.             return false;
  470.         }

  471.         return true;
  472.     }

  473.     /**
  474.      * Retrieve the Total Systemic Component Capital
  475.      *
  476.      * @return The Total Systemic Component Capital
  477.      */

  478.     public double systemicTotal()
  479.     {
  480.         return _systemic.fixed() + _systemic.floating() + _systemic.proRata();
  481.     }

  482.     /**
  483.      * Retrieve the Total Correlated Component Capital
  484.      *
  485.      * @return The Total Correlated Component Capital
  486.      */

  487.     public double correlatedTotal()
  488.     {
  489.         return _correlated.fixed() + _correlated.floating() + _correlated.proRata();
  490.     }

  491.     /**
  492.      * Retrieve the Total Idiosyncratic Component Capital
  493.      *
  494.      * @return The Total Idiosyncratic Component Capital
  495.      */

  496.     public double idiosyncraticTotal()
  497.     {
  498.         return _idiosyncratic.fixed() + _idiosyncratic.floating() + _idiosyncratic.proRata();
  499.     }

  500.     /**
  501.      * Retrieve the Total No Stress Component Capital
  502.      *
  503.      * @return The Total No Stress Component Capital
  504.      */

  505.     public double noStressTotal()
  506.     {
  507.         return _noStress.fixed() + _noStress.floating() + _noStress.proRata();
  508.     }

  509.     /**
  510.      * Retrieve the Fixed Beta Capital Component
  511.      *
  512.      * @return The Fixed Beta Capital Component
  513.      */

  514.     public double fixed()
  515.     {
  516.         return _systemic.fixed() + _correlated.fixed() + _idiosyncratic.fixed() + _noStress.fixed();
  517.     }

  518.     /**
  519.      * Retrieve the Floating Beta Capital Component
  520.      *
  521.      * @return The Floating Beta Capital Component
  522.      */

  523.     public double floating()
  524.     {
  525.         return _systemic.floating() + _correlated.floating() + _idiosyncratic.floating() +
  526.             _noStress.floating();
  527.     }

  528.     /**
  529.      * Retrieve the Pro-Rata Beta Capital Component
  530.      *
  531.      * @return The Pro-Rata Beta Capital Component
  532.      */

  533.     public double proRata()
  534.     {
  535.         return _systemic.proRata() + _correlated.proRata() + _idiosyncratic.proRata() + _noStress.proRata();
  536.     }

  537.     /**
  538.      * Retrieve the Pro-Rata Systemic Capital
  539.      *  
  540.      * @return The Pro-Rata Systemic Capital
  541.      */

  542.     public double systemicProRata()
  543.     {
  544.         return _systemic.proRata();
  545.     }

  546.     /**
  547.      * Retrieve the Pro-Rata Correlated Capital
  548.      *  
  549.      * @return The Pro-Rata Correlated Capital
  550.      */

  551.     public double correlatedProRata()
  552.     {
  553.         return _correlated.proRata();
  554.     }

  555.     /**
  556.      * Retrieve the Pro-Rata Idiosyncratic Capital
  557.      *  
  558.      * @return The Pro-Rata Idiosyncratic Capital
  559.      */

  560.     public double idiosyncraticProRata()
  561.     {
  562.         return _idiosyncratic.proRata();
  563.     }

  564.     /**
  565.      * Retrieve the Pro-Rata No-Stress Capital
  566.      *  
  567.      * @return The Pro-Rata No-Stress Capital
  568.      */

  569.     public double noStressProRata()
  570.     {
  571.         return _noStress.proRata();
  572.     }
  573. }