MarketPath.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>MarketPath</i> holds the Vertex Market Realizations at the Trajectory Vertexes along the Path of a
  78.  * Simulation. 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 MarketPath
  115. {
  116.     private org.drip.analytics.date.JulianDate[] _vertexDateArray = null;
  117.     private org.drip.exposure.universe.MarketVertex _epochalMarketVertex = null;
  118.     private org.drip.exposure.universe.MarketVertex _terminalMarketVertex = null;
  119.     private java.util.Map<java.lang.Integer, org.drip.exposure.universe.MarketVertex> _marketVertexTrajectory
  120.         = null;

  121.     /**
  122.      * Generate the Market Path from Market Vertex Array
  123.      *
  124.      * @param marketVertexArray The Market Vertex Array
  125.      *
  126.      * @return The Market Path
  127.      */

  128.     public static final MarketPath FromMarketVertexArray (
  129.         final org.drip.exposure.universe.MarketVertex[] marketVertexArray)
  130.     {
  131.         if (null == marketVertexArray)
  132.         {
  133.             return null;
  134.         }

  135.         int vertexCount = marketVertexArray.length;

  136.         if (0 == vertexCount)
  137.         {
  138.             return null;
  139.         }

  140.         java.util.Map<java.lang.Integer, org.drip.exposure.universe.MarketVertex> marketVertexTrajectory =
  141.             new java.util.TreeMap<java.lang.Integer, org.drip.exposure.universe.MarketVertex>();

  142.         for (int vertexIndex = 0; vertexIndex < vertexCount; ++vertexIndex)
  143.         {
  144.             int marketVertexDate = marketVertexArray[vertexIndex].anchorDate().julian();

  145.             if (marketVertexTrajectory.containsKey (marketVertexDate))
  146.             {
  147.                 return null;
  148.             }

  149.             marketVertexTrajectory.put (
  150.                 marketVertexDate,
  151.                 marketVertexArray[vertexIndex]
  152.             );
  153.         }

  154.         try
  155.         {
  156.             return new MarketPath (marketVertexTrajectory);
  157.         }
  158.         catch (java.lang.Exception e)
  159.         {
  160.             e.printStackTrace();
  161.         }

  162.         return null;
  163.     }

  164.     /**
  165.      * MarketPath Constructor
  166.      *
  167.      * @param marketVertexTrajectory Date Map of the Market Vertexes
  168.      *
  169.      * @throws java.lang.Exception Thrown if the Inputs are Invalid
  170.      */

  171.     public MarketPath (
  172.         final java.util.Map<java.lang.Integer, org.drip.exposure.universe.MarketVertex> marketVertexTrajectory)
  173.         throws java.lang.Exception
  174.     {
  175.         if (null == (_marketVertexTrajectory = marketVertexTrajectory))
  176.         {
  177.             throw new java.lang.Exception ("MarketPath Constructor => Invalid Inputs");
  178.         }

  179.         int vertexCount = _marketVertexTrajectory.size();

  180.         if (0 == _marketVertexTrajectory.size())
  181.         {
  182.             throw new java.lang.Exception ("MarketPath Constructor => Invalid Inputs");
  183.         }

  184.         int vertexIndex = 0;
  185.         _vertexDateArray = new org.drip.analytics.date.JulianDate[vertexCount];

  186.         for (java.util.Map.Entry<java.lang.Integer, org.drip.exposure.universe.MarketVertex>
  187.             marketVertexMapEntry : _marketVertexTrajectory.entrySet())
  188.         {
  189.             org.drip.exposure.universe.MarketVertex marketVertex = marketVertexMapEntry.getValue();

  190.             if (0 == vertexIndex)
  191.             {
  192.                 _epochalMarketVertex = marketVertex;
  193.             }

  194.             _vertexDateArray[vertexIndex++] = marketVertex.anchorDate();

  195.             if (vertexCount == vertexIndex)
  196.             {
  197.                 _terminalMarketVertex = marketVertex;
  198.             }
  199.         }
  200.     }

  201.     /**
  202.      * Retrieve the Array of the Vertex Anchor Dates
  203.      *
  204.      * @return The Array of the Vertex Anchor Dates
  205.      */

  206.     public org.drip.analytics.date.JulianDate[] anchorDates()
  207.     {
  208.         return _vertexDateArray;
  209.     }

  210.     /**
  211.      * Retrieve the Trajectory of the Market Vertexes
  212.      *
  213.      * @return The Market Vertex Trajectory
  214.      */

  215.     public java.util.Map<java.lang.Integer, org.drip.exposure.universe.MarketVertex> trajectory()
  216.     {
  217.         return _marketVertexTrajectory;
  218.     }

  219.     /**
  220.      * Retrieve the Array of the Market Vertexes
  221.      *
  222.      * @return The Market Vertex Array
  223.      */

  224.     public org.drip.exposure.universe.MarketVertex[] marketVertexArray()
  225.     {
  226.         int vertexCount = _marketVertexTrajectory.size();

  227.         int vertexIndex = 0;
  228.         org.drip.exposure.universe.MarketVertex[] marketVertexArray = new
  229.             org.drip.exposure.universe.MarketVertex[vertexCount];

  230.         for (java.util.Map.Entry<java.lang.Integer, org.drip.exposure.universe.MarketVertex>
  231.             marketVertexMapEntry : _marketVertexTrajectory.entrySet())
  232.         {
  233.             marketVertexArray[vertexIndex++] = marketVertexMapEntry.getValue();
  234.         }

  235.         return marketVertexArray;
  236.     }

  237.     /**
  238.      * Retrieve the Epochal Market Vertex
  239.      *
  240.      * @return The Epochal Market Vertex
  241.      */

  242.     public org.drip.exposure.universe.MarketVertex epochalMarketVertex()
  243.     {
  244.         return _epochalMarketVertex;
  245.     }

  246.     /**
  247.      * Retrieve the Terminal Market Vertex
  248.      *
  249.      * @return The Terminal Market Vertex
  250.      */

  251.     public org.drip.exposure.universe.MarketVertex terminalMarketVertex()
  252.     {
  253.         return _terminalMarketVertex;
  254.     }

  255.     /**
  256.      * Indicate if the Market Vertex is available for the Specified Date
  257.      *
  258.      * @param vertexDate The Vertex Date
  259.      *
  260.      * @return TRUE - The Market Vertex is available for the Specified Date
  261.      */

  262.     public boolean containsDate (
  263.         final int vertexDate)
  264.     {
  265.         return _marketVertexTrajectory.containsKey (vertexDate);
  266.     }

  267.     /**
  268.      * Retrieve the Market Vertex for the Specified Date
  269.      *
  270.      * @param vertexDate The Vertex Date
  271.      *
  272.      * @return The Market Vertex for the Specified Date
  273.      */

  274.     public org.drip.exposure.universe.MarketVertex marketVertex (
  275.         final int vertexDate)
  276.     {
  277.         return containsDate (vertexDate) ? _marketVertexTrajectory.get (vertexDate) : null;
  278.     }
  279. }