MarketVertexEntity.java

  1. package org.drip.exposure.universe;

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

  76. /**
  77.  * <i>MarketVertexEntity</i> holds the Realizations at a Market Trajectory Vertex of the given XVA Entity
  78.  * (i.e., Dealer/Client). The References are:
  79.  *  
  80.  * <br><br>
  81.  *      <ul>
  82.  *          <li>
  83.  *              Burgard, C., and M. Kjaer (2013): Funding Costs, Funding Strategies <i>Risk</i> <b>23
  84.  *                  (12)</b> 82-87
  85.  *          </li>
  86.  *          <li>
  87.  *              Burgard, C., and M. Kjaer (2014): In the Balance <i>Risk</i> <b>24 (11)</b> 72-75
  88.  *          </li>
  89.  *          <li>
  90.  *              Burgard, C., and M. Kjaer (2014): PDE Representations of Derivatives with Bilateral Counter-
  91.  *                  party Risk and Funding Costs <i>Journal of Credit Risk</i> <b>7 (3)</b> 1-19
  92.  *          </li>
  93.  *          <li>
  94.  *              Gregory, J. (2009): Being Two-faced over Counter-party Credit Risk <i>Risk</i> <b>20 (2)</b>
  95.  *                  86-90
  96.  *          </li>
  97.  *          <li>
  98.  *              Piterbarg, V. (2010): Funding Beyond Discounting: Collateral Agreements and Derivatives
  99.  *                  Pricing <i>Risk</i> <b>21 (2)</b> 97-102
  100.  *          </li>
  101.  *          <li>
  102.  *      </ul>
  103.  *
  104.  *  <br><br>
  105.  *  <ul>
  106.  *      <li><b>Module </b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/PortfolioCore.md">Portfolio Core Module</a></li>
  107.  *      <li><b>Library</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/ExposureAnalyticsLibrary.md">Exposure Analytics</a></li>
  108.  *      <li><b>Project</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/exposure/README.md">Exposure Group Level Collateralized/Uncollateralized Exposure</a></li>
  109.  *      <li><b>Package</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/exposure/universe/README.md">Exposure Generation - Market States Simulation</a></li>
  110.  *  </ul>
  111.  *
  112.  * @author Lakshmi Krishnamurthy
  113.  */

  114. public class MarketVertexEntity
  115. {
  116.     private double _hazardRate = java.lang.Double.NaN;
  117.     private double _seniorRecoveryRate = java.lang.Double.NaN;
  118.     private double _seniorFundingSpread = java.lang.Double.NaN;
  119.     private double _survivalProbability = java.lang.Double.NaN;
  120.     private double _seniorFundingReplicator = java.lang.Double.NaN;
  121.     private double _subordinateRecoveryRate = java.lang.Double.NaN;
  122.     private double _subordinateFundingSpread = java.lang.Double.NaN;
  123.     private double _subordinateFundingReplicator = java.lang.Double.NaN;

  124.     /**
  125.      * Instance of Senior MarketVertexEntity
  126.      *
  127.      * @param timeWidth The Time Width of the Node
  128.      * @param hazardRate The Hazard Rate Latent State
  129.      * @param seniorRecoveryRate The Recovery Rate Latent State
  130.      * @param seniorFundingSpread The Funding Spread Latent State
  131.      * @param baseRate The Period Base Discount Rate
  132.      * @param previousMarketVertexEntity The Previous Instance of MarketVertexEntity
  133.      *
  134.      * @return Instance of Senior MarketVertexEntity
  135.      */

  136.     public static final MarketVertexEntity Senior (
  137.         final double timeWidth,
  138.         final double hazardRate,
  139.         final double seniorRecoveryRate,
  140.         final double seniorFundingSpread,
  141.         final double baseRate,
  142.         final org.drip.exposure.universe.MarketVertexEntity previousMarketVertexEntity)
  143.     {
  144.         if (null == previousMarketVertexEntity)
  145.         {
  146.             return null;
  147.         }

  148.         try
  149.         {
  150.             return new org.drip.exposure.universe.MarketVertexEntity (
  151.                 previousMarketVertexEntity.survivalProbability()
  152.                     * java.lang.Math.exp (-1. * hazardRate * timeWidth),
  153.                 hazardRate,
  154.                 seniorRecoveryRate,
  155.                 seniorFundingSpread,
  156.                 previousMarketVertexEntity.seniorFundingReplicator() *
  157.                     java.lang.Math.exp ((baseRate + seniorFundingSpread) * timeWidth),
  158.                 java.lang.Double.NaN,
  159.                 java.lang.Double.NaN,
  160.                 java.lang.Double.NaN
  161.             );
  162.         }
  163.         catch (java.lang.Exception e)
  164.         {
  165.             e.printStackTrace();
  166.         }

  167.         return null;
  168.     }

  169.     /**
  170.      * Instance of Senior MarketVertexEntity
  171.      *
  172.      * @param timeWidth The Time Width of the Node
  173.      * @param hazardRate The Hazard Rate Latent State
  174.      * @param seniorRecoveryRate The Recovery Rate Latent State
  175.      * @param seniorFundingSpread The Funding Spread Latent State
  176.      * @param baseRate The Period Base Discount Rate
  177.      *
  178.      * @return Instance of Senior MarketVertexEntity
  179.      */

  180.     public static final MarketVertexEntity Senior (
  181.         final double timeWidth,
  182.         final double hazardRate,
  183.         final double seniorRecoveryRate,
  184.         final double seniorFundingSpread,
  185.         final double baseRate)
  186.     {
  187.         try
  188.         {
  189.             return Senior (
  190.                 timeWidth,
  191.                 hazardRate,
  192.                 seniorRecoveryRate,
  193.                 seniorFundingSpread,
  194.                 baseRate,
  195.                 new MarketVertexEntity (
  196.                     1.,
  197.                     hazardRate,
  198.                     seniorRecoveryRate,
  199.                     seniorFundingSpread,
  200.                     1.,
  201.                     java.lang.Double.NaN,
  202.                     java.lang.Double.NaN,
  203.                     java.lang.Double.NaN
  204.                 )
  205.             );
  206.         }
  207.         catch (java.lang.Exception e)
  208.         {
  209.             e.printStackTrace();
  210.         }

  211.         return null;
  212.     }

  213.     /**
  214.      * Instance of Senior + Subordinate MarketVertexEntity
  215.      *
  216.      * @param timeWidth The Time Width
  217.      * @param hazardRate The Hazard Rate Latent State
  218.      * @param seniorRecoveryRate The Senior Recovery Rate Latent State
  219.      * @param seniorFundingSpread The Senior Funding Spread Latent State
  220.      * @param subordinateRecoveryRate The Subordinate Recovery Rate Latent State
  221.      * @param subordinateFundingSpread The Subordinate Funding Spread Latent State
  222.      * @param baseRate The Period Base Discount Rate
  223.      * @param previousMarketVertexEntity The Previous Instance of MarketVertexEntity
  224.      *
  225.      * @return Instance of Senior MarketVertexEntity
  226.      */

  227.     public static final MarketVertexEntity SeniorSubordinate (
  228.         final double timeWidth,
  229.         final double hazardRate,
  230.         final double seniorRecoveryRate,
  231.         final double seniorFundingSpread,
  232.         final double subordinateRecoveryRate,
  233.         final double subordinateFundingSpread,
  234.         final double baseRate,
  235.         final org.drip.exposure.universe.MarketVertexEntity previousMarketVertexEntity)
  236.     {
  237.         if (null == previousMarketVertexEntity)
  238.         {
  239.             return null;
  240.         }

  241.         try
  242.         {
  243.             return new org.drip.exposure.universe.MarketVertexEntity (
  244.                 previousMarketVertexEntity.survivalProbability() *
  245.                     java.lang.Math.exp (-1. * hazardRate * timeWidth),
  246.                 hazardRate,
  247.                 seniorRecoveryRate,
  248.                 seniorFundingSpread,
  249.                 previousMarketVertexEntity.seniorFundingReplicator() *
  250.                     java.lang.Math.exp ((baseRate + seniorFundingSpread) * timeWidth),
  251.                 subordinateRecoveryRate,
  252.                 subordinateFundingSpread,
  253.                 previousMarketVertexEntity.subordinateFundingReplicator() *
  254.                     java.lang.Math.exp ((baseRate + subordinateFundingSpread) * timeWidth)
  255.             );
  256.         }
  257.         catch (java.lang.Exception e)
  258.         {
  259.             e.printStackTrace();
  260.         }

  261.         return null;
  262.     }

  263.     /**
  264.      * Instance of Senior + Subordinate MarketVertexEntity
  265.      *
  266.      * @param timeWidth The Time Width
  267.      * @param hazardRate The Hazard Rate Latent State
  268.      * @param seniorRecoveryRate The Senior Recovery Rate Latent State
  269.      * @param seniorFundingSpread The Senior Funding Spread Latent State
  270.      * @param subordinateRecoveryRate The Subordinate Recovery Rate Latent State
  271.      * @param subordinateFundingSpread The Subordinate Funding Spread Latent State
  272.      * @param baseRate The Period Base Discount Rate
  273.      *
  274.      * @return Instance of Senior MarketVertexEntity
  275.      */

  276.     public static final MarketVertexEntity SeniorSubordinate (
  277.         final double timeWidth,
  278.         final double hazardRate,
  279.         final double seniorRecoveryRate,
  280.         final double seniorFundingSpread,
  281.         final double subordinateRecoveryRate,
  282.         final double subordinateFundingSpread,
  283.         final double baseRate)
  284.     {
  285.         try
  286.         {
  287.             return SeniorSubordinate (
  288.                 timeWidth,
  289.                 hazardRate,
  290.                 seniorRecoveryRate,
  291.                 seniorFundingSpread,
  292.                 subordinateRecoveryRate,
  293.                 subordinateFundingSpread,
  294.                 baseRate,
  295.                 new MarketVertexEntity (
  296.                     1.,
  297.                     hazardRate,
  298.                     seniorRecoveryRate,
  299.                     seniorFundingSpread,
  300.                     1.,
  301.                     subordinateRecoveryRate,
  302.                     subordinateFundingSpread,
  303.                     1.
  304.                 )
  305.             );
  306.         }
  307.         catch (java.lang.Exception e)
  308.         {
  309.             e.printStackTrace();
  310.         }

  311.         return null;
  312.     }

  313.     /**
  314.      * MarketVertexEntity Constructor
  315.      *
  316.      * @param survivalProbability The Realized Entity Survival Probability
  317.      * @param hazardRate The Realized Entity Hazard Rate Latent State
  318.      * @param seniorRecoveryRate The Entity Senior Recovery Rate Latent State
  319.      * @param seniorFundingSpread The Entity Senior Funding Spread Latent State
  320.      * @param seniorFundingReplicator The Entity Senior Funding Replicator Vertex Latent State
  321.      * @param subordinateRecoveryRate The Entity Subordinate Recovery Rate Latent State
  322.      * @param subordinateFundingSpread The Entity Subordinate Funding Spread Latent State
  323.      * @param subordinateFundingReplicator The Entity Subordinate Funding Replicator Vertex Latent State
  324.      *
  325.      * @throws java.lang.Exception Thrown if the Inputs are Invalid
  326.      */

  327.     public MarketVertexEntity (
  328.         final double survivalProbability,
  329.         final double hazardRate,
  330.         final double seniorRecoveryRate,
  331.         final double seniorFundingSpread,
  332.         final double seniorFundingReplicator,
  333.         final double subordinateRecoveryRate,
  334.         final double subordinateFundingSpread,
  335.         final double subordinateFundingReplicator)
  336.         throws java.lang.Exception
  337.     {
  338.         if (!org.drip.numerical.common.NumberUtil.IsValid (_survivalProbability = survivalProbability) ||
  339.             !org.drip.numerical.common.NumberUtil.IsValid (_hazardRate = hazardRate) ||
  340.             !org.drip.numerical.common.NumberUtil.IsValid (_seniorRecoveryRate = seniorRecoveryRate) ||
  341.             !org.drip.numerical.common.NumberUtil.IsValid (_seniorFundingSpread = seniorFundingSpread) ||
  342.             !org.drip.numerical.common.NumberUtil.IsValid (_seniorFundingReplicator = seniorFundingReplicator))
  343.         {
  344.             throw new java.lang.Exception ("MarketVertexEntity Constructor => Invalid Inputs");
  345.         }

  346.         _subordinateRecoveryRate = subordinateRecoveryRate;
  347.         _subordinateFundingSpread = subordinateFundingSpread;
  348.         _subordinateFundingReplicator = subordinateFundingReplicator;
  349.     }

  350.     /**
  351.      * Retrieve the Realized Entity Survival Probability
  352.      *
  353.      * @return The Realized Entity Survival Probability
  354.      */

  355.     public double survivalProbability()
  356.     {
  357.         return _survivalProbability;
  358.     }

  359.     /**
  360.      * Retrieve the Realized Entity Hazard Rate Vertex Latent State
  361.      *
  362.      * @return The Realized Entity Hazard Rate Vertex Latent State
  363.      */

  364.     public double hazardRate()
  365.     {
  366.         return _hazardRate;
  367.     }

  368.     /**
  369.      * Retrieve the Realized Entity Senior Recovery Rate Vertex Latent State
  370.      *
  371.      * @return The Realized Entity Senior Recovery Rate Vertex Latent State
  372.      */

  373.     public double seniorRecoveryRate()
  374.     {
  375.         return _seniorRecoveryRate;
  376.     }

  377.     /**
  378.      * Retrieve the Realized Entity Senior Funding Spread Vertex Latent State
  379.      *
  380.      * @return The Realized Entity Senior Funding Spread Vertex Latent State
  381.      */

  382.     public double seniorFundingSpread()
  383.     {
  384.         return _seniorFundingSpread;
  385.     }

  386.     /**
  387.      * Retrieve the Realized Entity Senior Funding Replicator Vertex Latent State
  388.      *
  389.      * @return The Realized Entity Senior Funding Replicator Vertex Latent State
  390.      */

  391.     public double seniorFundingReplicator()
  392.     {
  393.         return _seniorFundingReplicator;
  394.     }

  395.     /**
  396.      * Retrieve the Realized Entity Subordinate Recovery Rate Vertex Latent State
  397.      *
  398.      * @return The Realized Entity Subordinate Recovery Rate Vertex Latent State
  399.      */

  400.     public double subordinateRecoveryRate()
  401.     {
  402.         return _subordinateRecoveryRate;
  403.     }

  404.     /**
  405.      * Retrieve the Realized Entity Subordinate Funding Spread Vertex Latent State
  406.      *
  407.      * @return The Realized Entity Subordinate Funding Spread Vertex Latent State
  408.      */

  409.     public double subordinateFundingSpread()
  410.     {
  411.         return _subordinateFundingSpread;
  412.     }

  413.     /**
  414.      * Retrieve the Realized Entity Subordinate Funding Replicator Vertex Latent State
  415.      *
  416.      * @return The Realized Entity Subordinate Funding Replicator Vertex Latent State
  417.      */

  418.     public double subordinateFundingReplicator()
  419.     {
  420.         return _subordinateFundingReplicator;
  421.     }
  422. }