CapitalUnitPnLAttribution.java

  1. package org.drip.capital.explain;

  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>CapitalUnitPnLAttribution</i> holds the Attributions of the PnL from the Contributing Paths for a Single
  76.  *  Capital Unit. 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/explain/README.md">Economic Risk Capital Attribution Explain</a></li>
  98.  *  </ul>
  99.  *
  100.  * @author Lakshmi Krishnamurthy
  101.  */

  102. public class CapitalUnitPnLAttribution
  103.     extends org.drip.capital.explain.PnLAttribution
  104.     implements org.drip.capital.simulation.EnsemblePnLDistributionGenerator
  105. {
  106.     private java.util.List<org.drip.capital.simulation.PathPnLRealization> _pathPnLRealizationList = null;

  107.     private static final boolean NormalizeExplainMap (
  108.         final java.util.Map<java.lang.String, java.lang.Double> pnlExplainMap,
  109.         final int normalizer)
  110.     {
  111.         if (null != pnlExplainMap)
  112.         {
  113.             for (java.util.Map.Entry<java.lang.String, java.lang.Double> pnlExplainEntry :
  114.                 pnlExplainMap.entrySet())
  115.             {
  116.                 pnlExplainMap.put (
  117.                     pnlExplainEntry.getKey(),
  118.                     pnlExplainEntry.getValue() / normalizer
  119.                 );
  120.             }
  121.         }

  122.         return true;
  123.     }

  124.     private boolean updateFSDecompositionMap (
  125.         final java.util.Map<java.lang.String, java.lang.Double> fsPnLMap)
  126.     {
  127.         if (null == _fsPnLDecompositionExplainMap)
  128.         {
  129.             _fsPnLDecompositionExplainMap = new
  130.                 org.drip.analytics.support.CaseInsensitiveHashMap<java.lang.Double>();
  131.         }

  132.         for (java.util.Map.Entry<java.lang.String, java.lang.Double> fsPnLEntry : fsPnLMap.entrySet())
  133.         {
  134.             java.lang.String fsType = fsPnLEntry.getKey();

  135.             if (_fsPnLDecompositionExplainMap.containsKey (
  136.                 fsType
  137.             ))
  138.             {
  139.                 _fsPnLDecompositionExplainMap.put (
  140.                     fsType,
  141.                     _fsPnLDecompositionExplainMap.get (
  142.                         fsType
  143.                     ) + fsPnLEntry.getValue()
  144.                 );
  145.             }
  146.             else
  147.             {
  148.                 _fsPnLDecompositionExplainMap.put (
  149.                     fsType,
  150.                     fsPnLEntry.getValue()
  151.                 );
  152.             }
  153.         }

  154.         return true;
  155.     }

  156.     private boolean updatePAACategoryDecompositionMap (
  157.         final java.util.Map<java.lang.String, java.lang.Double> paaCategoryPnLDecomposition)
  158.     {
  159.         if (null == _paaCategoryDecompositionExplainMap)
  160.         {
  161.             _paaCategoryDecompositionExplainMap = new
  162.                 org.drip.analytics.support.CaseInsensitiveHashMap<java.lang.Double>();
  163.         }

  164.         for (java.util.Map.Entry<java.lang.String, java.lang.Double> paaCategoryPnLEntry :
  165.             paaCategoryPnLDecomposition.entrySet())
  166.         {
  167.             java.lang.String paaCategoryName = paaCategoryPnLEntry.getKey();

  168.             if (_paaCategoryDecompositionExplainMap.containsKey (
  169.                 paaCategoryName
  170.             ))
  171.             {
  172.                 _paaCategoryDecompositionExplainMap.put (
  173.                     paaCategoryName,
  174.                     paaCategoryPnLEntry.getValue() + _paaCategoryDecompositionExplainMap.get (
  175.                         paaCategoryName
  176.                     )
  177.                 );
  178.             }
  179.             else
  180.             {
  181.                 _paaCategoryDecompositionExplainMap.put (
  182.                     paaCategoryName,
  183.                     paaCategoryPnLEntry.getValue()
  184.                 );
  185.             }
  186.         }

  187.         return true;
  188.     }

  189.     private boolean addPathPnLRealization (
  190.         final org.drip.capital.simulation.PathPnLRealization pathPnLRealization)
  191.     {
  192.         if (null == pathPnLRealization)
  193.         {
  194.             return false;
  195.         }

  196.         _expectedShortfall = _expectedShortfall + (_var = pathPnLRealization.grossPnL());

  197.         java.util.Map<java.lang.String, java.lang.Double> fsPnLDecompositionMap =
  198.             pathPnLRealization.fsPnLDecompositionMap();

  199.         if (null != fsPnLDecompositionMap)
  200.         {
  201.             if (!updateFSDecompositionMap (
  202.                 fsPnLDecompositionMap
  203.             ))
  204.             {
  205.                 return false;
  206.             }
  207.         }

  208.         org.drip.capital.simulation.StressEventIncidenceEnsemble systemicStressEventIncidenceEnsemble =
  209.             pathPnLRealization.systemic();

  210.         if (null != systemicStressEventIncidenceEnsemble)
  211.         {
  212.             for (org.drip.capital.simulation.StressEventIncidence stressEventIncidence :
  213.                 systemicStressEventIncidenceEnsemble.stressEventIncidenceList())
  214.             {
  215.                 java.lang.String eventName = stressEventIncidence.name();

  216.                 java.lang.String eventType = stressEventIncidence.type();

  217.                 if (org.drip.capital.definition.StressScenarioType.SYSTEMIC.equalsIgnoreCase (
  218.                     eventType
  219.                 ))
  220.                 {
  221.                     if (null == _systemicPnLExplainMap)
  222.                     {
  223.                         _systemicPnLExplainMap = new
  224.                             org.drip.analytics.support.CaseInsensitiveHashMap<java.lang.Double>();

  225.                         _systemicGrossPnLExplainMap = new
  226.                             org.drip.analytics.support.CaseInsensitiveHashMap<java.lang.Double>();
  227.                     }

  228.                     double systemicPnL = stressEventIncidence.pnl();

  229.                     if (_systemicPnLExplainMap.containsKey (
  230.                         eventName
  231.                     ))
  232.                     {
  233.                         _systemicPnLExplainMap.put (
  234.                             eventName,
  235.                             _systemicPnLExplainMap.get (
  236.                                 eventName
  237.                             ) + systemicPnL
  238.                         );

  239.                         _systemicGrossPnLExplainMap.put (
  240.                             eventName,
  241.                             _systemicGrossPnLExplainMap.get (
  242.                                 eventName
  243.                             ) + systemicPnL
  244.                         );
  245.                     }
  246.                     else
  247.                     {
  248.                         _systemicPnLExplainMap.put (
  249.                             eventName,
  250.                             systemicPnL
  251.                         );

  252.                         _systemicGrossPnLExplainMap.put (
  253.                             eventName,
  254.                             systemicPnL
  255.                         );
  256.                     }

  257.                     if (null == _systemicInstanceCountMap)
  258.                     {
  259.                         _systemicInstanceCountMap = new
  260.                             org.drip.analytics.support.CaseInsensitiveHashMap<java.lang.Integer>();
  261.                     }

  262.                     if (_systemicInstanceCountMap.containsKey (
  263.                         eventName
  264.                     ))
  265.                     {
  266.                         _systemicInstanceCountMap.put (
  267.                             eventName,
  268.                             _systemicInstanceCountMap.get (
  269.                                 eventName
  270.                             ) + 1
  271.                         );
  272.                     }
  273.                     else
  274.                     {
  275.                         _systemicInstanceCountMap.put (
  276.                             eventName,
  277.                             1
  278.                         );
  279.                     }
  280.                 }
  281.                 else if (org.drip.capital.definition.StressScenarioType.CORRELATED.equalsIgnoreCase (
  282.                     eventType
  283.                 ))
  284.                 {
  285.                     if (null == _correlatedPnLExplainMap)
  286.                     {
  287.                         _correlatedPnLExplainMap = new
  288.                             org.drip.analytics.support.CaseInsensitiveHashMap<java.lang.Double>();
  289.                     }

  290.                     if (null == _correlatedPnLWorstMap)
  291.                     {
  292.                         _correlatedPnLWorstMap = new
  293.                             org.drip.analytics.support.CaseInsensitiveHashMap<java.lang.Double>();
  294.                     }

  295.                     double correlatedPnL = stressEventIncidence.pnl();

  296.                     if (_correlatedPnLExplainMap.containsKey (
  297.                         eventName
  298.                     ))
  299.                     {
  300.                         _correlatedPnLExplainMap.put (
  301.                             eventName,
  302.                             _correlatedPnLExplainMap.get (
  303.                                 eventName
  304.                             ) + correlatedPnL
  305.                         );
  306.                     }
  307.                     else
  308.                     {
  309.                         _correlatedPnLExplainMap.put (
  310.                             eventName,
  311.                             correlatedPnL
  312.                         );
  313.                     }

  314.                     if (_correlatedPnLWorstMap.containsKey (
  315.                         eventName
  316.                     ))
  317.                     {
  318.                         double correlatedWorstPnL = _correlatedPnLWorstMap.get (
  319.                             eventName
  320.                         );

  321.                         _correlatedPnLWorstMap.put (
  322.                             eventName,
  323.                             correlatedWorstPnL < correlatedPnL ? correlatedWorstPnL : correlatedPnL
  324.                         );
  325.                     }
  326.                     else
  327.                     {
  328.                         _correlatedPnLWorstMap.put (
  329.                             eventName,
  330.                             correlatedPnL
  331.                         );
  332.                     }

  333.                     java.lang.String parentSystemicEventName = org.drip.numerical.common.StringUtil.Split (
  334.                         eventName,
  335.                         "::"
  336.                     )[0];

  337.                     _systemicGrossPnLExplainMap.put (
  338.                         parentSystemicEventName,
  339.                         _systemicGrossPnLExplainMap.get (
  340.                             parentSystemicEventName
  341.                         ) + correlatedPnL
  342.                     );

  343.                     if (null == _correlatedInstanceCountMap)
  344.                     {
  345.                         _correlatedInstanceCountMap = new
  346.                             org.drip.analytics.support.CaseInsensitiveHashMap<java.lang.Integer>();
  347.                     }

  348.                     if (_correlatedInstanceCountMap.containsKey (
  349.                         eventName
  350.                     ))
  351.                     {
  352.                         _correlatedInstanceCountMap.put (
  353.                             eventName,
  354.                             _correlatedInstanceCountMap.get (
  355.                                 eventName
  356.                             ) + 1
  357.                         );
  358.                     }
  359.                     else
  360.                     {
  361.                         _correlatedInstanceCountMap.put (
  362.                             eventName,
  363.                             1
  364.                         );
  365.                     }
  366.                 }
  367.             }

  368.             java.util.Map<java.lang.String, java.lang.Double> paaCategoryPnLDecomposition =
  369.                 systemicStressEventIncidenceEnsemble.grossPAACategoryPnLDecomposition();

  370.             if (null != paaCategoryPnLDecomposition && 0 != paaCategoryPnLDecomposition.size())
  371.             {
  372.                 if (!updatePAACategoryDecompositionMap (
  373.                     paaCategoryPnLDecomposition
  374.                 ))
  375.                 {
  376.                     return false;
  377.                 }
  378.             }
  379.         }

  380.         org.drip.capital.simulation.StressEventIncidenceEnsemble idiosyncraticStressEventIncidenceEnsemble =
  381.             pathPnLRealization.idiosyncratic();

  382.         if (null != idiosyncraticStressEventIncidenceEnsemble)
  383.         {
  384.             for (org.drip.capital.simulation.StressEventIncidence stressEventIncidence :
  385.                 idiosyncraticStressEventIncidenceEnsemble.stressEventIncidenceList())
  386.             {
  387.                 java.lang.String eventName = stressEventIncidence.name();

  388.                 if (null == _idiosyncraticPnLExplainMap)
  389.                 {
  390.                     _idiosyncraticPnLExplainMap = new
  391.                         org.drip.analytics.support.CaseInsensitiveHashMap<java.lang.Double>();
  392.                 }

  393.                 if (null == _idiosyncraticPnLWorstMap)
  394.                 {
  395.                     _idiosyncraticPnLWorstMap = new
  396.                         org.drip.analytics.support.CaseInsensitiveHashMap<java.lang.Double>();
  397.                 }

  398.                 double idiosyncraticPnL = stressEventIncidence.pnl();

  399.                 if (_idiosyncraticPnLExplainMap.containsKey (
  400.                     eventName
  401.                 ))
  402.                 {
  403.                     _idiosyncraticPnLExplainMap.put (
  404.                         eventName,
  405.                         _idiosyncraticPnLExplainMap.get (
  406.                             eventName
  407.                         ) + idiosyncraticPnL
  408.                     );
  409.                 }
  410.                 else
  411.                 {
  412.                     _idiosyncraticPnLExplainMap.put (
  413.                         eventName,
  414.                         idiosyncraticPnL
  415.                     );
  416.                 }

  417.                 if (_idiosyncraticPnLWorstMap.containsKey (
  418.                     eventName
  419.                 ))
  420.                 {
  421.                     double idiosyncraticPnLWorst = _idiosyncraticPnLWorstMap.get (
  422.                         eventName
  423.                     );

  424.                     _idiosyncraticPnLWorstMap.put (
  425.                         eventName,
  426.                         idiosyncraticPnLWorst < idiosyncraticPnL ? idiosyncraticPnLWorst : idiosyncraticPnL
  427.                     );
  428.                 }
  429.                 else
  430.                 {
  431.                     _idiosyncraticPnLWorstMap.put (
  432.                         eventName,
  433.                         idiosyncraticPnL
  434.                     );
  435.                 }

  436.                 if (null == _idiosyncraticInstanceCountMap)
  437.                 {
  438.                     _idiosyncraticInstanceCountMap = new
  439.                         org.drip.analytics.support.CaseInsensitiveHashMap<java.lang.Integer>();
  440.                 }

  441.                 if (_idiosyncraticInstanceCountMap.containsKey (
  442.                     eventName
  443.                 ))
  444.                 {
  445.                     _idiosyncraticInstanceCountMap.put (
  446.                         eventName,
  447.                         _idiosyncraticInstanceCountMap.get (
  448.                             eventName
  449.                         ) + 1
  450.                     );
  451.                 }
  452.                 else
  453.                 {
  454.                     _idiosyncraticInstanceCountMap.put (
  455.                         eventName,
  456.                         1
  457.                     );
  458.                 }
  459.             }
  460.         }

  461.         return true;
  462.     }

  463.     /**
  464.      * CapitalUnitPnLAttribution Constructor
  465.      *
  466.      * @param pathPnLRealizationList Path PnL Realization List
  467.      *
  468.      * @throws java.lang.Exception Thrown if the Inputs are Invalid
  469.      */

  470.     public CapitalUnitPnLAttribution (
  471.         final java.util.List<org.drip.capital.simulation.PathPnLRealization> pathPnLRealizationList)
  472.         throws java.lang.Exception
  473.     {
  474.         if (null == (_pathPnLRealizationList = pathPnLRealizationList))
  475.         {
  476.             throw new java.lang.Exception (
  477.                 "CapitalUnitPnLAttribution Constructor => Invalid Inputs"
  478.             );
  479.         }

  480.         int pathCount = _pathPnLRealizationList.size();

  481.         if (0 == pathCount)
  482.         {
  483.             throw new java.lang.Exception (
  484.                 "CapitalUnitPnLAttribution Constructor => Invalid Inputs"
  485.             );
  486.         }

  487.         _expectedShortfall = 0.;

  488.         for (org.drip.capital.simulation.PathPnLRealization pathPnLRealization : _pathPnLRealizationList)
  489.         {
  490.             if (!addPathPnLRealization (
  491.                 pathPnLRealization
  492.             ))
  493.             {
  494.                 throw new java.lang.Exception (
  495.                     "CapitalUnitPnLAttribution Constructor => Invalid Inputs"
  496.                 );
  497.             }
  498.         }

  499.         NormalizeExplainMap (
  500.             _systemicPnLExplainMap,
  501.             pathCount
  502.         );

  503.         NormalizeExplainMap (
  504.             _systemicGrossPnLExplainMap,
  505.             pathCount
  506.         );

  507.         NormalizeExplainMap (
  508.             _correlatedPnLExplainMap,
  509.             pathCount
  510.         );

  511.         NormalizeExplainMap (
  512.             _idiosyncraticPnLExplainMap,
  513.             pathCount
  514.         );

  515.         NormalizeExplainMap (
  516.             _fsPnLDecompositionExplainMap,
  517.             pathCount
  518.         );

  519.         NormalizeExplainMap (
  520.             _paaCategoryDecompositionExplainMap,
  521.             pathCount
  522.         );

  523.         _expectedShortfall = _expectedShortfall / pathCount;
  524.     }

  525.     /**
  526.      * Retrieve the Contributing Path PnL Realization List
  527.      *
  528.      * @return The Contributing Path PnL Realization List
  529.      */

  530.     public java.util.List<org.drip.capital.simulation.PathPnLRealization> pathPnLRealizationList()
  531.     {
  532.         return _pathPnLRealizationList;
  533.     }

  534.     @Override public java.util.List<java.lang.Integer> pathIndexList()
  535.     {
  536.         java.util.List<java.lang.Integer> pathIndexList = new java.util.ArrayList<java.lang.Integer>();

  537.         for (org.drip.capital.simulation.PathPnLRealization pathPnLRealization : _pathPnLRealizationList)
  538.         {
  539.             pathIndexList.add (
  540.                 pathPnLRealization.pathIndex()
  541.             );
  542.         }

  543.         return pathIndexList;
  544.     }

  545.     @Override public int pathCount()
  546.     {
  547.         return _pathPnLRealizationList.size();
  548.     }

  549.     @Override public java.util.List<java.lang.Double> grossSystemicStressPnLList()
  550.     {
  551.         java.util.List<java.lang.Double> grossSystemicStressPnLList =
  552.             new java.util.ArrayList<java.lang.Double>();

  553.         for (org.drip.capital.simulation.PathPnLRealization pathPnLRealization : _pathPnLRealizationList)
  554.         {
  555.             grossSystemicStressPnLList.add (
  556.                 pathPnLRealization.grossSystemicStressPnL()
  557.             );
  558.         }

  559.         return grossSystemicStressPnLList;
  560.     }

  561.     @Override public java.util.List<java.lang.Double> grossIdiosyncraticStressPnLList()
  562.     {
  563.         java.util.List<java.lang.Double> grossIdiosyncraticStressPnLList =
  564.             new java.util.ArrayList<java.lang.Double>();

  565.         for (org.drip.capital.simulation.PathPnLRealization pathPnLRealization : _pathPnLRealizationList)
  566.         {
  567.             grossIdiosyncraticStressPnLList.add (
  568.                 pathPnLRealization.grossIdiosyncraticStressPnL()
  569.             );
  570.         }

  571.         return grossIdiosyncraticStressPnLList;
  572.     }

  573.     @Override public java.util.List<java.lang.Double> grossFSPnLList()
  574.     {
  575.         java.util.List<java.lang.Double> grossFSPnLList = new java.util.ArrayList<java.lang.Double>();

  576.         for (org.drip.capital.simulation.PathPnLRealization pathPnLRealization : _pathPnLRealizationList)
  577.         {
  578.             grossFSPnLList.add (
  579.                 pathPnLRealization.grossFSPnL()
  580.             );
  581.         }

  582.         return grossFSPnLList;
  583.     }

  584.     @Override public java.util.List<java.lang.Double> grossPnLList()
  585.     {
  586.         java.util.List<java.lang.Double> grossPnLList = new java.util.ArrayList<java.lang.Double>();

  587.         for (org.drip.capital.simulation.PathPnLRealization pathPnLRealization : _pathPnLRealizationList)
  588.         {
  589.             grossPnLList.add (
  590.                 pathPnLRealization.grossPnL()
  591.             );
  592.         }

  593.         return grossPnLList;
  594.     }

  595.     @Override public org.drip.capital.simulation.EnsemblePnLDistribution ensembleDistribution()
  596.     {
  597.         java.util.List<java.lang.Double> grossPnLList = new java.util.ArrayList<java.lang.Double>();

  598.         java.util.List<java.lang.Double> grossFSPnLList = new java.util.ArrayList<java.lang.Double>();

  599.         java.util.List<java.lang.Double> grossSystemicStressPnLList =
  600.             new java.util.ArrayList<java.lang.Double>();

  601.         java.util.List<java.lang.Double> grossIdiosyncraticStressPnLList =
  602.             new java.util.ArrayList<java.lang.Double>();

  603.         for (org.drip.capital.simulation.PathPnLRealization pathPnLRealization : _pathPnLRealizationList)
  604.         {
  605.             grossSystemicStressPnLList.add (
  606.                 pathPnLRealization.grossSystemicStressPnL()
  607.             );

  608.             grossIdiosyncraticStressPnLList.add (
  609.                 pathPnLRealization.grossIdiosyncraticStressPnL()
  610.             );

  611.             grossFSPnLList.add (
  612.                 pathPnLRealization.grossFSPnL()
  613.             );

  614.             grossPnLList.add (
  615.                 pathPnLRealization.grossPnL()
  616.             );
  617.         }

  618.         try
  619.         {
  620.             return new org.drip.capital.simulation.EnsemblePnLDistribution (
  621.                 grossSystemicStressPnLList,
  622.                 grossIdiosyncraticStressPnLList,
  623.                 grossFSPnLList,
  624.                 grossPnLList
  625.             );
  626.         }
  627.         catch (java.lang.Exception e)
  628.         {
  629.             e.printStackTrace();
  630.         }

  631.         return null;
  632.     }
  633. }