SystemicScenarioPnLSeries.java

  1. package org.drip.capital.shell;

  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>SystemicScenarioPnLSeries</i> contains the PnL Series of a Systemic Stress Scenario. The References
  76.  *  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/shell/README.md">Economic Risk Capital Parameter Contexts</a></li>
  98.  *  </ul>
  99.  *
  100.  * @author Lakshmi Krishnamurthy
  101.  */

  102. public class SystemicScenarioPnLSeries
  103. {
  104.     private org.drip.capital.stress.PnLSeries _lostDecade = null;
  105.     private org.drip.capital.stress.PnLSeries _baseline1974 = null;
  106.     private org.drip.capital.stress.PnLSeries _baseline2008 = null;
  107.     private org.drip.capital.stress.PnLSeries _deepDownturn = null;
  108.     private org.drip.capital.stress.PnLSeries _dollarDecline = null;
  109.     private org.drip.capital.stress.PnLSeries _interestRateShock = null;

  110.     /**
  111.      * Construct the SystemicScenarioPnLSeries with Zeros
  112.      *
  113.      * @return The SystemicScenarioPnLSeries with Zeros
  114.      */

  115.     public static final SystemicScenarioPnLSeries ZERO()
  116.     {
  117.         try
  118.         {
  119.             return new SystemicScenarioPnLSeries (
  120.                 org.drip.capital.stress.PnLSeries.SingleZeroOutcome(),
  121.                 org.drip.capital.stress.PnLSeries.SingleZeroOutcome(),
  122.                 org.drip.capital.stress.PnLSeries.SingleZeroOutcome(),
  123.                 org.drip.capital.stress.PnLSeries.SingleZeroOutcome(),
  124.                 org.drip.capital.stress.PnLSeries.SingleZeroOutcome(),
  125.                 org.drip.capital.stress.PnLSeries.SingleZeroOutcome()
  126.             );
  127.         }
  128.         catch (java.lang.Exception e)
  129.         {
  130.             e.printStackTrace();
  131.         }

  132.         return null;
  133.     }

  134.     /**
  135.      * Construct the SystemicScenarioPnLSeries with Single Outcome
  136.      *
  137.      * @param baseline1974PnL 1974 Baseline PnL
  138.      * @param baseline2008PnL 2008 Baseline PnL
  139.      * @param deepDownturnPnL Deep Down-turn PnL
  140.      * @param dollarDeclinePnL Dollar Decline PnL
  141.      * @param interestRateShockPnL Interest Rate Shock PnL
  142.      * @param lostDecadePnL Lost Decade PnL
  143.      *
  144.      * @return The SystemicScenarioPnLSeries with Single Outcome
  145.      */

  146.     public static final SystemicScenarioPnLSeries SingleOutcome (
  147.         final double baseline1974PnL,
  148.         final double baseline2008PnL,
  149.         final double deepDownturnPnL,
  150.         final double dollarDeclinePnL,
  151.         final double interestRateShockPnL,
  152.         final double lostDecadePnL)
  153.     {
  154.         try
  155.         {
  156.             return new SystemicScenarioPnLSeries (
  157.                 org.drip.capital.stress.PnLSeries.SingleOutcome (
  158.                     baseline1974PnL
  159.                 ),
  160.                 org.drip.capital.stress.PnLSeries.SingleOutcome (
  161.                     baseline2008PnL
  162.                 ),
  163.                 org.drip.capital.stress.PnLSeries.SingleOutcome (
  164.                     deepDownturnPnL
  165.                 ),
  166.                 org.drip.capital.stress.PnLSeries.SingleOutcome (
  167.                     dollarDeclinePnL
  168.                 ),
  169.                 org.drip.capital.stress.PnLSeries.SingleOutcome (
  170.                     interestRateShockPnL
  171.                 ),
  172.                 org.drip.capital.stress.PnLSeries.SingleOutcome (
  173.                     lostDecadePnL
  174.                 )
  175.             );
  176.         }
  177.         catch (java.lang.Exception e)
  178.         {
  179.             e.printStackTrace();
  180.         }

  181.         return null;
  182.     }

  183.     /**
  184.      * Aggregate the Array of SystemicScenarioPnLSeries onto a Composite SystemicScenarioPnLSeries
  185.      *
  186.      * @param systemicScenarioPnLSeriesArray Array of SystemicScenarioPnLSeries
  187.      *
  188.      * @return The Aggregated, Composite SystemicScenarioPnLSeries
  189.      */

  190.     public static final SystemicScenarioPnLSeries AggregateComposite (
  191.         final SystemicScenarioPnLSeries[] systemicScenarioPnLSeriesArray)
  192.     {
  193.         if (null == systemicScenarioPnLSeriesArray)
  194.         {
  195.             return null;
  196.         }

  197.         double lostDecadePnLComposite = 0.;
  198.         double baseline1974PnLComposite = 0.;
  199.         double baseline2008PnLComposite = 0.;
  200.         double deepDownturnPnLComposite = 0.;
  201.         double dollarDeclinePnLComposite = 0.;
  202.         double interestRateShockPnLComposite = 0.;
  203.         int pnlCount = systemicScenarioPnLSeriesArray.length;

  204.         if (0 == pnlCount)
  205.         {
  206.             return null;
  207.         }

  208.         for (int pnlIndex = 0;
  209.             pnlIndex < pnlCount;
  210.             ++pnlIndex)
  211.         {
  212.             if (null != systemicScenarioPnLSeriesArray[pnlIndex])
  213.             {
  214.                 lostDecadePnLComposite = lostDecadePnLComposite +
  215.                     systemicScenarioPnLSeriesArray[pnlIndex].lostDecade().composite();

  216.                 baseline1974PnLComposite = baseline1974PnLComposite +
  217.                     systemicScenarioPnLSeriesArray[pnlIndex].baseline1974().composite();

  218.                 baseline2008PnLComposite = baseline2008PnLComposite +
  219.                     systemicScenarioPnLSeriesArray[pnlIndex].baseline2008().composite();

  220.                 deepDownturnPnLComposite = deepDownturnPnLComposite +
  221.                     systemicScenarioPnLSeriesArray[pnlIndex].deepDownturn().composite();

  222.                 dollarDeclinePnLComposite = dollarDeclinePnLComposite +
  223.                     systemicScenarioPnLSeriesArray[pnlIndex].dollarDecline().composite();

  224.                 interestRateShockPnLComposite = interestRateShockPnLComposite +
  225.                     systemicScenarioPnLSeriesArray[pnlIndex].interestRateShock().composite();
  226.             }
  227.         }

  228.         try
  229.         {
  230.             return new SystemicScenarioPnLSeries (
  231.                 org.drip.capital.stress.PnLSeries.SingleOutcome (
  232.                     baseline1974PnLComposite
  233.                 ),
  234.                 org.drip.capital.stress.PnLSeries.SingleOutcome (
  235.                     baseline2008PnLComposite
  236.                 ),
  237.                 org.drip.capital.stress.PnLSeries.SingleOutcome (
  238.                     deepDownturnPnLComposite
  239.                 ),
  240.                 org.drip.capital.stress.PnLSeries.SingleOutcome (
  241.                     dollarDeclinePnLComposite
  242.                 ),
  243.                 org.drip.capital.stress.PnLSeries.SingleOutcome (
  244.                     interestRateShockPnLComposite
  245.                 ),
  246.                 org.drip.capital.stress.PnLSeries.SingleOutcome (
  247.                     lostDecadePnLComposite
  248.                 )
  249.             );
  250.         }
  251.         catch (java.lang.Exception e)
  252.         {
  253.             e.printStackTrace();
  254.         }

  255.         return null;
  256.     }

  257.     /**
  258.      * SystemicScenarioPnLSeries Constructor
  259.      *
  260.      * @param baseline1974 1974 Baseline PnL Series
  261.      * @param baseline2008 2008 Baseline PnL Series
  262.      * @param deepDownturn Deep Down-turn PnL Series
  263.      * @param dollarDecline Dollar Decline PnL Series
  264.      * @param interestRateShock Interest Rate Shock PnL Series
  265.      * @param lostDecade Lost Decade PnL Series
  266.      *
  267.      * @throws java.lang.Exception Thrown if the Inputs are Invalid
  268.      */

  269.     public SystemicScenarioPnLSeries (
  270.         final org.drip.capital.stress.PnLSeries baseline1974,
  271.         final org.drip.capital.stress.PnLSeries baseline2008,
  272.         final org.drip.capital.stress.PnLSeries deepDownturn,
  273.         final org.drip.capital.stress.PnLSeries dollarDecline,
  274.         final org.drip.capital.stress.PnLSeries interestRateShock,
  275.         final org.drip.capital.stress.PnLSeries lostDecade)
  276.         throws java.lang.Exception
  277.     {
  278.         if (null == (_baseline1974 = baseline1974) ||
  279.             null == (_baseline2008 = baseline2008) ||
  280.             null == (_deepDownturn = deepDownturn) ||
  281.             null == (_dollarDecline = dollarDecline) ||
  282.             null == (_interestRateShock = interestRateShock) ||
  283.             null == (_lostDecade = lostDecade))
  284.         {
  285.             throw new java.lang.Exception (
  286.                 "SystemicScenarioPnLSeries Constructor => Invalid inputs"
  287.             );
  288.         }
  289.     }

  290.     /**
  291.      * Retrieve the 1974 Baseline PnL Series
  292.      *
  293.      * @return The 1974 Baseline PnL Series
  294.      */

  295.     public org.drip.capital.stress.PnLSeries baseline1974()
  296.     {
  297.         return _baseline1974;
  298.     }

  299.     /**
  300.      * Retrieve the 2008 Baseline PnL Series
  301.      *
  302.      * @return The 2008 Baseline PnL Series
  303.      */

  304.     public org.drip.capital.stress.PnLSeries baseline2008()
  305.     {
  306.         return _baseline2008;
  307.     }

  308.     /**
  309.      * Retrieve the Deep Down-turn PnL Series
  310.      *
  311.      * @return The Deep Down-turn PnL Series
  312.      */

  313.     public org.drip.capital.stress.PnLSeries deepDownturn()
  314.     {
  315.         return _deepDownturn;
  316.     }

  317.     /**
  318.      * Retrieve the Dollar Decline PnL Series
  319.      *
  320.      * @return The Dollar Decline PnL Series
  321.      */

  322.     public org.drip.capital.stress.PnLSeries dollarDecline()
  323.     {
  324.         return _dollarDecline;
  325.     }

  326.     /**
  327.      * Retrieve the Interest Rate Shock PnL Series
  328.      *
  329.      * @return The Interest Rate Shock PnL Series
  330.      */

  331.     public org.drip.capital.stress.PnLSeries interestRateShock()
  332.     {
  333.         return _interestRateShock;
  334.     }

  335.     /**
  336.      * Retrieve the Lost Decade PnL Series
  337.      *
  338.      * @return The Lost Decade PnL Series
  339.      */

  340.     public org.drip.capital.stress.PnLSeries lostDecade()
  341.     {
  342.         return _lostDecade;
  343.     }

  344.     @Override public java.lang.String toString()
  345.     {
  346.         return "[" + _baseline1974.toString() + " | " +
  347.             _baseline2008.toString() + " | " +
  348.             _deepDownturn.toString() + " | " +
  349.             _dollarDecline.toString() + " | " +
  350.             _interestRateShock.toString() + " | " +
  351.             _lostDecade.toString() + "]";
  352.     }
  353. }