CreditDebtGroupPath.java

  1. package org.drip.xva.netting;

  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>CreditDebtGroupPath</i> rolls up the Path Realizations of the Sequence in a Single Path Projection Run
  78.  * over Multiple Collateral Hypothecation Groups onto a Single Credit/Debt Netting Group - the Purpose being
  79.  * to calculate Credit Valuation Adjustments. The References are:
  80.  *
  81.  *  <br><br>
  82.  *  <ul>
  83.  *      <li>
  84.  *          Burgard, C., and M. Kjaer (2014): PDE Representations of Derivatives with Bilateral Counter-party
  85.  *              Risk and Funding Costs <i>Journal of Credit Risk</i> <b>7 (3)</b> 1-19
  86.  *      </li>
  87.  *      <li>
  88.  *          Burgard, C., and M. Kjaer (2014): In the Balance <i>Risk</i> <b>24 (11)</b> 72-75
  89.  *      </li>
  90.  *      <li>
  91.  *          Gregory, J. (2009): Being Two-faced over Counter-party Credit Risk <i>Risk</i> <b>20 (2)</b>
  92.  *              86-90
  93.  *      </li>
  94.  *      <li>
  95.  *          Li, B., and Y. Tang (2007): <i>Quantitative Analysis, Derivatives Modeling, and Trading
  96.  *              Strategies in the Presence of Counter-party Credit Risk for the Fixed Income Market</i>
  97.  *              <b>World Scientific Publishing</b> Singapore
  98.  *      </li>
  99.  *      <li>
  100.  *          Piterbarg, V. (2010): Funding Beyond Discounting: Collateral Agreements and Derivatives Pricing
  101.  *              <i>Risk</i> <b>21 (2)</b> 97-102
  102.  *      </li>
  103.  *  </ul>
  104.  *
  105.  *  <br><br>
  106.  *  <ul>
  107.  *      <li><b>Module </b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/PortfolioCore.md">Portfolio Core Module</a></li>
  108.  *      <li><b>Library</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/XVAAnalyticsLibrary.md">XVA Analytics Library</a></li>
  109.  *      <li><b>Project</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/xva/README.md">Valuation Adjustments that account for Collateral, CC Credit/Debt and Funding Overhead</a></li>
  110.  *      <li><b>Package</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/xva/netting/README.md">Credit/Debt/Funding Netting Groups</a></li>
  111.  *  </ul>
  112.  * <br><br>
  113.  *
  114.  * @author Lakshmi Krishnamurthy
  115.  */

  116. public abstract class CreditDebtGroupPath
  117. {
  118.     private org.drip.exposure.universe.MarketPath _marketPath = null;
  119.     private org.drip.xva.netting.CollateralGroupPath[] _collateralGroupPathArray = null;

  120.     protected CreditDebtGroupPath (
  121.         final org.drip.xva.netting.CollateralGroupPath[] collateralGroupPathArray,
  122.         final org.drip.exposure.universe.MarketPath marketPath)
  123.         throws java.lang.Exception
  124.     {
  125.         if (null == (_collateralGroupPathArray = collateralGroupPathArray) ||
  126.             null == (_marketPath = marketPath))
  127.         {
  128.             throw new java.lang.Exception ("CreditDebtGroupPath Constructor => Invalid Inputs");
  129.         }

  130.         int collateralGroupCount = _collateralGroupPathArray.length;

  131.         if (0 == collateralGroupCount)
  132.         {
  133.             throw new java.lang.Exception ("CreditDebtGroupPath Constructor => Invalid Inputs");
  134.         }

  135.         for (int collateralGroupIndex = 0; collateralGroupIndex < collateralGroupCount;
  136.             ++collateralGroupIndex)
  137.         {
  138.             if (null == _collateralGroupPathArray[collateralGroupIndex])
  139.             {
  140.                 throw new java.lang.Exception ("CreditDebtGroupPath Constructor => Invalid Inputs");
  141.             }
  142.         }
  143.     }

  144.     /**
  145.      * Retrieve the Array of the Position Hypothecation Group Trajectory Paths
  146.      *
  147.      * @return Array of the Position Hypothecation Group Trajectory Paths
  148.      */

  149.     public org.drip.xva.netting.CollateralGroupPath[] collateralGroupPaths()
  150.     {
  151.         return _collateralGroupPathArray;
  152.     }

  153.     /**
  154.      * Retrieve the Market Path
  155.      *
  156.      * @return The Market Path
  157.      */

  158.     public org.drip.exposure.universe.MarketPath marketPath()
  159.     {
  160.         return _marketPath;
  161.     }

  162.     /**
  163.      * Retrieve the Array of the Vertex Anchor Dates
  164.      *
  165.      * @return The Array of the Vertex Anchor Dates
  166.      */

  167.     public org.drip.analytics.date.JulianDate[] vertexDates()
  168.     {
  169.         return _collateralGroupPathArray[0].vertexDates();
  170.     }

  171.     /**
  172.      * Retrieve the Array of Vertex Collateralized Exposures
  173.      *
  174.      * @return The Array of Vertex Collateralized Exposures
  175.      */

  176.     public double[] vertexCollateralizedExposure()
  177.     {
  178.         int vertexCount = vertexDates().length;

  179.         int collateralGroupCount = _collateralGroupPathArray.length;
  180.         double[] vertexCollateralizedExposure = new double[vertexCount];

  181.         for (int vertexIndex = 0; vertexIndex < vertexCount; ++vertexIndex)
  182.         {
  183.             vertexCollateralizedExposure[vertexIndex] = 0.;
  184.         }

  185.         for (int collateralGroupIndex = 0; collateralGroupIndex < collateralGroupCount;
  186.             ++collateralGroupIndex)
  187.         {
  188.             double[] collateralGroupVertexCollateralizedExposure =
  189.                 _collateralGroupPathArray[collateralGroupIndex].vertexCollateralizedExposure();

  190.             for (int vertexIndex = 0; vertexIndex < vertexCount; ++vertexIndex)
  191.             {
  192.                 vertexCollateralizedExposure[vertexIndex] +=
  193.                     collateralGroupVertexCollateralizedExposure[vertexIndex];
  194.             }
  195.         }

  196.         return vertexCollateralizedExposure;
  197.     }

  198.     /**
  199.      * Retrieve the Array of Vertex Collateralized Exposure PV
  200.      *
  201.      * @return The Array of Vertex Collateralized Exposure PV
  202.      */

  203.     public double[] vertexCollateralizedExposurePV()
  204.     {
  205.         int vertexCount = vertexDates().length;

  206.         double[] vertexCollateralizedExposurePV = new double[vertexCount];
  207.         int collateralGroupCount = _collateralGroupPathArray.length;

  208.         for (int vertexIndex = 0; vertexIndex < vertexCount; ++vertexIndex)
  209.         {
  210.             vertexCollateralizedExposurePV[vertexIndex] = 0.;
  211.         }

  212.         for (int collateralGroupIndex = 0; collateralGroupIndex < collateralGroupCount;
  213.             ++collateralGroupIndex)
  214.         {
  215.             double[] collateralGroupVertexCollateralizedExposurePV =
  216.                 _collateralGroupPathArray[collateralGroupIndex].vertexCollateralizedExposurePV();

  217.             for (int vertexIndex = 0; vertexIndex < vertexCount; ++vertexIndex)
  218.             {
  219.                 vertexCollateralizedExposurePV[vertexIndex] +=
  220.                     collateralGroupVertexCollateralizedExposurePV[vertexIndex];
  221.             }
  222.         }

  223.         return vertexCollateralizedExposurePV;
  224.     }

  225.     /**
  226.      * Retrieve the Array of Vertex Collateralized Positive Exposures
  227.      *
  228.      * @return The Array of Vertex Collateralized Positive Exposures
  229.      */

  230.     public double[] vertexCollateralizedPositiveExposure()
  231.     {
  232.         double[] vertexCollateralizedPositiveExposure = vertexCollateralizedExposure();

  233.         int vertexCount = vertexCollateralizedPositiveExposure.length;

  234.         for (int vertexIndex = 0; vertexIndex < vertexCount; ++vertexIndex)
  235.         {
  236.             if (0. > vertexCollateralizedPositiveExposure[vertexIndex])
  237.                 vertexCollateralizedPositiveExposure[vertexIndex] = 0.;
  238.         }

  239.         return vertexCollateralizedPositiveExposure;
  240.     }

  241.     /**
  242.      * Retrieve the Array of Vertex Collateralized Positive Exposure PV
  243.      *
  244.      * @return The Array of Vertex Collateralized Positive Exposures PV
  245.      */

  246.     public double[] vertexCollateralizedPositiveExposurePV()
  247.     {
  248.         double[] vertexCollateralizedPositiveExposurePV = vertexCollateralizedExposurePV();

  249.         int vertexCount = vertexCollateralizedPositiveExposurePV.length;

  250.         for (int vertexIndex = 0; vertexIndex < vertexCount; ++vertexIndex)
  251.         {
  252.             if (0. > vertexCollateralizedPositiveExposurePV[vertexIndex])
  253.                 vertexCollateralizedPositiveExposurePV[vertexIndex] = 0.;
  254.         }

  255.         return vertexCollateralizedPositiveExposurePV;
  256.     }

  257.     /**
  258.      * Retrieve the Array of Vertex Collateralized Negative Exposures
  259.      *
  260.      * @return The Array of Vertex Collateralized Negative Exposures
  261.      */

  262.     public double[] vertexCollateralizedNegativeExposure()
  263.     {
  264.         double[] vertexCollateralizedNegativeExposure = vertexCollateralizedExposure();

  265.         int vertexCount = vertexCollateralizedNegativeExposure.length;

  266.         for (int vertexIndex = 0; vertexIndex < vertexCount; ++vertexIndex)
  267.         {
  268.             if (0. < vertexCollateralizedNegativeExposure[vertexIndex])
  269.                 vertexCollateralizedNegativeExposure[vertexIndex] = 0.;
  270.         }

  271.         return vertexCollateralizedNegativeExposure;
  272.     }

  273.     /**
  274.      * Retrieve the Array of Vertex Collateralized Negative Exposure PV
  275.      *
  276.      * @return The Array of Vertex Collateralized Negative Exposure PV
  277.      */

  278.     public double[] vertexCollateralizedNegativeExposurePV()
  279.     {
  280.         double[] vertexCollateralizedNegativeExposurePV = vertexCollateralizedExposurePV();

  281.         int vertexCount = vertexCollateralizedNegativeExposurePV.length;

  282.         for (int vertexIndex = 0; vertexIndex < vertexCount; ++vertexIndex)
  283.         {
  284.             if (0. < vertexCollateralizedNegativeExposurePV[vertexIndex])
  285.                 vertexCollateralizedNegativeExposurePV[vertexIndex] = 0.;
  286.         }

  287.         return vertexCollateralizedNegativeExposurePV;
  288.     }

  289.     /**
  290.      * Retrieve the Array of Vertex Uncollateralized Exposures
  291.      *
  292.      * @return The Array of Vertex Uncollateralized Exposures
  293.      */

  294.     public double[] vertexUncollateralizedExposure()
  295.     {
  296.         int vertexCount = vertexDates().length;

  297.         int collateralGroupCount = _collateralGroupPathArray.length;
  298.         double[] vertexUncollateralizedExposure = new double[vertexCount];

  299.         for (int vertexIndex = 0; vertexIndex < vertexCount; ++vertexIndex)
  300.         {
  301.             vertexUncollateralizedExposure[vertexIndex] = 0.;
  302.         }

  303.         for (int collateralGroupIndex = 0; collateralGroupIndex < collateralGroupCount;
  304.             ++collateralGroupIndex)
  305.         {
  306.             double[] collateralGroupVertexUncollateralizedExposure =
  307.                 _collateralGroupPathArray[collateralGroupIndex].vertexUncollateralizedExposure();

  308.             for (int vertexIndex = 0; vertexIndex < vertexCount; ++vertexIndex)
  309.             {
  310.                 vertexUncollateralizedExposure[vertexIndex] +=
  311.                     collateralGroupVertexUncollateralizedExposure[vertexIndex];
  312.             }
  313.         }

  314.         return vertexUncollateralizedExposure;
  315.     }

  316.     /**
  317.      * Retrieve the Array of Vertex Uncollateralized Exposure PV
  318.      *
  319.      * @return The Array of Vertex Uncollateralized Exposure PV
  320.      */

  321.     public double[] vertexUncollateralizedExposurePV()
  322.     {
  323.         int vertexCount = vertexDates().length;

  324.         int collateralGroupCount = _collateralGroupPathArray.length;
  325.         double[] vertexUncollateralizedExposurePV = new double[vertexCount];

  326.         for (int vertexIndex = 0; vertexIndex < vertexCount; ++vertexIndex)
  327.         {
  328.             vertexUncollateralizedExposurePV[vertexIndex] = 0.;
  329.         }

  330.         for (int collateralGroupIndex = 0; collateralGroupIndex < collateralGroupCount;
  331.             ++collateralGroupIndex)
  332.         {
  333.             double[] collateralGroupVertexUncollateralizedExposurePV =
  334.                 _collateralGroupPathArray[collateralGroupIndex].vertexUncollateralizedExposurePV();

  335.             for (int vertexIndex = 0; vertexIndex < vertexCount; ++vertexIndex)
  336.             {
  337.                 vertexUncollateralizedExposurePV[vertexIndex] +=
  338.                     collateralGroupVertexUncollateralizedExposurePV[vertexIndex];
  339.             }
  340.         }

  341.         return vertexUncollateralizedExposurePV;
  342.     }

  343.     /**
  344.      * Retrieve the Array of Vertex Uncollateralized Positive Exposures
  345.      *
  346.      * @return The Array of Vertex Uncollateralized Positive Exposures
  347.      */

  348.     public double[] vertexUncollateralizedPositiveExposure()
  349.     {
  350.         double[] vertexUncollateralizedPositiveExposure = vertexUncollateralizedExposure();

  351.         int vertexCount = vertexUncollateralizedPositiveExposure.length;

  352.         for (int vertexIndex = 0; vertexIndex < vertexCount; ++vertexIndex)
  353.         {
  354.             if (0. > vertexUncollateralizedPositiveExposure[vertexIndex])
  355.                 vertexUncollateralizedPositiveExposure[vertexIndex] = 0.;
  356.         }

  357.         return vertexUncollateralizedPositiveExposure;
  358.     }

  359.     /**
  360.      * Retrieve the Array of Vertex Uncollateralized Positive Exposure PV
  361.      *
  362.      * @return The Array of Vertex Uncollateralized Positive Exposure PV
  363.      */

  364.     public double[] vertexUncollateralizedPositiveExposurePV()
  365.     {
  366.         double[] vertexUncollateralizedPositiveExposurePV = vertexUncollateralizedExposurePV();

  367.         int vertexCount = vertexUncollateralizedPositiveExposurePV.length;

  368.         for (int vertexIndex = 0; vertexIndex < vertexCount; ++vertexIndex)
  369.         {
  370.             if (0. > vertexUncollateralizedPositiveExposurePV[vertexIndex])
  371.                 vertexUncollateralizedPositiveExposurePV[vertexIndex] = 0.;
  372.         }

  373.         return vertexUncollateralizedPositiveExposurePV;
  374.     }

  375.     /**
  376.      * Retrieve the Array of Vertex Uncollateralized Negative Exposures
  377.      *
  378.      * @return The Array of Vertex Uncollateralized Negative Exposures
  379.      */

  380.     public double[] vertexUncollateralizedNegativeExposure()
  381.     {
  382.         double[] vertexUncollateralizedNegativeExposure = vertexUncollateralizedExposure();

  383.         int vertexCount = vertexUncollateralizedNegativeExposure.length;

  384.         for (int vertexIndex = 0; vertexIndex < vertexCount; ++vertexIndex)
  385.         {
  386.             if (0. < vertexUncollateralizedNegativeExposure[vertexIndex])
  387.                 vertexUncollateralizedNegativeExposure[vertexIndex] = 0.;
  388.         }

  389.         return vertexUncollateralizedNegativeExposure;
  390.     }

  391.     /**
  392.      * Retrieve the Array of Vertex Uncollateralized Negative Exposure PV
  393.      *
  394.      * @return The Array of Vertex Uncollateralized Negative Exposure PV
  395.      */

  396.     public double[] vertexUncollateralizedNegativeExposurePV()
  397.     {
  398.         double[] vertexUncollateralizedNegativeExposurePV = vertexUncollateralizedExposurePV();

  399.         int vertexCount = vertexUncollateralizedNegativeExposurePV.length;

  400.         for (int vertexIndex = 0; vertexIndex < vertexCount; ++vertexIndex)
  401.         {
  402.             if (0. < vertexUncollateralizedNegativeExposurePV[vertexIndex])
  403.                 vertexUncollateralizedNegativeExposurePV[vertexIndex] = 0.;
  404.         }

  405.         return vertexUncollateralizedNegativeExposurePV;
  406.     }

  407.     /**
  408.      * Retrieve the Array of Vertex Credit Exposure
  409.      *
  410.      * @return The Array of Vertex Credit Exposure
  411.      */

  412.     public double[] vertexCreditExposure()
  413.     {
  414.         return vertexCollateralizedPositiveExposure();
  415.     }

  416.     /**
  417.      * Retrieve the Array of Vertex Credit Exposure PV
  418.      *
  419.      * @return The Array of Vertex Credit Exposure PV
  420.      */

  421.     public double[] vertexCreditExposurePV()
  422.     {
  423.         return vertexCollateralizedPositiveExposurePV();
  424.     }

  425.     /**
  426.      * Retrieve the Array of Vertex Debt Exposure
  427.      *
  428.      * @return The Array of Vertex Debt Exposure
  429.      */

  430.     public double[] vertexDebtExposure()
  431.     {
  432.         return vertexCollateralizedNegativeExposure();
  433.     }

  434.     /**
  435.      * Retrieve the Array of Vertex Debt Exposure PV
  436.      *
  437.      * @return The Array of Vertex Debt Exposure PV
  438.      */

  439.     public double[] vertexDebtExposurePV()
  440.     {
  441.         return vertexCollateralizedNegativeExposurePV();
  442.     }

  443.     /**
  444.      * Retrieve the Array of Vertex Funding Exposure
  445.      *
  446.      * @return The Array of Vertex Funding Exposure
  447.      */

  448.     public double[] vertexFundingExposure()
  449.     {
  450.         return vertexCollateralizedExposure();
  451.     }

  452.     /**
  453.      * Retrieve the Array of Vertex Funding Exposure PV
  454.      *
  455.      * @return The Array of Vertex Funding Exposure PV
  456.      */

  457.     public double[] vertexFundingExposurePV()
  458.     {
  459.         return vertexCollateralizedExposurePV();
  460.     }

  461.     /**
  462.      * Retrieve the Array of Vertex Collateral Balances
  463.      *
  464.      * @return The Array of Vertex Collateral Balances
  465.      */

  466.     public double[] vertexCollateralBalance()
  467.     {
  468.         int vertexCount = vertexDates().length;

  469.         int collateralGroupCount = _collateralGroupPathArray.length;
  470.         double[] vertexCollateralBalance = new double[vertexCount];

  471.         for (int vertexIndex = 0; vertexIndex < vertexCount; ++vertexIndex)
  472.         {
  473.             vertexCollateralBalance[vertexIndex] = 0.;
  474.         }

  475.         for (int collateralGroupIndex = 0; collateralGroupIndex < collateralGroupCount;
  476.             ++collateralGroupIndex)
  477.         {
  478.             double[] collateralVertexGroupCollateralBalance =
  479.                 _collateralGroupPathArray[collateralGroupIndex].vertexCollateralBalance();

  480.             for (int vertexIndex = 0; vertexIndex < vertexCount; ++vertexIndex)
  481.             {
  482.                 vertexCollateralBalance[vertexIndex] += collateralVertexGroupCollateralBalance[vertexIndex];
  483.             }
  484.         }

  485.         return vertexCollateralBalance;
  486.     }

  487.     /**
  488.      * Retrieve the Array of Vertex Collateral Balances PV
  489.      *
  490.      * @return The Array of Vertex Collateral Balances PV
  491.      */

  492.     public double[] vertexCollateralBalancePV()
  493.     {
  494.         int vertexCount = vertexDates().length;

  495.         int collateralGroupCount = _collateralGroupPathArray.length;
  496.         double[] vertexCollateralBalancePV = new double[vertexCount];

  497.         for (int vertexIndex = 0; vertexIndex < vertexCount; ++vertexIndex)
  498.         {
  499.             vertexCollateralBalancePV[vertexIndex] = 0.;
  500.         }

  501.         for (int collateralGroupIndex = 0; collateralGroupIndex < collateralGroupCount;
  502.             ++collateralGroupIndex)
  503.         {
  504.             double[] collateralVertexGroupCollateralBalancePV =
  505.                 _collateralGroupPathArray[collateralGroupIndex].vertexCollateralBalancePV();

  506.             for (int vertexIndex = 0; vertexIndex < vertexCount; ++vertexIndex)
  507.             {
  508.                 vertexCollateralBalancePV[vertexIndex] +=
  509.                     collateralVertexGroupCollateralBalancePV[vertexIndex];
  510.             }
  511.         }

  512.         return vertexCollateralBalancePV;
  513.     }

  514.     /**
  515.      * Compute Period-wise Path Collateral Spread 01
  516.      *
  517.      * @return The Period-wise Path Collateral Spread 01
  518.      */

  519.     public double[] periodCollateralSpread01()
  520.     {
  521.         int vertexCount = vertexDates().length;

  522.         int periodCount = vertexCount - 1;
  523.         int collateralGroupCount = _collateralGroupPathArray.length;
  524.         double[] periodCollateralSpread01 = new double[periodCount];

  525.         for (int periodIndex = 0; periodIndex < periodCount; ++periodIndex)
  526.         {
  527.             periodCollateralSpread01[periodIndex] = 0.;
  528.         }

  529.         for (int collateralGroupIndex = 0; collateralGroupIndex < collateralGroupCount;
  530.             ++collateralGroupIndex)
  531.         {
  532.             double[] collateralPeriodCollateralSpread01 =
  533.                 _collateralGroupPathArray[collateralGroupIndex].periodCollateralSpread01();

  534.             for (int periodIndex = 0; periodIndex < periodCount; ++periodIndex)
  535.             {
  536.                 periodCollateralSpread01[periodIndex] += collateralPeriodCollateralSpread01[periodIndex];
  537.             }
  538.         }

  539.         return periodCollateralSpread01;
  540.     }

  541.     /**
  542.      * Compute Period-wise Path Collateral Value Adjustment
  543.      *
  544.      * @return The Period-wise Path Collateral Value Adjustment
  545.      */

  546.     public double[] periodCollateralValueAdjustment()
  547.     {
  548.         int vertexCount = vertexDates().length;

  549.         int periodCount = vertexCount - 1;
  550.         int collateralGroupCount = _collateralGroupPathArray.length;
  551.         double[] periodCollateralValueAdjustment = new double[periodCount];

  552.         for (int periodIndex = 0; periodIndex < periodCount; ++periodIndex)
  553.         {
  554.             periodCollateralValueAdjustment[periodIndex] = 0.;
  555.         }

  556.         for (int collateralGroupIndex = 0; collateralGroupIndex < collateralGroupCount;
  557.             ++collateralGroupIndex)
  558.         {
  559.             double[] collateralPeriodCollateralValueAdjustment =
  560.                 _collateralGroupPathArray[collateralGroupIndex].periodCollateralValueAdjustment();

  561.             for (int periodIndex = 0; periodIndex < periodCount; ++periodIndex)
  562.             {
  563.                 periodCollateralValueAdjustment[periodIndex] +=
  564.                     collateralPeriodCollateralValueAdjustment[periodIndex];
  565.             }
  566.         }

  567.         return periodCollateralValueAdjustment;
  568.     }

  569.     /**
  570.      * Compute Path Unilateral Credit Adjustment
  571.      *
  572.      * @return The Path Unilateral Credit Adjustment
  573.      */

  574.     public double unilateralCreditAdjustment()
  575.     {
  576.         org.drip.exposure.universe.MarketVertex[] marketVertexArray = _marketPath.marketVertexArray();

  577.         double[] vertexCreditExposurePV = vertexCreditExposurePV();

  578.         int vertexCount = vertexCreditExposurePV.length;
  579.         double unilateralCreditAdjustment = 0.;

  580.         for (int vertexIndex = 1; vertexIndex < vertexCount; ++vertexIndex)
  581.         {
  582.             double periodIntegrandStart = vertexCreditExposurePV[vertexIndex - 1] * (1. -
  583.                 marketVertexArray[vertexIndex - 1].client().seniorRecoveryRate());

  584.             double periodIntegrandEnd = vertexCreditExposurePV[vertexIndex] * (1. -
  585.                 marketVertexArray[vertexIndex].client().seniorRecoveryRate());

  586.             unilateralCreditAdjustment -= 0.5 * (periodIntegrandStart + periodIntegrandEnd) *
  587.                 (marketVertexArray[vertexIndex - 1].client().survivalProbability() -
  588.                     marketVertexArray[vertexIndex].client().survivalProbability());
  589.         }

  590.         return unilateralCreditAdjustment;
  591.     }

  592.     /**
  593.      * Compute Path Bilateral Credit Adjustment
  594.      *
  595.      * @return The Path Bilateral Credit Adjustment
  596.      */

  597.     public double bilateralCreditAdjustment()
  598.     {
  599.         org.drip.exposure.universe.MarketVertex[] marketVertexArray = _marketPath.marketVertexArray();

  600.         double[] vertexCreditExposurePV = vertexCreditExposurePV();

  601.         int vertexCount = vertexCreditExposurePV.length;
  602.         double bilateralCreditAdjustment = 0.;

  603.         for (int vertexIndex = 1; vertexIndex < vertexCount; ++vertexIndex)
  604.         {
  605.             double periodIntegrandStart = vertexCreditExposurePV[vertexIndex - 1] * (1. -
  606.                 marketVertexArray[vertexIndex - 1].client().seniorRecoveryRate()) *
  607.                 marketVertexArray[vertexIndex - 1].dealer().survivalProbability();

  608.             double periodIntegrandEnd = vertexCreditExposurePV[vertexIndex] * (1. -
  609.                 marketVertexArray[vertexIndex].client().seniorRecoveryRate()) *
  610.                 marketVertexArray[vertexIndex].dealer().survivalProbability();

  611.             bilateralCreditAdjustment -= 0.5 * (periodIntegrandStart + periodIntegrandEnd) *
  612.                 (marketVertexArray[vertexIndex - 1].client().survivalProbability() -
  613.                     marketVertexArray[vertexIndex].client().survivalProbability());
  614.         }

  615.         return bilateralCreditAdjustment;
  616.     }

  617.     /**
  618.      * Compute Path Contra-Liability Credit Adjustment
  619.      *
  620.      * @return The Path Contra-Liability Credit Adjustment
  621.      */

  622.     public double contraLiabilityCreditAdjustment()
  623.     {
  624.         return bilateralCreditAdjustment() - unilateralCreditAdjustment();
  625.     }

  626.     /**
  627.      * Compute Path Unilateral Debt Adjustment
  628.      *
  629.      * @return The Path Unilateral Debt Adjustment
  630.      */

  631.     public double unilateralDebtAdjustment()
  632.     {
  633.         org.drip.exposure.universe.MarketVertex[] marketVertexArray = _marketPath.marketVertexArray();

  634.         double[] vertexDebtExposurePV = vertexDebtExposurePV();

  635.         int vertexCount = vertexDebtExposurePV.length;
  636.         double unilateralDebtAdjustment = 0.;

  637.         for (int vertexIndex = 1; vertexIndex < vertexCount; ++vertexIndex)
  638.         {
  639.             double periodIntegrandStart = vertexDebtExposurePV[vertexIndex - 1] * (1. -
  640.                 marketVertexArray[vertexIndex - 1].dealer().seniorRecoveryRate());

  641.             double periodIntegrandEnd = vertexDebtExposurePV[vertexIndex] * (1. -
  642.                 marketVertexArray[vertexIndex].dealer().seniorRecoveryRate());

  643.             unilateralDebtAdjustment -= 0.5 * (periodIntegrandStart + periodIntegrandEnd) *
  644.                 (marketVertexArray[vertexIndex - 1].dealer().survivalProbability() -
  645.                     marketVertexArray[vertexIndex].dealer().survivalProbability());
  646.         }

  647.         return unilateralDebtAdjustment;
  648.     }

  649.     /**
  650.      * Compute Path Bilateral Debt Adjustment
  651.      *
  652.      * @return The Path Bilateral Debt Adjustment
  653.      */

  654.     public double bilateralDebtAdjustment()
  655.     {
  656.         org.drip.exposure.universe.MarketVertex[] marketVertexArray = _marketPath.marketVertexArray();

  657.         double[] vertexDebtExposurePV = vertexDebtExposurePV();

  658.         int vertexCount = vertexDebtExposurePV.length;
  659.         double bilateralDebtAdjustment = 0.;

  660.         for (int vertexIndex = 1; vertexIndex < vertexCount; ++vertexIndex)
  661.         {
  662.             double periodIntegrandStart = vertexDebtExposurePV[vertexIndex - 1] * (1. -
  663.                 marketVertexArray[vertexIndex - 1].dealer().seniorRecoveryRate()) *
  664.                 marketVertexArray[vertexIndex - 1].client().survivalProbability();

  665.             double periodIntegrandEnd = vertexDebtExposurePV[vertexIndex] * (1. -
  666.                 marketVertexArray[vertexIndex].dealer().seniorRecoveryRate()) *
  667.                 marketVertexArray[vertexIndex].client().survivalProbability();

  668.             bilateralDebtAdjustment -= 0.5 * (periodIntegrandStart + periodIntegrandEnd) *
  669.                 (marketVertexArray[vertexIndex - 1].dealer().survivalProbability() -
  670.                     marketVertexArray[vertexIndex].dealer().survivalProbability());
  671.         }

  672.         return bilateralDebtAdjustment;
  673.     }

  674.     /**
  675.      * Compute Path Contra-Asset Debt Adjustment
  676.      *
  677.      * @return The Path Contra-Asset Debt Adjustment
  678.      */

  679.     public double contraAssetDebtAdjustment()
  680.     {
  681.         return bilateralDebtAdjustment() - unilateralDebtAdjustment();
  682.     }

  683.     /**
  684.      * Compute Path Symmetric Funding Value Spread 01
  685.      *
  686.      * @return The Path Symmetric Funding Value Spread 01
  687.      */

  688.     public double symmetricFundingValueSpread01()
  689.     {
  690.         org.drip.exposure.universe.MarketVertex[] marketVertexArray = _marketPath.marketVertexArray();

  691.         double[] vertexCollateralizedExposurePV = vertexCollateralizedExposurePV();

  692.         int vertexCount = vertexCollateralizedExposurePV.length;
  693.         double symmetricFundingValueSpread01 = 0.;

  694.         for (int vertexIndex = 1; vertexIndex < vertexCount; ++vertexIndex)
  695.         {
  696.             symmetricFundingValueSpread01 = 0.5 * (
  697.                 vertexCollateralizedExposurePV[vertexIndex - 1] *
  698.                 marketVertexArray[vertexIndex - 1].dealer().survivalProbability() +
  699.                 vertexCollateralizedExposurePV[vertexIndex] *
  700.                 marketVertexArray[vertexIndex].dealer().survivalProbability()
  701.             ) * (
  702.                 marketVertexArray[vertexIndex].anchorDate().julian() -
  703.                 marketVertexArray[vertexIndex - 1].anchorDate().julian()
  704.             ) / 365.25;
  705.         }

  706.         return symmetricFundingValueSpread01;
  707.     }

  708.     /**
  709.      * Compute Path Unilateral Funding Value Spread 01
  710.      *
  711.      * @return The Path Unilateral Funding Value Spread 01
  712.      */

  713.     public double unilateralFundingValueSpread01()
  714.     {
  715.         org.drip.exposure.universe.MarketVertex[] marketVertexArray = _marketPath.marketVertexArray();

  716.         double[] vertexFundingExposurePV = vertexFundingExposurePV();

  717.         int vertexCount = vertexFundingExposurePV.length;
  718.         double unilateralFundingValueSpread01 = 0.;

  719.         for (int vertexIndex = 1; vertexIndex < vertexCount; ++vertexIndex)
  720.         {
  721.             double periodIntegrandStart = vertexFundingExposurePV[vertexIndex - 1] *
  722.                 marketVertexArray[vertexIndex - 1].client().survivalProbability();

  723.             double periodIntegrandEnd = vertexFundingExposurePV[vertexIndex] *
  724.                 marketVertexArray[vertexIndex].client().survivalProbability();

  725.             unilateralFundingValueSpread01 = 0.5 * (periodIntegrandStart + periodIntegrandEnd) * (
  726.                 marketVertexArray[vertexIndex].anchorDate().julian() -
  727.                 marketVertexArray[vertexIndex - 1].anchorDate().julian()
  728.             ) / 365.25;
  729.         }

  730.         return unilateralFundingValueSpread01;
  731.     }

  732.     /**
  733.      * Compute Path Bilateral Funding Value Spread 01
  734.      *
  735.      * @return The Path Bilateral Funding Value Spread 01
  736.      */

  737.     public double bilateralFundingValueSpread01()
  738.     {
  739.         org.drip.exposure.universe.MarketVertex[] marketVertexArray = _marketPath.marketVertexArray();

  740.         double[] vertexFundingExposurePV = vertexFundingExposurePV();

  741.         int vertexCount = vertexFundingExposurePV.length;
  742.         double bilateralFundingValueSpread01 = 0.;

  743.         for (int vertexIndex = 1; vertexIndex < vertexCount; ++vertexIndex)
  744.         {
  745.             double periodIntegrandStart = vertexFundingExposurePV[vertexIndex - 1] *
  746.                 marketVertexArray[vertexIndex - 1].client().survivalProbability() *
  747.                 marketVertexArray[vertexIndex - 1].dealer().survivalProbability();

  748.             double periodIntegrandEnd = vertexFundingExposurePV[vertexIndex] *
  749.                 marketVertexArray[vertexIndex].client().survivalProbability() *
  750.                 marketVertexArray[vertexIndex].dealer().survivalProbability();

  751.             bilateralFundingValueSpread01 = 0.5 * (periodIntegrandStart + periodIntegrandEnd) * (
  752.                 marketVertexArray[vertexIndex].anchorDate().julian() -
  753.                 marketVertexArray[vertexIndex - 1].anchorDate().julian()
  754.             ) / 365.25;
  755.         }

  756.         return bilateralFundingValueSpread01;
  757.     }

  758.     /**
  759.      * Compute Path Unilateral Funding Debt Adjustment
  760.      *
  761.      * @return The Path Unilateral Funding Debt Adjustment
  762.      */

  763.     public double unilateralFundingDebtAdjustment()
  764.     {
  765.         org.drip.exposure.universe.MarketVertex[] marketVertexArray = _marketPath.marketVertexArray();

  766.         double[] vertexDebtExposurePV = vertexDebtExposurePV();

  767.         int vertexCount = vertexDebtExposurePV.length;
  768.         double unilateralFundingDebtAdjustment = 0.;

  769.         for (int vertexIndex = 1; vertexIndex < vertexCount; ++vertexIndex)
  770.         {
  771.             double periodIntegrandStart = vertexDebtExposurePV[vertexIndex - 1] * (1. -
  772.                 marketVertexArray[vertexIndex - 1].dealer().seniorRecoveryRate());

  773.             double periodIntegrandEnd = vertexDebtExposurePV[vertexIndex] * (1. -
  774.                 marketVertexArray[vertexIndex].dealer().seniorRecoveryRate());

  775.             unilateralFundingDebtAdjustment -= 0.5 * (periodIntegrandStart + periodIntegrandEnd) *
  776.                 (marketVertexArray[vertexIndex - 1].dealer().survivalProbability() -
  777.                     marketVertexArray[vertexIndex].dealer().survivalProbability());
  778.         }

  779.         return unilateralFundingDebtAdjustment;
  780.     }

  781.     /**
  782.      * Compute Path Bilateral Funding Debt Adjustment
  783.      *
  784.      * @return The Path Bilateral Funding Debt Adjustment
  785.      */

  786.     public double bilateralFundingDebtAdjustment()
  787.     {
  788.         org.drip.exposure.universe.MarketVertex[] marketVertexArray = _marketPath.marketVertexArray();

  789.         double[] vertexDebtExposurePV = vertexDebtExposurePV();

  790.         int vertexCount = vertexDebtExposurePV.length;
  791.         double bilateralFundingDebtAdjustment = 0.;

  792.         for (int vertexIndex = 1; vertexIndex < vertexCount; ++vertexIndex)
  793.         {
  794.             double periodIntegrandStart = vertexDebtExposurePV[vertexIndex - 1] *
  795.                 marketVertexArray[vertexIndex - 1].client().survivalProbability() * (1. -
  796.                 marketVertexArray[vertexIndex - 1].dealer().seniorRecoveryRate());

  797.             double periodIntegrandEnd = vertexDebtExposurePV[vertexIndex] *
  798.                 marketVertexArray[vertexIndex].client().survivalProbability() * (1. -
  799.                 marketVertexArray[vertexIndex].dealer().seniorRecoveryRate());

  800.             bilateralFundingDebtAdjustment += 0.5 * (periodIntegrandStart + periodIntegrandEnd) *
  801.                 (marketVertexArray[vertexIndex - 1].dealer().survivalProbability() -
  802.                     marketVertexArray[vertexIndex].dealer().survivalProbability());
  803.         }

  804.         return bilateralFundingDebtAdjustment;
  805.     }

  806.     /**
  807.      * Compute Path Unilateral Collateral Value Adjustment
  808.      *
  809.      * @return The Path Unilateral Collateral Value Adjustment
  810.      */

  811.     public double unilateralCollateralAdjustment()
  812.     {
  813.         org.drip.exposure.universe.MarketVertex[] marketVertexArray = _marketPath.marketVertexArray();

  814.         double[] periodCollateralValueAdjustment = periodCollateralValueAdjustment();

  815.         double unilateralCollateralValueAdjustment = 0.;
  816.         int periodCount = periodCollateralValueAdjustment.length;

  817.         for (int periodIndex = 0; periodIndex < periodCount; ++periodIndex)
  818.         {
  819.             unilateralCollateralValueAdjustment += 0.5 * periodCollateralValueAdjustment[periodIndex] * (
  820.                 marketVertexArray[periodIndex].client().survivalProbability() +
  821.                 marketVertexArray[periodIndex + 1].client().survivalProbability()
  822.             );
  823.         }

  824.         return unilateralCollateralValueAdjustment;
  825.     }

  826.     /**
  827.      * Compute Path Bilateral Collateral Value Adjustment
  828.      *
  829.      * @return The Path Bilateral Collateral Value Adjustment
  830.      */

  831.     public double bilateralCollateralAdjustment()
  832.     {
  833.         org.drip.exposure.universe.MarketVertex[] marketVertexArray = _marketPath.marketVertexArray();

  834.         double[] periodCollateralValueAdjustment = periodCollateralValueAdjustment();

  835.         double bilateralCollateralValueAdjustment = 0.;
  836.         int periodCount = periodCollateralValueAdjustment.length;

  837.         for (int periodIndex = 0; periodIndex < periodCount; ++periodIndex)
  838.         {
  839.             bilateralCollateralValueAdjustment += 0.5 * periodCollateralValueAdjustment[periodIndex] * (
  840.                 marketVertexArray[periodIndex].dealer().survivalProbability() *
  841.                 marketVertexArray[periodIndex].client().survivalProbability() +
  842.                 marketVertexArray[periodIndex + 1].dealer().survivalProbability() *
  843.                 marketVertexArray[periodIndex + 1].client().survivalProbability()
  844.             );
  845.         }

  846.         return bilateralCollateralValueAdjustment;
  847.     }

  848.     /**
  849.      * Compute Path Collateral Value Adjustment
  850.      *
  851.      * @return The Path Collateral Value Adjustment
  852.      */

  853.     public double collateralValueAdjustment()
  854.     {
  855.         return unilateralCollateralAdjustment();
  856.     }

  857.     /**
  858.      * Compute Period-wise Symmetric Funding Value Spread 01
  859.      *
  860.      * @return The Period-wise Symmetric Funding Value Spread 01
  861.      */

  862.     public double[] periodSymmetricFundingValueSpread01()
  863.     {
  864.         org.drip.exposure.universe.MarketVertex[] marketVertexArray = _marketPath.marketVertexArray();

  865.         double[] vertexCollateralizedExposurePV = vertexCollateralizedExposurePV();

  866.         int periodCount = vertexCollateralizedExposurePV.length - 1;
  867.         double[] periodSymmetricFundingValueSpread01 = new double[periodCount];

  868.         for (int periodIndex = 0; periodIndex < periodCount; ++periodIndex)
  869.         {
  870.             periodSymmetricFundingValueSpread01[periodIndex] = -0.5 * (
  871.                 vertexCollateralizedExposurePV[periodIndex] +
  872.                 vertexCollateralizedExposurePV[periodIndex + 1]
  873.             ) * (
  874.                 marketVertexArray[periodIndex + 1].anchorDate().julian() -
  875.                 marketVertexArray[periodIndex].anchorDate().julian()
  876.             ) / 365.25;
  877.         }

  878.         return periodSymmetricFundingValueSpread01;
  879.     }

  880.     /**
  881.      * Compute Period-wise Unilateral Credit Adjustment
  882.      *
  883.      * @return The Period-wise Unilateral Credit Adjustment
  884.      */

  885.     public double[] periodUnilateralCreditAdjustment()
  886.     {
  887.         org.drip.exposure.universe.MarketVertex[] marketVertexArray = _marketPath.marketVertexArray();

  888.         double[] vertexCreditExposurePV = vertexCreditExposurePV();

  889.         int vertexCount = vertexCreditExposurePV.length;
  890.         double[] periodUnilateralCreditAdjustment = new double[vertexCount - 1];

  891.         for (int vertexIndex = 1; vertexIndex < vertexCount; ++vertexIndex)
  892.         {
  893.             double periodIntegrandStart = vertexCreditExposurePV[vertexIndex - 1] * (1. -
  894.                 marketVertexArray[vertexIndex - 1].client().seniorRecoveryRate());

  895.             double periodIntegrandEnd = vertexCreditExposurePV[vertexIndex] * (1. -
  896.                 marketVertexArray[vertexIndex].client().seniorRecoveryRate());

  897.             periodUnilateralCreditAdjustment[vertexIndex - 1] =
  898.                 -0.5 * (periodIntegrandStart + periodIntegrandEnd) *
  899.                 (marketVertexArray[vertexIndex - 1].client().survivalProbability() -
  900.                 marketVertexArray[vertexIndex].client().survivalProbability());
  901.         }

  902.         return periodUnilateralCreditAdjustment;
  903.     }

  904.     /**
  905.      * Compute Period-wise Bilateral Credit Adjustment
  906.      *
  907.      * @return The Period-wise Bilateral Credit Adjustment
  908.      */

  909.     public double[] periodBilateralCreditAdjustment()
  910.     {
  911.         org.drip.exposure.universe.MarketVertex[] marketVertexArray = _marketPath.marketVertexArray();

  912.         double[] vertexCreditExposurePV = vertexCreditExposurePV();

  913.         int vertexCount = vertexCreditExposurePV.length;
  914.         double[] periodBilateralCreditAdjustment = new double[vertexCount - 1];

  915.         for (int vertexIndex = 1; vertexIndex < vertexCount; ++vertexIndex)
  916.         {
  917.             double periodIntegrandStart = vertexCreditExposurePV[vertexIndex - 1] * (1. -
  918.                 marketVertexArray[vertexIndex - 1].client().seniorRecoveryRate()) *
  919.                 marketVertexArray[vertexIndex - 1].dealer().survivalProbability();

  920.             double periodIntegrandEnd = vertexCreditExposurePV[vertexIndex] * (1. -
  921.                 marketVertexArray[vertexIndex].client().seniorRecoveryRate()) *
  922.                 marketVertexArray[vertexIndex].dealer().survivalProbability();

  923.             periodBilateralCreditAdjustment[vertexIndex - 1] =
  924.                 -0.5 * (periodIntegrandStart + periodIntegrandEnd) *
  925.                 (marketVertexArray[vertexIndex - 1].client().survivalProbability() -
  926.                 marketVertexArray[vertexIndex].client().survivalProbability());
  927.         }

  928.         return periodBilateralCreditAdjustment;
  929.     }

  930.     /**
  931.      * Compute Period-wise Contra-Liability Credit Adjustment
  932.      *
  933.      * @return The Period-wise Contra-Liability Credit Adjustment
  934.      */

  935.     public double[] periodContraLiabilityCreditAdjustment()
  936.     {
  937.         double[] periodUnilateralCreditAdjustment = periodUnilateralCreditAdjustment();

  938.         double[] periodBilateralCreditAdjustment = periodBilateralCreditAdjustment();

  939.         int vertexCount = periodUnilateralCreditAdjustment.length;
  940.         double[] periodContraLiabilityCreditAdjustment = new double[vertexCount];

  941.         for (int vertexIndex = 0; vertexIndex < vertexCount; ++vertexIndex)
  942.         {
  943.             periodContraLiabilityCreditAdjustment[vertexIndex] =
  944.                 periodUnilateralCreditAdjustment[vertexIndex] -
  945.                 periodBilateralCreditAdjustment[vertexIndex];
  946.         }

  947.         return periodContraLiabilityCreditAdjustment;
  948.     }

  949.     /**
  950.      * Compute Period-wise Unilateral Debt Adjustment
  951.      *
  952.      * @return The Period-wise Unilateral Debt Adjustment
  953.      */

  954.     public double[] periodUnilateralDebtAdjustment()
  955.     {
  956.         org.drip.exposure.universe.MarketVertex[] marketVertexArray = _marketPath.marketVertexArray();

  957.         double[] vertexDebtExposurePV = vertexDebtExposurePV();

  958.         int vertexCount = vertexDebtExposurePV.length;
  959.         double[] periodUnilateralDebtAdjustment = new double[vertexCount - 1];

  960.         for (int vertexIndex = 1; vertexIndex < vertexCount; ++vertexIndex)
  961.         {
  962.             double periodIntegrandStart = vertexDebtExposurePV[vertexIndex - 1] * (1. -
  963.                 marketVertexArray[vertexIndex - 1].dealer().seniorRecoveryRate());

  964.             double periodIntegrandEnd = vertexDebtExposurePV[vertexIndex] * (1. -
  965.                 marketVertexArray[vertexIndex].dealer().seniorRecoveryRate());

  966.             periodUnilateralDebtAdjustment[vertexIndex - 1] =
  967.                 -0.5 * (periodIntegrandStart + periodIntegrandEnd) *
  968.                 (marketVertexArray[vertexIndex - 1].dealer().survivalProbability() -
  969.                 marketVertexArray[vertexIndex].dealer().survivalProbability());
  970.         }

  971.         return periodUnilateralDebtAdjustment;
  972.     }

  973.     /**
  974.      * Compute Period-wise Bilateral Debt Adjustment
  975.      *
  976.      * @return The Period-wise Bilateral Debt Adjustment
  977.      */

  978.     public double[] periodBilateralDebtAdjustment()
  979.     {
  980.         org.drip.exposure.universe.MarketVertex[] marketVertexArray = _marketPath.marketVertexArray();

  981.         double[] vertexDebtExposurePV = vertexDebtExposurePV();

  982.         int vertexCount = vertexDebtExposurePV.length;
  983.         double[] periodBilateralDebtAdjustment = new double[vertexCount - 1];

  984.         for (int vertexIndex = 1; vertexIndex < vertexCount; ++vertexIndex)
  985.         {
  986.             double periodIntegrandStart = vertexDebtExposurePV[vertexIndex - 1] * (1. -
  987.                 marketVertexArray[vertexIndex - 1].dealer().seniorRecoveryRate()) *
  988.                 marketVertexArray[vertexIndex - 1].client().survivalProbability();

  989.             double periodIntegrandEnd = vertexDebtExposurePV[vertexIndex] * (1. -
  990.                 marketVertexArray[vertexIndex].dealer().seniorRecoveryRate()) *
  991.                 marketVertexArray[vertexIndex].client().survivalProbability();

  992.             periodBilateralDebtAdjustment[vertexIndex - 1] =
  993.                 -0.5 * (periodIntegrandStart + periodIntegrandEnd) *
  994.                 (marketVertexArray[vertexIndex - 1].dealer().survivalProbability() -
  995.                 marketVertexArray[vertexIndex].dealer().survivalProbability());
  996.         }

  997.         return periodBilateralDebtAdjustment;
  998.     }

  999.     /**
  1000.      * Compute Period Unilateral Funding Value Spread 01
  1001.      *
  1002.      * @return The Period Unilateral Funding Value Spread 01
  1003.      */

  1004.     public double[] periodUnilateralFundingValueSpread01()
  1005.     {
  1006.         org.drip.exposure.universe.MarketVertex[] marketVertexArray = _marketPath.marketVertexArray();

  1007.         double[] vertexFundingExposurePV = vertexFundingExposurePV();

  1008.         int periodCount = vertexFundingExposurePV.length - 1;
  1009.         double[] periodUnilateralFundingValueSpread01 = new double[periodCount];

  1010.         for (int periodIndex = 0; periodIndex < periodCount; ++periodIndex)
  1011.         {
  1012.             double periodIntegrandStart = vertexFundingExposurePV[periodIndex] *
  1013.                 marketVertexArray[periodIndex].client().survivalProbability();

  1014.             double periodIntegrandEnd = vertexFundingExposurePV[periodIndex + 1] *
  1015.                 marketVertexArray[periodIndex + 1].client().survivalProbability();

  1016.             periodUnilateralFundingValueSpread01[periodIndex] =
  1017.                 0.5 * (periodIntegrandStart + periodIntegrandEnd) * (
  1018.                     marketVertexArray[periodIndex + 1].anchorDate().julian() -
  1019.                     marketVertexArray[periodIndex].anchorDate().julian()
  1020.                 ) / 365.25;
  1021.         }

  1022.         return periodUnilateralFundingValueSpread01;
  1023.     }

  1024.     /**
  1025.      * Compute Period Bilateral Funding Value Spread 01
  1026.      *
  1027.      * @return The Period Bilateral Funding Value Spread 01
  1028.      */

  1029.     public double[] periodBilateralFundingValueSpread01()
  1030.     {
  1031.         org.drip.exposure.universe.MarketVertex[] marketVertexArray = _marketPath.marketVertexArray();

  1032.         double[] vertexFundingExposurePV = vertexFundingExposurePV();

  1033.         int periodCount = vertexFundingExposurePV.length - 1;
  1034.         double[] periodBilateralFundingValueSpread01 = new double[periodCount];

  1035.         for (int periodIndex = 0; periodIndex < periodCount; ++periodIndex)
  1036.         {
  1037.             double periodIntegrandStart = vertexFundingExposurePV[periodIndex] *
  1038.                 marketVertexArray[periodIndex].client().survivalProbability() *
  1039.                 marketVertexArray[periodIndex].dealer().survivalProbability();

  1040.             double periodIntegrandEnd = vertexFundingExposurePV[periodIndex + 1] *
  1041.                 marketVertexArray[periodIndex + 1].client().survivalProbability() *
  1042.                 marketVertexArray[periodIndex + 1].dealer().survivalProbability();

  1043.             periodBilateralFundingValueSpread01[periodIndex] =
  1044.                 0.5 * (periodIntegrandStart + periodIntegrandEnd) * (
  1045.                     marketVertexArray[periodIndex + 1].anchorDate().julian() -
  1046.                     marketVertexArray[periodIndex].anchorDate().julian()
  1047.                 ) / 365.25;
  1048.         }

  1049.         return periodBilateralFundingValueSpread01;
  1050.     }

  1051.     /**
  1052.      * Compute Period Unilateral Funding Debt Adjustment
  1053.      *
  1054.      * @return The Period Unilateral Funding Debt Adjustment
  1055.      */

  1056.     public double[] periodUnilateralFundingDebtAdjustment()
  1057.     {
  1058.         org.drip.exposure.universe.MarketVertex[] marketVertexArray = _marketPath.marketVertexArray();

  1059.         double[] vertexDebtExposurePV = vertexDebtExposurePV();

  1060.         int vertexCount = vertexDebtExposurePV.length;
  1061.         double[] periodUnilateralFundingDebtAdjustment = new double[vertexCount - 1];

  1062.         for (int vertexIndex = 1; vertexIndex < vertexCount; ++vertexIndex)
  1063.         {
  1064.             double periodIntegrandStart = vertexDebtExposurePV[vertexIndex - 1] * (1. -
  1065.                 marketVertexArray[vertexIndex - 1].dealer().seniorRecoveryRate());

  1066.             double periodIntegrandEnd = vertexDebtExposurePV[vertexIndex] * (1. -
  1067.                 marketVertexArray[vertexIndex].dealer().seniorRecoveryRate());

  1068.             periodUnilateralFundingDebtAdjustment[vertexIndex - 1] = -0.5 *
  1069.                 (periodIntegrandStart + periodIntegrandEnd) *
  1070.                 (marketVertexArray[vertexIndex - 1].dealer().survivalProbability() -
  1071.                 marketVertexArray[vertexIndex].dealer().survivalProbability());
  1072.         }

  1073.         return periodUnilateralFundingDebtAdjustment;
  1074.     }

  1075.     /**
  1076.      * Compute Period Bilateral Funding Debt Adjustment
  1077.      *
  1078.      * @return The Period Bilateral Funding Debt Adjustment
  1079.      */

  1080.     public double[] periodBilateralFundingDebtAdjustment()
  1081.     {
  1082.         org.drip.exposure.universe.MarketVertex[] marketVertexArray = _marketPath.marketVertexArray();

  1083.         double[] vertexDebtExposurePV = vertexDebtExposurePV();

  1084.         int vertexCount = vertexDebtExposurePV.length;
  1085.         double[] periodBilateralFundingDebtAdjustment = new double[vertexCount - 1];

  1086.         for (int vertexIndex = 1; vertexIndex < vertexCount; ++vertexIndex)
  1087.         {
  1088.             double periodIntegrandStart = vertexDebtExposurePV[vertexIndex - 1] * (1. -
  1089.                 marketVertexArray[vertexIndex - 1].dealer().seniorRecoveryRate()) *
  1090.                 marketVertexArray[vertexIndex - 1].client().survivalProbability();

  1091.             double periodIntegrandEnd = vertexDebtExposurePV[vertexIndex] * (1. -
  1092.                 marketVertexArray[vertexIndex].dealer().seniorRecoveryRate()) *
  1093.                 marketVertexArray[vertexIndex].client().survivalProbability();

  1094.             periodBilateralFundingDebtAdjustment[vertexIndex - 1] = -0.5 *
  1095.                 (periodIntegrandStart + periodIntegrandEnd) *
  1096.                 (marketVertexArray[vertexIndex - 1].dealer().survivalProbability() -
  1097.                 marketVertexArray[vertexIndex].dealer().survivalProbability());
  1098.         }

  1099.         return periodBilateralFundingDebtAdjustment;
  1100.     }

  1101.     /**
  1102.      * Compute Path Credit Adjustment
  1103.      *
  1104.      * @return The Path Credit Adjustment
  1105.      */

  1106.     public abstract double creditAdjustment();

  1107.     /**
  1108.      * Compute Path Debt Adjustment
  1109.      *
  1110.      * @return The Path Debt Adjustment
  1111.      */

  1112.     public abstract double debtAdjustment();

  1113.     /**
  1114.      * Compute Period-wise Credit Adjustment
  1115.      *
  1116.      * @return The Period-wise Credit Adjustment
  1117.      */

  1118.     public abstract double[] periodCreditAdjustment();

  1119.     /**
  1120.      * Compute Period-wise Debt Adjustment
  1121.      *
  1122.      * @return The Period-wise Debt Adjustment
  1123.      */

  1124.     public abstract double[] periodDebtAdjustment();
  1125. }