MarketVertexGenerator.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>MarketVertexGenerator</i> generates the Market Realizations at a Trajectory Vertex needed for computing
  78.  * the 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 MarketVertexGenerator
  115. {
  116.     private int _spotDate = -1;
  117.     private double[] _ycfWidth = null;
  118.     private int[] _eventDateArray = null;
  119.     private org.drip.exposure.evolver.EntityDynamicsContainer _entityDynamicsContainer = null;
  120.     private org.drip.exposure.evolver.LatentStateDynamicsContainer _latentStateDynamicsContainer = null;
  121.     private org.drip.exposure.evolver.PrimarySecurityDynamicsContainer _primarySecurityDynamicsContainer =
  122.         null;

  123.     private org.drip.measure.process.DiffusionEvolver evolver (
  124.         final org.drip.state.identifier.LatentStateLabel latentStateLabel)
  125.     {
  126.         org.drip.exposure.evolver.TerminalLatentState terminalLatentState =
  127.             _latentStateDynamicsContainer.terminal (latentStateLabel);

  128.         if (null == terminalLatentState)
  129.         {
  130.             terminalLatentState = _latentStateDynamicsContainer.terminal (latentStateLabel);
  131.         }

  132.         return null == terminalLatentState ? null : terminalLatentState.evolver();
  133.     }

  134.     private java.util.List<org.drip.measure.realization.JumpDiffusionVertex[]> latentStateVertexArrayList (
  135.         final java.util.List<org.drip.state.identifier.LatentStateLabel> latentStateLabelList,
  136.         final org.drip.exposure.universe.MarketVertex initialMarketVertex,
  137.         final org.drip.exposure.universe.LatentStateWeiner latentStateWeiner,
  138.         final int terminalDate)
  139.     {
  140.         if (null == latentStateLabelList)
  141.         {
  142.             return null;
  143.         }

  144.         java.util.List<org.drip.measure.realization.JumpDiffusionVertex[]> latentStateVertexArrayList = new
  145.             java.util.ArrayList<org.drip.measure.realization.JumpDiffusionVertex[]>();

  146.         for (org.drip.state.identifier.LatentStateLabel latentStateLabel : latentStateLabelList)
  147.         {
  148.             org.drip.measure.process.DiffusionEvolver latentStateDiffusionEvolver = evolver
  149.                 (latentStateLabel);

  150.             if (null == latentStateDiffusionEvolver)
  151.             {
  152.                 continue;
  153.             }

  154.             try
  155.             {
  156.                 latentStateVertexArrayList.add (
  157.                     latentStateDiffusionEvolver.vertexSequence (
  158.                         new org.drip.measure.realization.JumpDiffusionVertex (
  159.                             terminalDate,
  160.                             initialMarketVertex.latentStateValue (latentStateLabel),
  161.                             0.,
  162.                             false
  163.                         ),
  164.                         org.drip.measure.realization.JumpDiffusionEdgeUnit.Diffusion (
  165.                             _ycfWidth,
  166.                             latentStateWeiner.incrementArray (latentStateLabel)
  167.                         ),
  168.                         _ycfWidth
  169.                     )
  170.                 );
  171.             }
  172.             catch (java.lang.Exception e)
  173.             {
  174.                 e.printStackTrace();
  175.             }
  176.         }

  177.         return latentStateVertexArrayList;
  178.     }

  179.     private org.drip.measure.realization.JumpDiffusionVertex[] overnightReplicatorVertexArray (
  180.         final org.drip.exposure.universe.MarketVertex initialMarketVertex,
  181.         final org.drip.exposure.universe.LatentStateWeiner latentStateWeiner,
  182.         final int terminalDate)
  183.     {
  184.         org.drip.exposure.evolver.PrimarySecurity overnightReplicator =
  185.             _primarySecurityDynamicsContainer.overnight();

  186.         try
  187.         {
  188.             return overnightReplicator.evolver().vertexSequenceReverse (
  189.                 new org.drip.measure.realization.JumpDiffusionVertex (
  190.                     terminalDate,
  191.                     initialMarketVertex.overnightReplicator(),
  192.                     0.,
  193.                     false
  194.                 ),
  195.                 org.drip.measure.realization.JumpDiffusionEdgeUnit.Diffusion (
  196.                     _ycfWidth,
  197.                     latentStateWeiner.incrementArray (overnightReplicator.label())
  198.                 ),
  199.                 _ycfWidth
  200.             );
  201.         }
  202.         catch (java.lang.Exception e)
  203.         {
  204.             e.printStackTrace();
  205.         }

  206.         return null;
  207.     }

  208.     private org.drip.measure.realization.JumpDiffusionVertex[] csaReplicatorVertexArray (
  209.         final org.drip.exposure.universe.MarketVertex initialMarketVertex,
  210.         final org.drip.exposure.universe.LatentStateWeiner latentStateWeiner,
  211.         final int terminalDate)
  212.     {
  213.         org.drip.exposure.evolver.PrimarySecurity csaReplicator = _primarySecurityDynamicsContainer.csa();

  214.         try
  215.         {
  216.             return csaReplicator.evolver().vertexSequenceReverse (
  217.                 new org.drip.measure.realization.JumpDiffusionVertex (
  218.                     terminalDate,
  219.                     initialMarketVertex.csaReplicator(),
  220.                     0.,
  221.                     false
  222.                 ),
  223.                 org.drip.measure.realization.JumpDiffusionEdgeUnit.Diffusion (
  224.                     _ycfWidth,
  225.                     latentStateWeiner.incrementArray (csaReplicator.label())
  226.                 ),
  227.                 _ycfWidth
  228.             );
  229.         }
  230.         catch (java.lang.Exception e)
  231.         {
  232.             e.printStackTrace();
  233.         }

  234.         return null;
  235.     }

  236.     private org.drip.measure.realization.JumpDiffusionVertex[] dealerSeniorFundingReplicatorVertexArray (
  237.         final org.drip.exposure.universe.MarketVertex initialMarketVertex,
  238.         final org.drip.exposure.universe.LatentStateWeiner latentStateWeiner,
  239.         final int terminalDate)
  240.     {
  241.         org.drip.exposure.evolver.PrimarySecurity dealerSeniorFundingReplicator =
  242.             _primarySecurityDynamicsContainer.dealerSeniorFunding();

  243.         try
  244.         {
  245.             return dealerSeniorFundingReplicator.evolver().vertexSequenceReverse (
  246.                 new org.drip.measure.realization.JumpDiffusionVertex (
  247.                     terminalDate,
  248.                     initialMarketVertex.dealer().seniorFundingReplicator(),
  249.                     0.,
  250.                     false
  251.                 ),
  252.                 org.drip.measure.realization.JumpDiffusionEdgeUnit.Diffusion (
  253.                     _ycfWidth,
  254.                     latentStateWeiner.incrementArray (dealerSeniorFundingReplicator.label())
  255.                 ),
  256.                 _ycfWidth
  257.             );
  258.         }
  259.         catch (java.lang.Exception e)
  260.         {
  261.             e.printStackTrace();
  262.         }

  263.         return null;
  264.     }

  265.     private org.drip.measure.realization.JumpDiffusionVertex[]
  266.         dealerSubordinateFundingReplicatorVertexArray (
  267.             final org.drip.exposure.universe.MarketVertex initialMarketVertex,
  268.             final org.drip.exposure.universe.LatentStateWeiner latentStateWeiner,
  269.             final int terminalDate)
  270.     {
  271.         org.drip.exposure.evolver.PrimarySecurity dealerSubordinateFundingReplicator =
  272.             _primarySecurityDynamicsContainer.dealerSubordinateFunding();

  273.         double initialDealerSubordinateFundingReplicator =
  274.             initialMarketVertex.dealer().subordinateFundingReplicator();

  275.         if (null == dealerSubordinateFundingReplicator ||
  276.             !org.drip.numerical.common.NumberUtil.IsValid (initialDealerSubordinateFundingReplicator))
  277.         {
  278.             return null;
  279.         }

  280.         try
  281.         {
  282.             return dealerSubordinateFundingReplicator.evolver().vertexSequenceReverse (
  283.                 new org.drip.measure.realization.JumpDiffusionVertex (
  284.                     terminalDate,
  285.                     initialDealerSubordinateFundingReplicator,
  286.                     0.,
  287.                     false
  288.                 ),
  289.                 org.drip.measure.realization.JumpDiffusionEdgeUnit.Diffusion (
  290.                     _ycfWidth,
  291.                     latentStateWeiner.incrementArray (dealerSubordinateFundingReplicator.label())
  292.                 ),
  293.                 _ycfWidth
  294.             );
  295.         }
  296.         catch (java.lang.Exception e)
  297.         {
  298.             e.printStackTrace();
  299.         }

  300.         return null;
  301.     }

  302.     private org.drip.measure.realization.JumpDiffusionVertex[] clientFundingReplicatorVertexArray (
  303.         final org.drip.exposure.universe.MarketVertex initialMarketVertex,
  304.         final org.drip.exposure.universe.LatentStateWeiner latentStateWeiner,
  305.         final int terminalDate)
  306.     {
  307.         org.drip.exposure.evolver.PrimarySecurity clientFundingReplicator =
  308.             _primarySecurityDynamicsContainer.clientFunding();

  309.         try
  310.         {
  311.             return clientFundingReplicator.evolver().vertexSequenceReverse (
  312.                 new org.drip.measure.realization.JumpDiffusionVertex (
  313.                     terminalDate,
  314.                     initialMarketVertex.client().seniorFundingReplicator(),
  315.                     0.,
  316.                     false
  317.                 ),
  318.                 org.drip.measure.realization.JumpDiffusionEdgeUnit.Diffusion (
  319.                     _ycfWidth,
  320.                     latentStateWeiner.incrementArray (clientFundingReplicator.label())
  321.                 ),
  322.                 _ycfWidth
  323.             );
  324.         }
  325.         catch (java.lang.Exception e)
  326.         {
  327.             e.printStackTrace();
  328.         }

  329.         return null;
  330.     }

  331.     private org.drip.measure.realization.JumpDiffusionVertex[] dealerHazardVertexArray (
  332.         final org.drip.exposure.universe.MarketVertex initialMarketVertex,
  333.         final org.drip.exposure.universe.LatentStateWeiner latentStateWeiner,
  334.         final int terminalDate)
  335.     {
  336.         try
  337.         {
  338.             return _entityDynamicsContainer.dealerHazardRateEvolver().vertexSequence (
  339.                 new org.drip.measure.realization.JumpDiffusionVertex (
  340.                     terminalDate,
  341.                     initialMarketVertex.dealer().hazardRate(),
  342.                     0.,
  343.                     false
  344.                 ),
  345.                 org.drip.measure.realization.JumpDiffusionEdgeUnit.Diffusion (
  346.                     _ycfWidth,
  347.                     latentStateWeiner.incrementArray (_entityDynamicsContainer.dealerHazardLabel())
  348.                 ),
  349.                 _ycfWidth
  350.             );
  351.         }
  352.         catch (java.lang.Exception e)
  353.         {
  354.             e.printStackTrace();
  355.         }

  356.         return null;
  357.     }

  358.     private org.drip.measure.realization.JumpDiffusionVertex[] clientHazardVertexArray (
  359.         final org.drip.exposure.universe.MarketVertex initialMarketVertex,
  360.         final org.drip.exposure.universe.LatentStateWeiner latentStateWeiner,
  361.         final int terminalDate)
  362.     {
  363.         try
  364.         {
  365.             return _entityDynamicsContainer.clientHazardRateEvolver().vertexSequence (
  366.                 new org.drip.measure.realization.JumpDiffusionVertex (
  367.                     terminalDate,
  368.                     initialMarketVertex.client().hazardRate(),
  369.                     0.,
  370.                     false
  371.                 ),
  372.                 org.drip.measure.realization.JumpDiffusionEdgeUnit.Diffusion (
  373.                     _ycfWidth,
  374.                     latentStateWeiner.incrementArray (_entityDynamicsContainer.clientHazardLabel())
  375.                 ),
  376.                 _ycfWidth
  377.             );
  378.         }
  379.         catch (java.lang.Exception e)
  380.         {
  381.             e.printStackTrace();
  382.         }

  383.         return null;
  384.     }

  385.     private org.drip.measure.realization.JumpDiffusionVertex[] dealerSeniorRecoveryVertexArray (
  386.         final org.drip.exposure.universe.MarketVertex initialMarketVertex,
  387.         final org.drip.exposure.universe.LatentStateWeiner latentStateWeiner,
  388.         final int terminalDate)
  389.     {
  390.         try
  391.         {
  392.             return _entityDynamicsContainer.dealerSeniorRecoveryRateEvolver().vertexSequence (
  393.                 new org.drip.measure.realization.JumpDiffusionVertex (
  394.                     terminalDate,
  395.                     initialMarketVertex.dealer().seniorRecoveryRate(),
  396.                     0.,
  397.                     false
  398.                 ),
  399.                 org.drip.measure.realization.JumpDiffusionEdgeUnit.Diffusion (
  400.                     _ycfWidth,
  401.                     latentStateWeiner.incrementArray (_entityDynamicsContainer.dealerSeniorRecoveryLabel())
  402.                 ),
  403.                 _ycfWidth
  404.             );
  405.         }
  406.         catch (java.lang.Exception e)
  407.         {
  408.             e.printStackTrace();
  409.         }

  410.         return null;
  411.     }

  412.     private org.drip.measure.realization.JumpDiffusionVertex[] dealerSubordinateRecoveryVertexArray (
  413.         final org.drip.exposure.universe.MarketVertex initialMarketVertex,
  414.         final org.drip.exposure.universe.LatentStateWeiner latentStateWeiner,
  415.         final int terminalDate)
  416.     {
  417.         org.drip.measure.process.DiffusionEvolver dealerSubordinateRecoveryRateEvolver =
  418.             _entityDynamicsContainer.dealerSubordinateRecoveryRateEvolver();

  419.         if (null == dealerSubordinateRecoveryRateEvolver)
  420.         {
  421.             return null;
  422.         }

  423.         try
  424.         {
  425.             return dealerSubordinateRecoveryRateEvolver.vertexSequence (
  426.                 new org.drip.measure.realization.JumpDiffusionVertex (
  427.                     terminalDate,
  428.                     initialMarketVertex.dealer().subordinateRecoveryRate(),
  429.                     0.,
  430.                     false
  431.                 ),
  432.                 org.drip.measure.realization.JumpDiffusionEdgeUnit.Diffusion (
  433.                     _ycfWidth,
  434.                     latentStateWeiner.incrementArray
  435.                         (_entityDynamicsContainer.dealerSubordinateRecoveryLabel())
  436.                 ),
  437.                 _ycfWidth
  438.             );
  439.         }
  440.         catch (java.lang.Exception e)
  441.         {
  442.             e.printStackTrace();
  443.         }

  444.         return null;
  445.     }

  446.     private org.drip.measure.realization.JumpDiffusionVertex[] clientRecoveryVertexArray (
  447.         final org.drip.exposure.universe.MarketVertex initialMarketVertex,
  448.         final org.drip.exposure.universe.LatentStateWeiner latentStateWeiner,
  449.         final int terminalDate)
  450.     {
  451.         try
  452.         {
  453.             return _entityDynamicsContainer.clientRecoveryRateEvolver().vertexSequence (
  454.                 new org.drip.measure.realization.JumpDiffusionVertex (
  455.                     terminalDate,
  456.                     initialMarketVertex.client().seniorRecoveryRate(),
  457.                     0.,
  458.                     false
  459.                 ),
  460.                 org.drip.measure.realization.JumpDiffusionEdgeUnit.Diffusion (
  461.                     _ycfWidth,
  462.                     latentStateWeiner.incrementArray (_entityDynamicsContainer.clientRecoveryLabel())
  463.                 ),
  464.                 _ycfWidth
  465.             );
  466.         }
  467.         catch (java.lang.Exception e)
  468.         {
  469.             e.printStackTrace();
  470.         }

  471.         return null;
  472.     }

  473.     /**
  474.      * MarketVertexGenerator Constructor
  475.      *
  476.      * @param spotDate The Spot Date
  477.      * @param eventDateArray Array of the Event Dates
  478.      * @param entityDynamicsContainer The Dealer/Client Entity Latent State Dynamics Container
  479.      * @param primarySecurityDynamicsContainer The Primary Security Dynamics Container
  480.      * @param latentStateDynamicsContainer The Latent State Dynamics Container
  481.      *
  482.      * @throws java.lang.Exception Thrown if the Inputs are Invalid
  483.      */

  484.     public MarketVertexGenerator (
  485.         final int spotDate,
  486.         final int[] eventDateArray,
  487.         final org.drip.exposure.evolver.EntityDynamicsContainer entityDynamicsContainer,
  488.         final org.drip.exposure.evolver.PrimarySecurityDynamicsContainer primarySecurityDynamicsContainer,
  489.         final org.drip.exposure.evolver.LatentStateDynamicsContainer latentStateDynamicsContainer)
  490.         throws java.lang.Exception
  491.     {
  492.         if (0 >= (_spotDate = spotDate) ||
  493.             null == (_eventDateArray = eventDateArray) ||
  494.             null == (_entityDynamicsContainer = entityDynamicsContainer))
  495.         {
  496.             throw new java.lang.Exception ("MarketVertexGenerator Constructor => Invalid Inputs");
  497.         }

  498.         int eventVertexCount = _eventDateArray.length;
  499.         _latentStateDynamicsContainer = latentStateDynamicsContainer;
  500.         _primarySecurityDynamicsContainer = primarySecurityDynamicsContainer;
  501.         _ycfWidth = 0 == eventVertexCount ? null : new double[eventVertexCount];

  502.         if (0 == eventVertexCount ||
  503.             0. >= (_ycfWidth[0] = ((double) (_eventDateArray[0] - _spotDate)) / 365.25))
  504.         {
  505.             throw new java.lang.Exception ("MarketVertexGenerator Constructor => Invalid Inputs");
  506.         }

  507.         for (int eventVertexIndex = 1; eventVertexIndex < eventVertexCount; ++eventVertexIndex)
  508.         {
  509.             if (0. >= (_ycfWidth[eventVertexIndex] = ((double) (_eventDateArray[eventVertexIndex] -
  510.                 _eventDateArray[eventVertexIndex - 1])) / 365.25))
  511.             {
  512.                 throw new java.lang.Exception ("MarketVertexGenerator Constructor => Invalid Inputs");
  513.             }
  514.         }
  515.     }

  516.     /**
  517.      * Retrieve the Spot Date
  518.      *
  519.      * @return The Spot Date
  520.      */

  521.     public int spotDate()
  522.     {
  523.         return _spotDate;
  524.     }

  525.     /**
  526.      * Retrieve the Time Width Array
  527.      *
  528.      * @return The Time Width Array
  529.      */

  530.     public double[] timeWidth()
  531.     {
  532.         return _ycfWidth;
  533.     }

  534.     /**
  535.      * Retrieve the Entity Dynamics Container
  536.      *
  537.      * @return The Entity Dynamics Container
  538.      */

  539.     public org.drip.exposure.evolver.EntityDynamicsContainer entityDynamicsContainer()
  540.     {
  541.         return _entityDynamicsContainer;
  542.     }

  543.     /**
  544.      * Retrieve the Primary Security Dynamics Container
  545.      *
  546.      * @return The Primary Security Dynamics Container
  547.      */

  548.     public org.drip.exposure.evolver.PrimarySecurityDynamicsContainer primarySecurityDynamicsContainer()
  549.     {
  550.         return _primarySecurityDynamicsContainer;
  551.     }

  552.     /**
  553.      * Retrieve the Latent State Dynamics Container
  554.      *
  555.      * @return The Latent State Dynamics Container
  556.      */

  557.     public org.drip.exposure.evolver.LatentStateDynamicsContainer latentStateDynamicsContainer()
  558.     {
  559.         return _latentStateDynamicsContainer;
  560.     }

  561.     /**
  562.      * Retrieve the Vertex Date Array
  563.      *
  564.      * @return The Vertex Date Array
  565.      */

  566.     public int[] vertexDates()
  567.     {
  568.         int eventDateCount = _eventDateArray.length;
  569.         int[] vertexDateArray = new int[eventDateCount + 1];
  570.         vertexDateArray[0] = _spotDate;

  571.         for (int i = 0; i < eventDateCount; ++i)
  572.             vertexDateArray[i + 1] = _eventDateArray[i];

  573.         return vertexDateArray;
  574.     }

  575.     /**
  576.      * Generate the Trajectory of the Simulated Market Vertexes
  577.      *
  578.      * @param initialMarketVertex The Initial Market Vertex
  579.      * @param latentStateWeiner The Latent State Weiner Instance
  580.      *
  581.      * @return The Trajectory of the Simulated Market Vertexes
  582.      */

  583.     public java.util.Map<java.lang.Integer, org.drip.exposure.universe.MarketVertex> marketVertex (
  584.         final org.drip.exposure.universe.MarketVertex initialMarketVertex,
  585.         final org.drip.exposure.universe.LatentStateWeiner latentStateWeiner)
  586.     {
  587.         if (null == initialMarketVertex ||
  588.             null == latentStateWeiner)
  589.         {
  590.             return null;
  591.         }

  592.         int latentStateCount = latentStateWeiner.stateCount();

  593.         if (7 > latentStateCount)
  594.         {
  595.             return null;
  596.         }

  597.         org.drip.exposure.evolver.LatentStateVertexContainer latentStateVertexContainerInitial =
  598.             initialMarketVertex.latentStateVertexContainer();

  599.         java.util.List<org.drip.state.identifier.LatentStateLabel> latentStateLabelList = null ==
  600.             latentStateVertexContainerInitial ? null : latentStateVertexContainerInitial.labelList();

  601.         double clientSurvivalProbabilityExponent = 0.;
  602.         double dealerSurvivalProbabilityExponent = 0.;
  603.         int eventVertexCount = _eventDateArray.length;
  604.         int terminalDate = _eventDateArray[eventVertexCount - 1];

  605.         int latentStateLabelCount = null == latentStateLabelList ? 0 : latentStateLabelList.size();

  606.         org.drip.measure.realization.JumpDiffusionVertex[] overnightReplicatorVertexArray =
  607.             overnightReplicatorVertexArray (
  608.                 initialMarketVertex,
  609.                 latentStateWeiner,
  610.                 terminalDate
  611.             );

  612.         org.drip.measure.realization.JumpDiffusionVertex[] csaReplicatorVertexArray =
  613.             csaReplicatorVertexArray (
  614.                 initialMarketVertex,
  615.                 latentStateWeiner,
  616.                 terminalDate
  617.             );

  618.         org.drip.measure.realization.JumpDiffusionVertex[] dealerSeniorFundingReplicatorVertexArray =
  619.             dealerSeniorFundingReplicatorVertexArray (
  620.                 initialMarketVertex,
  621.                 latentStateWeiner,
  622.                 terminalDate
  623.             );

  624.         org.drip.measure.realization.JumpDiffusionVertex[] dealerSubordinateFundingReplicatorVertexArray =
  625.             dealerSubordinateFundingReplicatorVertexArray (
  626.                 initialMarketVertex,
  627.                 latentStateWeiner,
  628.                 terminalDate
  629.             );

  630.         org.drip.measure.realization.JumpDiffusionVertex[] clientFundingReplicatorVertexArray =
  631.             clientFundingReplicatorVertexArray (
  632.                 initialMarketVertex,
  633.                 latentStateWeiner,
  634.                 terminalDate
  635.             );

  636.         org.drip.measure.realization.JumpDiffusionVertex[] dealerHazardVertexArray =
  637.             dealerHazardVertexArray (
  638.                 initialMarketVertex,
  639.                 latentStateWeiner,
  640.                 terminalDate
  641.             );

  642.         org.drip.measure.realization.JumpDiffusionVertex[] clientHazardVertexArray =
  643.             clientHazardVertexArray (
  644.                 initialMarketVertex,
  645.                 latentStateWeiner,
  646.                 terminalDate
  647.             );

  648.         org.drip.measure.realization.JumpDiffusionVertex[] dealerSeniorRecoveryVertexArray =
  649.             dealerSeniorRecoveryVertexArray (
  650.                 initialMarketVertex,
  651.                 latentStateWeiner,
  652.                 terminalDate
  653.             );

  654.         org.drip.measure.realization.JumpDiffusionVertex[] dealerSubordinateRecoveryVertexArray =
  655.             dealerSubordinateRecoveryVertexArray (
  656.                 initialMarketVertex,
  657.                 latentStateWeiner,
  658.                 terminalDate
  659.             );

  660.         org.drip.measure.realization.JumpDiffusionVertex[] clientRecoveryVertexArray =
  661.             clientRecoveryVertexArray (
  662.                 initialMarketVertex,
  663.                 latentStateWeiner,
  664.                 terminalDate
  665.             );

  666.         java.util.List<org.drip.measure.realization.JumpDiffusionVertex[]> latentStateVertexArrayList =
  667.             latentStateVertexArrayList (
  668.                 latentStateLabelList,
  669.                 initialMarketVertex,
  670.                 latentStateWeiner,
  671.                 terminalDate
  672.             );

  673.         if (null == overnightReplicatorVertexArray ||
  674.             null == csaReplicatorVertexArray ||
  675.             null == dealerSeniorFundingReplicatorVertexArray ||
  676.             null == clientFundingReplicatorVertexArray ||
  677.             null == dealerHazardVertexArray ||
  678.             null == clientHazardVertexArray ||
  679.             null == dealerSeniorRecoveryVertexArray ||
  680.             null == clientRecoveryVertexArray)
  681.         {
  682.             return null;
  683.         }

  684.         double initialCSAReplicator = csaReplicatorVertexArray[0].value();

  685.         double initialOvernightReplicator = overnightReplicatorVertexArray[0].value();

  686.         double initialDealerSeniorFundingReplicator = dealerSeniorFundingReplicatorVertexArray[0].value();

  687.         double initialDealerSubordinateFundingReplicator =
  688.             null == dealerSubordinateFundingReplicatorVertexArray ||
  689.             null == dealerSubordinateFundingReplicatorVertexArray[0] ?
  690.             java.lang.Double.NaN : dealerSubordinateFundingReplicatorVertexArray[0].value();

  691.         double initialClientFundingReplicator = clientFundingReplicatorVertexArray[0].value();

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

  694.         for (int eventVertexIndex = 1; eventVertexIndex <= eventVertexCount; ++eventVertexIndex)
  695.         {
  696.             double clientHazardRate = clientHazardVertexArray[eventVertexIndex].value();

  697.             double dealerHazardRate = dealerHazardVertexArray[eventVertexIndex].value();

  698.             double csaReplicatorFinish =  csaReplicatorVertexArray[eventVertexIndex].value();

  699.             double overnightReplicatorFinish = overnightReplicatorVertexArray[eventVertexIndex].value();

  700.             double clientFundingReplicatorFinish =
  701.                 clientFundingReplicatorVertexArray[eventVertexIndex].value();

  702.             double dealerSeniorFundingReplicatorFinish =
  703.                 dealerSeniorFundingReplicatorVertexArray[eventVertexIndex].value();

  704.             double timeWidth = _ycfWidth[eventVertexIndex - 1];
  705.             double timeWidthReciprocal = 1. / timeWidth;
  706.             clientSurvivalProbabilityExponent += clientHazardRate * timeWidth;
  707.             dealerSurvivalProbabilityExponent += dealerHazardRate * timeWidth;

  708.             double overnightRate = timeWidthReciprocal * java.lang.Math.log (overnightReplicatorFinish /
  709.                 initialOvernightReplicator);

  710.             double dealerSubordinateFundingReplicatorFinish =
  711.                 null == dealerSubordinateFundingReplicatorVertexArray ||
  712.                 null == dealerSubordinateFundingReplicatorVertexArray[eventVertexIndex] ?
  713.                 java.lang.Double.NaN :
  714.                 dealerSubordinateFundingReplicatorVertexArray[eventVertexIndex].value();

  715.             try
  716.             {
  717.                 org.drip.exposure.universe.MarketVertexEntity dealerMarketVertex =
  718.                     new org.drip.exposure.universe.MarketVertexEntity (
  719.                         java.lang.Math.exp (-1. * dealerSurvivalProbabilityExponent),
  720.                         dealerHazardRate,
  721.                         dealerSeniorRecoveryVertexArray[eventVertexIndex].value(),
  722.                         timeWidthReciprocal * java.lang.Math.log (dealerSeniorFundingReplicatorFinish /
  723.                             initialDealerSeniorFundingReplicator) - overnightRate,
  724.                         dealerSeniorFundingReplicatorFinish,
  725.                         null == dealerSubordinateFundingReplicatorVertexArray ||
  726.                         null == dealerSubordinateRecoveryVertexArray[eventVertexIndex] ? java.lang.Double.NaN
  727.                             : dealerSubordinateRecoveryVertexArray[eventVertexIndex].value(),
  728.                         null == dealerSubordinateFundingReplicatorVertexArray ? java.lang.Double.NaN :
  729.                             timeWidthReciprocal *
  730.                             java.lang.Math.log (dealerSubordinateFundingReplicatorFinish /
  731.                                 initialDealerSubordinateFundingReplicator) - overnightRate,
  732.                         dealerSubordinateFundingReplicatorFinish
  733.                     );

  734.                 org.drip.exposure.universe.MarketVertexEntity clientMarketVertex =
  735.                     new org.drip.exposure.universe.MarketVertexEntity (
  736.                         java.lang.Math.exp (-1. * clientSurvivalProbabilityExponent),
  737.                         clientHazardRate,
  738.                         clientRecoveryVertexArray[eventVertexIndex].value(),
  739.                         timeWidthReciprocal * java.lang.Math.log (clientFundingReplicatorFinish /
  740.                             initialClientFundingReplicator) - overnightRate,
  741.                         clientFundingReplicatorFinish,
  742.                         java.lang.Double.NaN,
  743.                         java.lang.Double.NaN,
  744.                         java.lang.Double.NaN
  745.                     );

  746.                 org.drip.exposure.evolver.LatentStateVertexContainer latentStateVertexContainer = new
  747.                     org.drip.exposure.evolver.LatentStateVertexContainer();

  748.                 if (null != latentStateVertexArrayList && null != latentStateLabelList)
  749.                 {
  750.                     for (int latentStateLabelIndex = 0; latentStateLabelIndex < latentStateLabelCount;
  751.                         ++latentStateLabelIndex)
  752.                     {
  753.                         org.drip.state.identifier.LatentStateLabel latentStateLabel =
  754.                             latentStateLabelList.get (latentStateLabelIndex);

  755.                         if (null != latentStateLabel)
  756.                         {
  757.                             latentStateVertexContainer.addLatentStateValue (
  758.                                 latentStateLabel,
  759.                                 latentStateVertexArrayList.get
  760.                                     (latentStateLabelIndex)[eventVertexIndex].value()
  761.                             );
  762.                         }
  763.                     }
  764.                 }

  765.                 org.drip.exposure.universe.MarketVertex marketVertex =
  766.                     new org.drip.exposure.universe.MarketVertex (
  767.                         new org.drip.analytics.date.JulianDate (_eventDateArray[eventVertexIndex - 1]),
  768.                         overnightRate,
  769.                         overnightReplicatorFinish,
  770.                         timeWidthReciprocal * java.lang.Math.log (csaReplicatorFinish / initialCSAReplicator)
  771.                             - overnightRate,
  772.                         csaReplicatorFinish,
  773.                         dealerMarketVertex,
  774.                         clientMarketVertex,
  775.                         latentStateVertexContainer
  776.                     );

  777.                 marketVertexTrajectory.put (
  778.                     _eventDateArray[eventVertexIndex - 1],
  779.                     marketVertex
  780.                 );
  781.             }
  782.             catch (java.lang.Exception e)
  783.             {
  784.                 e.printStackTrace();

  785.                 return null;
  786.             }

  787.             initialCSAReplicator = csaReplicatorFinish;
  788.             initialOvernightReplicator = overnightReplicatorFinish;
  789.             initialClientFundingReplicator = clientFundingReplicatorFinish;
  790.             initialDealerSeniorFundingReplicator = dealerSeniorFundingReplicatorFinish;
  791.             initialDealerSubordinateFundingReplicator = dealerSubordinateFundingReplicatorFinish;
  792.         }

  793.         try
  794.         {
  795.             double clientHazardVertexEpochal = clientHazardVertexArray[0].value();

  796.             double dealerHazardVertexEpochal = dealerHazardVertexArray[0].value();

  797.             marketVertexTrajectory.put (
  798.                 initialMarketVertex.anchorDate().julian(),
  799.                 new org.drip.exposure.universe.MarketVertex (
  800.                     new org.drip.analytics.date.JulianDate (_spotDate),
  801.                     0.,
  802.                     overnightReplicatorVertexArray[0].value(),
  803.                     0.,
  804.                     csaReplicatorVertexArray[0].value(),
  805.                     new org.drip.exposure.universe.MarketVertexEntity (
  806.                         java.lang.Math.exp (-1. * _ycfWidth[0] * dealerHazardVertexEpochal),
  807.                         dealerHazardVertexEpochal,
  808.                         dealerSeniorRecoveryVertexArray[0].value(),
  809.                         initialMarketVertex.dealer().seniorFundingSpread(),
  810.                         dealerSeniorFundingReplicatorVertexArray[0].value(),
  811.                         null == dealerSubordinateFundingReplicatorVertexArray ||
  812.                         null == dealerSubordinateRecoveryVertexArray[0] ? java.lang.Double.NaN :
  813.                             dealerSubordinateRecoveryVertexArray[0].value(),
  814.                         null == dealerSubordinateFundingReplicatorVertexArray ? java.lang.Double.NaN :
  815.                             initialMarketVertex.dealer().subordinateFundingSpread(),
  816.                         null == dealerSubordinateFundingReplicatorVertexArray ||
  817.                             null == dealerSubordinateFundingReplicatorVertexArray[0] ?
  818.                             java.lang.Double.NaN :
  819.                             dealerSubordinateFundingReplicatorVertexArray[0].value()
  820.                     ),
  821.                     new org.drip.exposure.universe.MarketVertexEntity (
  822.                         java.lang.Math.exp (-1. * _ycfWidth[0] * clientHazardVertexEpochal),
  823.                         clientHazardVertexEpochal,
  824.                         clientRecoveryVertexArray[0].value(),
  825.                         initialMarketVertex.client().seniorFundingSpread(),
  826.                         clientFundingReplicatorVertexArray[0].value(),
  827.                         java.lang.Double.NaN,
  828.                         java.lang.Double.NaN,
  829.                         java.lang.Double.NaN
  830.                     ),
  831.                     initialMarketVertex.latentStateVertexContainer()
  832.                 )
  833.             );
  834.         }
  835.         catch (java.lang.Exception e)
  836.         {
  837.             e.printStackTrace();

  838.             return null;
  839.         }

  840.         return marketVertexTrajectory;
  841.     }
  842. }