MarketVertex.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>MarketVertex</i> holds the Market Realizations at a Market Trajectory Vertex needed for computing the
  78.  * Valuation Adjustment. 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 MarketVertex
  115. {
  116.     private double _csaSpread = java.lang.Double.NaN;
  117.     private double _csaReplicator = java.lang.Double.NaN;
  118.     private double _overnightRate = java.lang.Double.NaN;
  119.     private double _overnightReplicator = java.lang.Double.NaN;
  120.     private org.drip.analytics.date.JulianDate _anchorDate = null;
  121.     private org.drip.exposure.universe.MarketVertexEntity _clientMarketVertex = null;
  122.     private org.drip.exposure.universe.MarketVertexEntity _dealerMarketVertex = null;
  123.     private org.drip.exposure.evolver.LatentStateVertexContainer _latentStateVertexContainer = null;

  124.     /**
  125.      * Generate an Initial Instance of MarketVertex
  126.      *
  127.      * @param anchorDate The Anchor Date
  128.      * @param overnightReplicator The Realized Overnight Latent State Replicator
  129.      * @param csaReplicator The Realized CSA Latent State Replicator
  130.      * @param dealerHazardRate Realized Dealer Hazard Rate
  131.      * @param dealerRecoveryRate Realized Dealer Recovery Rate
  132.      * @param dealerFundingSpread Realized Dealer Funding Spread
  133.      * @param clientHazardRate Realized Client Hazard Rate
  134.      * @param clientRecoveryRate Realized Client Recovery Rate
  135.      * @param clientFundingSpread Realized Client Funding Spread
  136.      * @param latentStateVertexContainer Latent State Vertex Container
  137.      *
  138.      * @return The Initial MarketVertex Instance
  139.      */

  140.     public static final MarketVertex Epochal (
  141.         final org.drip.analytics.date.JulianDate anchorDate,
  142.         final double overnightReplicator,
  143.         final double csaReplicator,
  144.         final double dealerHazardRate,
  145.         final double dealerRecoveryRate,
  146.         final double dealerFundingSpread,
  147.         final double clientHazardRate,
  148.         final double clientRecoveryRate,
  149.         final double clientFundingSpread,
  150.         final org.drip.exposure.evolver.LatentStateVertexContainer latentStateVertexContainer)
  151.     {
  152.         try
  153.         {
  154.             return new org.drip.exposure.universe.MarketVertex (
  155.                 anchorDate,
  156.                 0.,
  157.                 overnightReplicator,
  158.                 0.,
  159.                 csaReplicator,
  160.                 org.drip.exposure.universe.MarketVertexEntity.Senior (
  161.                     0.,
  162.                     dealerHazardRate,
  163.                     dealerRecoveryRate,
  164.                     dealerFundingSpread,
  165.                     0.
  166.                 ),
  167.                 org.drip.exposure.universe.MarketVertexEntity.Senior (
  168.                     0.,
  169.                     clientHazardRate,
  170.                     clientRecoveryRate,
  171.                     clientFundingSpread,
  172.                     0.
  173.                 ),
  174.                 latentStateVertexContainer
  175.             );
  176.         }
  177.         catch (java.lang.Exception e)
  178.         {
  179.             e.printStackTrace();
  180.         }

  181.         return null;
  182.     }

  183.     /**
  184.      * Generate an Initial Instance of MarketVertex
  185.      *
  186.      * @param anchorDate The Anchor Date
  187.      * @param overnightReplicator The Realized Overnight Latent State Replicator
  188.      * @param csaReplicator The Realized CSA Latent State Replicator
  189.      * @param dealerHazardRate Realized Dealer Hazard Rate
  190.      * @param dealerSeniorRecoveryRate Realized Dealer Senior Recovery Rate
  191.      * @param dealerSeniorFundingSpread Realized Dealer Senior Funding Spread
  192.      * @param dealerSubordinateRecoveryRate Realized Dealer Subordinate Recovery Rate
  193.      * @param dealerSubordinateFundingSpread Realized Dealer Subordinate Funding Spread
  194.      * @param clientHazardRate Realized Client Hazard Rate
  195.      * @param clientRecoveryRate Realized Client Recovery Rate
  196.      * @param clientFundingSpread Realized Client Funding Spread
  197.      * @param latentStateVertexContainer Latent State Vertex Container
  198.      *
  199.      * @return The Initial MarketVertex Instance
  200.      */

  201.     public static final MarketVertex Epochal (
  202.         final org.drip.analytics.date.JulianDate anchorDate,
  203.         final double overnightReplicator,
  204.         final double csaReplicator,
  205.         final double dealerHazardRate,
  206.         final double dealerSeniorRecoveryRate,
  207.         final double dealerSeniorFundingSpread,
  208.         final double dealerSubordinateRecoveryRate,
  209.         final double dealerSubordinateFundingSpread,
  210.         final double clientHazardRate,
  211.         final double clientRecoveryRate,
  212.         final double clientFundingSpread,
  213.         final org.drip.exposure.evolver.LatentStateVertexContainer latentStateVertexContainer)
  214.     {
  215.         try {
  216.             return new org.drip.exposure.universe.MarketVertex (
  217.                 anchorDate,
  218.                 0.,
  219.                 overnightReplicator,
  220.                 0.,
  221.                 csaReplicator,
  222.                 org.drip.exposure.universe.MarketVertexEntity.SeniorSubordinate (
  223.                     0.,
  224.                     dealerHazardRate,
  225.                     dealerSeniorRecoveryRate,
  226.                     dealerSeniorFundingSpread,
  227.                     dealerSubordinateRecoveryRate,
  228.                     dealerSubordinateFundingSpread,
  229.                     0.
  230.                 ),
  231.                 org.drip.exposure.universe.MarketVertexEntity.Senior (
  232.                     0.,
  233.                     clientHazardRate,
  234.                     clientRecoveryRate,
  235.                     clientFundingSpread,
  236.                     0.
  237.                 ),
  238.                 latentStateVertexContainer
  239.             );
  240.         } catch (java.lang.Exception e) {
  241.             e.printStackTrace();
  242.         }

  243.         return null;
  244.     }

  245.     /**
  246.      * Construct a Nodal Market Vertex
  247.      *
  248.      * @param anchorDate The Vertex Date Anchor
  249.      * @param overnightRate The Realized Overnight Rate
  250.      * @param overnightReplicator The Realized Overnight Latent State Replicator
  251.      * @param csaSpread The Realized CSA Spread
  252.      * @param csaReplicator The Realized CSA Latent State Replicator
  253.      * @param dealerMarketVertex Dealer Market Vertex Instance
  254.      * @param clientMarketVertex Client Market Vertex Instance
  255.      * @param latentStateVertexContainer Latent State Vertex Container
  256.      *
  257.      * @return The Nodal Market Vertex Instance
  258.      */

  259.     public static final MarketVertex Nodal (
  260.         final org.drip.analytics.date.JulianDate anchorDate,
  261.         final double overnightRate,
  262.         final double overnightReplicator,
  263.         final double csaSpread,
  264.         final double csaReplicator,
  265.         final org.drip.exposure.universe.MarketVertexEntity dealerMarketVertex,
  266.         final org.drip.exposure.universe.MarketVertexEntity clientMarketVertex,
  267.         final org.drip.exposure.evolver.LatentStateVertexContainer latentStateVertexContainer)
  268.     {
  269.         try
  270.         {
  271.             return new MarketVertex (
  272.                 anchorDate,
  273.                 overnightRate,
  274.                 overnightReplicator,
  275.                 csaSpread,
  276.                 csaReplicator,
  277.                 dealerMarketVertex,
  278.                 clientMarketVertex,
  279.                 latentStateVertexContainer
  280.             );
  281.         }
  282.         catch (java.lang.Exception e)
  283.         {
  284.             e.printStackTrace();
  285.         }

  286.         return null;
  287.     }

  288.     /**
  289.      * MarketVertex Constructor
  290.      *
  291.      * @param anchorDate The Vertex Date Anchor
  292.      * @param overnightRate The Realized Overnight Rate
  293.      * @param overnightReplicator The Realized Overnight Latent State Replicator
  294.      * @param csaSpread The Realized CSA Spread
  295.      * @param csaReplicator The Realized CSA Latent State Replicator
  296.      * @param dealerMarketVertex Dealer Market Vertex Instance
  297.      * @param clientMarketVertex Client Market Vertex Instance
  298.      * @param latentStateVertexContainer Latent State Vertex Container
  299.      *
  300.      * @throws java.lang.Exception Thrown if the Inputs are Invalid
  301.      */

  302.     protected MarketVertex (
  303.         final org.drip.analytics.date.JulianDate anchorDate,
  304.         final double overnightRate,
  305.         final double overnightReplicator,
  306.         final double csaSpread,
  307.         final double csaReplicator,
  308.         final org.drip.exposure.universe.MarketVertexEntity dealerMarketVertex,
  309.         final org.drip.exposure.universe.MarketVertexEntity clientMarketVertex,
  310.         final org.drip.exposure.evolver.LatentStateVertexContainer latentStateVertexContainer)
  311.         throws java.lang.Exception
  312.     {
  313.         if (null == (_anchorDate = anchorDate) ||
  314.             !org.drip.numerical.common.NumberUtil.IsValid (_overnightRate = overnightRate) ||
  315.             !org.drip.numerical.common.NumberUtil.IsValid (_overnightReplicator = overnightReplicator) ||
  316.             !org.drip.numerical.common.NumberUtil.IsValid (_csaSpread = csaSpread) ||
  317.             !org.drip.numerical.common.NumberUtil.IsValid (_csaReplicator = csaReplicator) ||
  318.             null == (_dealerMarketVertex = dealerMarketVertex) ||
  319.             null == (_clientMarketVertex = clientMarketVertex) ||
  320.             null == (_latentStateVertexContainer = latentStateVertexContainer))
  321.         {
  322.             throw new java.lang.Exception ("MarketVertex Constructor => Invalid Inputs");
  323.         }

  324.         _latentStateVertexContainer = latentStateVertexContainer;
  325.     }

  326.     /**
  327.      * Retrieve the Date Anchor
  328.      *
  329.      * @return The Date Anchor
  330.      */

  331.     public org.drip.analytics.date.JulianDate anchorDate()
  332.     {
  333.         return _anchorDate;
  334.     }

  335.     /**
  336.      * Retrieve the Latent State Vertex Container
  337.      *
  338.      * @return The Latent State Vertex Container
  339.      */

  340.     org.drip.exposure.evolver.LatentStateVertexContainer latentStateVertexContainer()
  341.     {
  342.         return _latentStateVertexContainer;
  343.     }

  344.     /**
  345.      * Retrieve the Realized Value for the Latent State
  346.      *
  347.      * @param latentStateLabel The Latent State Label
  348.      *
  349.      * @return The Realized Value for the Latent State
  350.      *
  351.      * @throws java.lang.Exception Thrown if the Inputs are Invalid
  352.      */

  353.     public double latentStateValue (
  354.         final org.drip.state.identifier.LatentStateLabel latentStateLabel)
  355.         throws java.lang.Exception
  356.     {
  357.         return _latentStateVertexContainer.value (latentStateLabel);
  358.     }

  359.     /**
  360.      * Retrieve the Realized Overnight Index Rate
  361.      *
  362.      * @return The Realized Overnight Index Rate
  363.      */

  364.     public double overnightRate()
  365.     {
  366.         return _overnightRate;
  367.     }

  368.     /**
  369.      * Retrieve the Realized Overnight Index Numeraire
  370.      *
  371.      * @return The Realized Overnight Index Numeraire
  372.      */

  373.     public double overnightReplicator()
  374.     {
  375.         return _overnightReplicator;
  376.     }

  377.     /**
  378.      * Retrieve the Realized Spread over the Overnight Policy Rate corresponding to the CSA Scheme
  379.      *
  380.      * @return The Realized Spread over the Overnight Policy Rate corresponding to the CSA Scheme
  381.      */

  382.     public double csaSpread()
  383.     {
  384.         return _csaSpread;
  385.     }

  386.     /**
  387.      * Retrieve the Realized CSA Scheme Numeraire
  388.      *
  389.      * @return The Realized CSA Scheme Numeraire
  390.      */

  391.     public double csaReplicator()
  392.     {
  393.         return _csaReplicator;
  394.     }

  395.     /**
  396.      * Retrieve the Realized CSA Scheme Rate
  397.      *
  398.      * @return The Realized CSA Scheme Rate
  399.      */

  400.     public double csaRate()
  401.     {
  402.         return _overnightRate + _csaSpread;
  403.     }

  404.     /**
  405.      * Retrieve the Realized Dealer Senior Market Vertex
  406.      *
  407.      * @return The Realized Dealer Senior Market Vertex
  408.      */

  409.     public org.drip.exposure.universe.MarketVertexEntity dealer()
  410.     {
  411.         return _dealerMarketVertex;
  412.     }

  413.     /**
  414.      * Retrieve the Realized Client Market Vertex
  415.      *
  416.      * @return The Realized Client Market Vertex
  417.      */

  418.     public org.drip.exposure.universe.MarketVertexEntity client()
  419.     {
  420.         return _clientMarketVertex;
  421.     }
  422. }