CPGAUncollateralizedCorrelated.java

  1. package org.drip.sample.xvadigest;

  2. import org.drip.analytics.date.*;
  3. import org.drip.exposure.evolver.LatentStateVertexContainer;
  4. import org.drip.exposure.universe.*;
  5. import org.drip.measure.discrete.SequenceGenerator;
  6. import org.drip.measure.dynamics.*;
  7. import org.drip.measure.process.DiffusionEvolver;
  8. import org.drip.measure.realization.*;
  9. import org.drip.measure.statistics.UnivariateDiscreteThin;
  10. import org.drip.numerical.common.FormatUtil;
  11. import org.drip.numerical.linearalgebra.Matrix;
  12. import org.drip.service.env.EnvManager;
  13. import org.drip.state.identifier.OTCFixFloatLabel;
  14. import org.drip.xva.gross.*;
  15. import org.drip.xva.netting.CollateralGroupPath;
  16. import org.drip.xva.strategy.*;
  17. import org.drip.xva.vertex.AlbaneseAndersen;

  18. /*
  19.  * -*- mode: java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  20.  */

  21. /*!
  22.  * Copyright (C) 2018 Lakshmi Krishnamurthy
  23.  * Copyright (C) 2017 Lakshmi Krishnamurthy
  24.  *
  25.  *  This file is part of DRIP, a free-software/open-source library for buy/side financial/trading model
  26.  *      libraries targeting analysts and developers
  27.  *      https://lakshmidrip.github.io/DRIP/
  28.  *  
  29.  *  DRIP is composed of four main libraries:
  30.  *  
  31.  *  - DRIP Fixed Income - https://lakshmidrip.github.io/DRIP-Fixed-Income/
  32.  *  - DRIP Asset Allocation - https://lakshmidrip.github.io/DRIP-Asset-Allocation/
  33.  *  - DRIP Numerical Optimizer - https://lakshmidrip.github.io/DRIP-Numerical-Optimizer/
  34.  *  - DRIP Statistical Learning - https://lakshmidrip.github.io/DRIP-Statistical-Learning/
  35.  *
  36.  *  - DRIP Fixed Income: Library for Instrument/Trading Conventions, Treasury Futures/Options,
  37.  *      Funding/Forward/Overnight Curves, Multi-Curve Construction/Valuation, Collateral Valuation and XVA
  38.  *      Metric Generation, Calibration and Hedge Attributions, Statistical Curve Construction, Bond RV
  39.  *      Metrics, Stochastic Evolution and Option Pricing, Interest Rate Dynamics and Option Pricing, LMM
  40.  *      Extensions/Calibrations/Greeks, Algorithmic Differentiation, and Asset Backed Models and Analytics.
  41.  *
  42.  *  - DRIP Asset Allocation: Library for model libraries for MPT framework, Black Litterman Strategy
  43.  *      Incorporator, Holdings Constraint, and Transaction Costs.
  44.  *
  45.  *  - DRIP Numerical Optimizer: Library for Numerical Optimization and Spline Functionality.
  46.  *
  47.  *  - DRIP Statistical Learning: Library for Statistical Evaluation and Machine Learning.
  48.  *
  49.  *  Licensed under the Apache License, Version 2.0 (the "License");
  50.  *      you may not use this file except in compliance with the License.
  51.  *  
  52.  *  You may obtain a copy of the License at
  53.  *      http://www.apache.org/licenses/LICENSE-2.0
  54.  *  
  55.  *  Unless required by applicable law or agreed to in writing, software
  56.  *      distributed under the License is distributed on an "AS IS" BASIS,
  57.  *      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  58.  *  
  59.  *  See the License for the specific language governing permissions and
  60.  *      limitations under the License.
  61.  */

  62. /**
  63.  * CPGAUncollateralizedCorrelated illustrates the Counter Party Aggregation over Netting Groups based
  64.  *  Uncollateralized Collateral Groups with several Fix-Float Swaps where the Market Numeraires have
  65.  *  Correlated Realizations. The References are:
  66.  *  
  67.  *  - Burgard, C., and M. Kjaer (2014): PDE Representations of Derivatives with Bilateral Counter-party Risk
  68.  *      and Funding Costs, Journal of Credit Risk, 7 (3) 1-19.
  69.  *  
  70.  *  - Burgard, C., and M. Kjaer (2014): In the Balance, Risk, 24 (11) 72-75.
  71.  *  
  72.  *  - Gregory, J. (2009): Being Two-faced over Counter-party Credit Risk, Risk 20 (2) 86-90.
  73.  *  
  74.  *  - Li, B., and Y. Tang (2007): Quantitative Analysis, Derivatives Modeling, and Trading Strategies in the
  75.  *      Presence of Counter-party Credit Risk for the Fixed Income Market, World Scientific Publishing,
  76.  *      Singapore.
  77.  *
  78.  *  - Piterbarg, V. (2010): Funding Beyond Discounting: Collateral Agreements and Derivatives Pricing, Risk
  79.  *      21 (2) 97-102.
  80.  *
  81.  * @author Lakshmi Krishnamurthy
  82.  */

  83. public class CPGAUncollateralizedCorrelated {

  84.     private static final double[] NumeraireValueRealization (
  85.         final DiffusionEvolver deNumeraireValue,
  86.         final double dblNumeraireValueInitial,
  87.         final double dblTime,
  88.         final double dblTimeWidth,
  89.         final double[] adblRandom,
  90.         final int iNumStep)
  91.         throws Exception
  92.     {
  93.         double[] adblNumeraireValue = new double[iNumStep + 1];
  94.         adblNumeraireValue[0] = dblNumeraireValueInitial;
  95.         double[] adblTimeWidth = new double[iNumStep];

  96.         for (int i = 0; i < iNumStep; ++i)
  97.             adblTimeWidth[i] = dblTimeWidth;

  98.         JumpDiffusionEdge[] aJDE = deNumeraireValue.incrementSequence (
  99.             new JumpDiffusionVertex (
  100.                 dblTime,
  101.                 dblNumeraireValueInitial,
  102.                 0.,
  103.                 false
  104.             ),
  105.             JumpDiffusionEdgeUnit.Diffusion (
  106.                 adblTimeWidth,
  107.                 adblRandom
  108.             ),
  109.             dblTimeWidth
  110.         );

  111.         for (int j = 1; j <= iNumStep; ++j)
  112.             adblNumeraireValue[j] = aJDE[j - 1].finish();

  113.         return adblNumeraireValue;
  114.     }

  115.     private static final double[] VertexNumeraireRealization (
  116.         final DiffusionEvolver deNumeraireValue,
  117.         final double dblNumeraireValueInitial,
  118.         final double dblTime,
  119.         final double dblTimeWidth,
  120.         final double[] adblRandom,
  121.         final int iNumStep)
  122.         throws Exception
  123.     {
  124.         double[] adblNumeraireValue = new double[iNumStep + 1];
  125.         double[] adblTimeWidth = new double[iNumStep];

  126.         for (int i = 0; i < iNumStep; ++i)
  127.             adblTimeWidth[i] = dblTimeWidth;

  128.         JumpDiffusionVertex[] aJDV = deNumeraireValue.vertexSequenceReverse (
  129.             new JumpDiffusionVertex (
  130.                 dblTime,
  131.                 dblNumeraireValueInitial,
  132.                 0.,
  133.                 false
  134.             ),
  135.             JumpDiffusionEdgeUnit.Diffusion (
  136.                 adblTimeWidth,
  137.                 adblRandom
  138.             ),
  139.             adblTimeWidth
  140.         );

  141.         for (int j = 0; j <= iNumStep; ++j)
  142.             adblNumeraireValue[j] = aJDV[j].value();

  143.         return adblNumeraireValue;
  144.     }

  145.     private static final double[] ATMSwapRateOffsetRealization (
  146.         final DiffusionEvolver deATMSwapRateOffset,
  147.         final double dblATMSwapRateOffsetInitial,
  148.         final double[] adblRandom,
  149.         final double dblTime,
  150.         final double dblTimeWidth,
  151.         final int iNumStep)
  152.         throws Exception
  153.     {
  154.         double[] adblATMSwapRateOffset = new double[iNumStep + 1];
  155.         adblATMSwapRateOffset[0] = dblATMSwapRateOffsetInitial;
  156.         double[] adblTimeWidth = new double[iNumStep];

  157.         for (int i = 0; i < iNumStep; ++i)
  158.             adblTimeWidth[i] = dblTimeWidth;

  159.         JumpDiffusionEdge[] aJDE = deATMSwapRateOffset.incrementSequence (
  160.             new JumpDiffusionVertex (
  161.                 dblTime,
  162.                 dblATMSwapRateOffsetInitial,
  163.                 0.,
  164.                 false
  165.             ),
  166.             JumpDiffusionEdgeUnit.Diffusion (
  167.                 adblTimeWidth,
  168.                 adblRandom
  169.             ),
  170.             dblTimeWidth
  171.         );

  172.         for (int j = 1; j <= iNumStep; ++j)
  173.             adblATMSwapRateOffset[j] = aJDE[j - 1].finish();

  174.         return adblATMSwapRateOffset;
  175.     }

  176.     private static final double[] SwapPortfolioValueRealization (
  177.         final DiffusionEvolver deATMSwapRate,
  178.         final double dblATMSwapRateStart,
  179.         final double[] adblRandom,
  180.         final int iNumStep,
  181.         final double dblTime,
  182.         final double dblTimeWidth,
  183.         final int iNumSwap)
  184.         throws Exception
  185.     {
  186.         double[] adblSwapPortfolioValueRealization = new double[iNumStep + 1];

  187.         for (int i = 0; i < iNumStep; ++i)
  188.             adblSwapPortfolioValueRealization[i] = 0.;

  189.         for (int i = 0; i < iNumSwap; ++i) {
  190.             double[] adblATMSwapRateOffsetRealization = ATMSwapRateOffsetRealization (
  191.                 deATMSwapRate,
  192.                 dblATMSwapRateStart,
  193.                 adblRandom,
  194.                 dblTime,
  195.                 dblTimeWidth,
  196.                 iNumStep
  197.             );

  198.             for (int j = 0; j <= iNumStep; ++j)
  199.                 adblSwapPortfolioValueRealization[j] += dblTimeWidth * (iNumStep - j) * adblATMSwapRateOffsetRealization[j];
  200.         }

  201.         return adblSwapPortfolioValueRealization;
  202.     }

  203.     private static final void UDTDump (
  204.         final String strHeader,
  205.         final JulianDate[] adtVertexNode,
  206.         final UnivariateDiscreteThin[] aUDT)
  207.         throws Exception
  208.     {
  209.         System.out.println ("\t|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|");

  210.         System.out.println (strHeader);

  211.         System.out.println ("\t|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|");

  212.         String strDump = "\t|       DATE      =>" ;

  213.         for (int i = 0; i < adtVertexNode.length; ++i)
  214.             strDump = strDump + " " + adtVertexNode[i] + "  |";

  215.         System.out.println (strDump);

  216.         System.out.println ("\t|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|");

  217.          strDump = "\t|     AVERAGE     =>";

  218.         for (int j = 0; j < aUDT.length; ++j)
  219.             strDump = strDump + "   " + FormatUtil.FormatDouble (aUDT[j].average(), 2, 4, 1.) + "   |";

  220.         System.out.println (strDump);

  221.         strDump = "\t|     MAXIMUM     =>";

  222.         for (int j = 0; j < aUDT.length; ++j)
  223.             strDump = strDump + "   " + FormatUtil.FormatDouble (aUDT[j].maximum(), 2, 4, 1.) + "   |";

  224.         System.out.println (strDump);

  225.         strDump = "\t|     MINIMUM     =>";

  226.         for (int j = 0; j < aUDT.length; ++j)
  227.             strDump = strDump + "   " + FormatUtil.FormatDouble (aUDT[j].minimum(), 2, 4, 1.) + "   |";

  228.         System.out.println (strDump);

  229.         strDump = "\t|      ERROR      =>";

  230.         for (int j = 0; j < aUDT.length; ++j)
  231.             strDump = strDump + "   " + FormatUtil.FormatDouble (aUDT[j].error(), 2, 4, 1.) + "   |";

  232.         System.out.println (strDump);

  233.         System.out.println ("\t|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|");
  234.     }

  235.     private static final void UDTDump (
  236.         final String strHeader,
  237.         final UnivariateDiscreteThin udt)
  238.         throws Exception
  239.     {
  240.         System.out.println (
  241.             strHeader +
  242.             FormatUtil.FormatDouble (udt.average(), 3, 2, 100.) + "% | " +
  243.             FormatUtil.FormatDouble (udt.maximum(), 3, 2, 100.) + "% | " +
  244.             FormatUtil.FormatDouble (udt.minimum(), 3, 2, 100.) + "% | " +
  245.             FormatUtil.FormatDouble (udt.error(), 3, 2, 100.) + "% ||"
  246.         );
  247.     }

  248.     public static final void main (
  249.         final String[] astrArgs)
  250.         throws Exception
  251.     {
  252.         EnvManager.InitEnv ("");

  253.         int iNumStep = 10;
  254.         int iNumSwap = 10;
  255.         double dblTime = 5.;
  256.         int iNumPath = 10000;
  257.         double dblATMSwapRateOffsetDrift = 0.0;
  258.         double dblATMSwapRateOffsetVolatility = 0.25;
  259.         double dblATMSwapRateOffsetStart = 0.;
  260.         double dblOvernightNumeraireDrift = 0.004;
  261.         double dblOvernightNumeraireVolatility = 0.02;
  262.         double dblOvernightNumeraireInitial = 1.;
  263.         double dblCSADrift = 0.01;
  264.         double dblCSAVolatility = 0.05;
  265.         double dblCSAInitial = 1.;
  266.         double dblBankHazardRateDrift = 0.002;
  267.         double dblBankHazardRateVolatility = 0.20;
  268.         double dblBankHazardRateInitial = 0.015;
  269.         double dblBankRecoveryRateDrift = 0.002;
  270.         double dblBankRecoveryRateVolatility = 0.02;
  271.         double dblBankRecoveryRateInitial = 0.40;
  272.         double dblCounterPartyHazardRateDrift = 0.002;
  273.         double dblCounterPartyHazardRateVolatility = 0.30;
  274.         double dblCounterPartyHazardRateInitial = 0.030;
  275.         double dblCounterPartyRecoveryRateDrift = 0.002;
  276.         double dblCounterPartyRecoveryRateVolatility = 0.02;
  277.         double dblCounterPartyRecoveryRateInitial = 0.30;
  278.         double dblBankFundingSpreadDrift = 0.00002;
  279.         double dblBankFundingSpreadVolatility = 0.002;
  280.         double dblCounterPartyFundingSpreadDrift = 0.000022;
  281.         double dblCounterPartyFundingSpreadVolatility = 0.0022;

  282.         double[][] aadblCorrelation = new double[][] {
  283.             {1.00,  0.00,  0.03,  0.07,  0.04,  0.05,  0.08,  0.00,  0.00},  // PORTFOLIO
  284.             {0.00,  1.00,  0.00,  0.00,  0.00,  0.00,  0.00,  0.00,  1.00},  // OVERNIGHT
  285.             {0.03,  0.00,  1.00,  0.26,  0.33,  0.21,  0.35,  0.13,  0.00},  // CSA
  286.             {0.07,  0.00,  0.26,  1.00,  0.45, -0.17,  0.07,  0.77,  0.00},  // BANK HAZARD
  287.             {0.04,  0.00,  0.33,  0.45,  1.00, -0.22, -0.54,  0.58,  0.00},  // COUNTER PARTY HAZARD
  288.             {0.05,  0.00,  0.21, -0.17, -0.22,  1.00,  0.47, -0.23,  0.00},  // BANK RECOVERY
  289.             {0.08,  0.00,  0.35,  0.07, -0.54,  0.47,  1.00,  0.01,  0.00},  // COUNTER PARTY RECOVERY
  290.             {0.00,  0.00,  0.13,  0.77,  0.58, -0.23,  0.01,  1.00,  0.00},  // BANK FUNDING SPREAD
  291.             {0.00,  0.00,  0.00,  0.00,  0.00,  0.00,  0.00,  0.00,  1.00}   // COUNTER PARTY FUNDING SPREAD
  292.         };

  293.         JulianDate dtSpot = DateUtil.Today();

  294.         double dblTimeWidth = dblTime / iNumStep;
  295.         JulianDate[] adtVertex = new JulianDate[iNumStep + 1];
  296.         double[][] aadblPortfolioValue = new double[iNumPath][iNumStep + 1];
  297.         double[][] aadblCollateralBalance = new double[iNumPath][iNumStep + 1];
  298.         MonoPathExposureAdjustment[] aMPEA = new MonoPathExposureAdjustment[iNumPath];
  299.         double dblBankFundingSpreadInitial = dblBankHazardRateInitial / (1. - dblBankRecoveryRateInitial);
  300.         double dblCounterPartyFundingSpreadInitial = dblCounterPartyHazardRateInitial / (1. - dblCounterPartyRecoveryRateInitial);

  301.         DiffusionEvolver deATMSwapRateOffset = new DiffusionEvolver (
  302.             DiffusionEvaluatorLinear.Standard (
  303.                 dblATMSwapRateOffsetDrift,
  304.                 dblATMSwapRateOffsetVolatility
  305.             )
  306.         );

  307.         DiffusionEvolver deOvernightNumeraire = new DiffusionEvolver (
  308.             DiffusionEvaluatorLogarithmic.Standard (
  309.                 dblOvernightNumeraireDrift,
  310.                 dblOvernightNumeraireVolatility
  311.             )
  312.         );

  313.         DiffusionEvolver deCSA = new DiffusionEvolver (
  314.             DiffusionEvaluatorLogarithmic.Standard (
  315.                 dblCSADrift,
  316.                 dblCSAVolatility
  317.             )
  318.         );

  319.         DiffusionEvolver deBankHazardRate = new DiffusionEvolver (
  320.             DiffusionEvaluatorLogarithmic.Standard (
  321.                 dblBankHazardRateDrift,
  322.                 dblBankHazardRateVolatility
  323.             )
  324.         );

  325.         DiffusionEvolver deCounterPartyHazardRate = new DiffusionEvolver (
  326.             DiffusionEvaluatorLogarithmic.Standard (
  327.                 dblCounterPartyHazardRateDrift,
  328.                 dblCounterPartyHazardRateVolatility
  329.             )
  330.         );

  331.         DiffusionEvolver deBankRecoveryRate = new DiffusionEvolver (
  332.             DiffusionEvaluatorLogarithmic.Standard (
  333.                 dblBankRecoveryRateDrift,
  334.                 dblBankRecoveryRateVolatility
  335.             )
  336.         );

  337.         DiffusionEvolver deCounterPartyRecoveryRate = new DiffusionEvolver (
  338.             DiffusionEvaluatorLogarithmic.Standard (
  339.                 dblCounterPartyRecoveryRateDrift,
  340.                 dblCounterPartyRecoveryRateVolatility
  341.             )
  342.         );

  343.         DiffusionEvolver deBankFundingSpread = new DiffusionEvolver (
  344.             DiffusionEvaluatorLinear.Standard (
  345.                 dblBankFundingSpreadDrift,
  346.                 dblBankFundingSpreadVolatility
  347.             )
  348.         );

  349.         DiffusionEvolver deCounterPartyFundingSpread = new DiffusionEvolver (
  350.             DiffusionEvaluatorLinear.Standard (
  351.                 dblCounterPartyFundingSpreadDrift,
  352.                 dblCounterPartyFundingSpreadVolatility
  353.             )
  354.         );

  355.         for (int i = 0; i < iNumPath; ++i) {
  356.             double[][] aadblNumeraire = Matrix.Transpose (
  357.                 SequenceGenerator.GaussianJoint (
  358.                     iNumStep,
  359.                     aadblCorrelation
  360.                 )
  361.             );

  362.             aadblPortfolioValue[i] = SwapPortfolioValueRealization (
  363.                 deATMSwapRateOffset,
  364.                 dblATMSwapRateOffsetStart,
  365.                 aadblNumeraire[0],
  366.                 iNumStep,
  367.                 dblTime,
  368.                 dblTimeWidth,
  369.                 iNumSwap
  370.             );

  371.             double[] adblOvernightNumeraire = VertexNumeraireRealization (
  372.                 deOvernightNumeraire,
  373.                 dblOvernightNumeraireInitial,
  374.                 dblTime,
  375.                 dblTimeWidth,
  376.                 aadblNumeraire[1],
  377.                 iNumStep
  378.             );

  379.             double[] adblCSA = VertexNumeraireRealization (
  380.                 deCSA,
  381.                 dblCSAInitial,
  382.                 dblTime,
  383.                 dblTimeWidth,
  384.                 aadblNumeraire[2],
  385.                 iNumStep
  386.             );

  387.             double[] adblBankHazardRate = NumeraireValueRealization (
  388.                 deBankHazardRate,
  389.                 dblBankHazardRateInitial,
  390.                 dblTime,
  391.                 dblTimeWidth,
  392.                 aadblNumeraire[3],
  393.                 iNumStep
  394.             );

  395.             double[] adblCounterPartyHazardRate = NumeraireValueRealization (
  396.                 deCounterPartyHazardRate,
  397.                 dblCounterPartyHazardRateInitial,
  398.                 dblTime,
  399.                 dblTimeWidth,
  400.                 aadblNumeraire[4],
  401.                 iNumStep
  402.             );

  403.             double[] adblBankRecoveryRate = NumeraireValueRealization (
  404.                 deBankRecoveryRate,
  405.                 dblBankRecoveryRateInitial,
  406.                 dblTime,
  407.                 dblTimeWidth,
  408.                 aadblNumeraire[5],
  409.                 iNumStep
  410.             );

  411.             double[] adblCounterPartyRecoveryRate = NumeraireValueRealization (
  412.                 deCounterPartyRecoveryRate,
  413.                 dblCounterPartyRecoveryRateInitial,
  414.                 dblTime,
  415.                 dblTimeWidth,
  416.                 aadblNumeraire[6],
  417.                 iNumStep
  418.             );

  419.             double[] adblBankFundingSpread = NumeraireValueRealization (
  420.                 deBankFundingSpread,
  421.                 dblBankFundingSpreadInitial,
  422.                 dblTime,
  423.                 dblTimeWidth,
  424.                 aadblNumeraire[7],
  425.                 iNumStep
  426.             );

  427.             double[] adblCounterPartyFundingSpread = NumeraireValueRealization (
  428.                 deCounterPartyFundingSpread,
  429.                 dblCounterPartyFundingSpreadInitial,
  430.                 dblTime,
  431.                 dblTimeWidth,
  432.                 aadblNumeraire[8],
  433.                 iNumStep
  434.             );

  435.             MarketVertex[] aMV = new MarketVertex [iNumStep + 1];
  436.             AlbaneseAndersen[] aHGVR = new AlbaneseAndersen[iNumStep + 1];

  437.             for (int j = 0; j <= iNumStep; ++j)
  438.             {
  439.                 LatentStateVertexContainer latentStateVertexContainer = new LatentStateVertexContainer();

  440.                 latentStateVertexContainer.add (
  441.                     OTCFixFloatLabel.Standard ("USD-3M-10Y"),
  442.                     Double.NaN
  443.                 );

  444.                 aMV[j] = MarketVertex.Nodal (
  445.                     adtVertex[j] = dtSpot.addMonths (6 * j),
  446.                     dblOvernightNumeraireDrift,
  447.                     adblOvernightNumeraire[j],
  448.                     dblCSADrift,
  449.                     adblCSA[j],
  450.                     new MarketVertexEntity (
  451.                         Math.exp (-0.5 * adblBankHazardRate[j] * j),
  452.                         adblBankHazardRate[j],
  453.                         adblBankRecoveryRate[j],
  454.                         adblBankFundingSpread[j],
  455.                         Math.exp (-0.5 * adblBankHazardRate[j] * (1. - adblBankRecoveryRate[j]) * (iNumStep - j)),
  456.                         Double.NaN,
  457.                         Double.NaN,
  458.                         Double.NaN
  459.                     ),
  460.                     new MarketVertexEntity (
  461.                         Math.exp (-0.5 * adblCounterPartyHazardRate[j] * j),
  462.                         adblCounterPartyHazardRate[j],
  463.                         adblCounterPartyRecoveryRate[j],
  464.                         adblCounterPartyFundingSpread[j],
  465.                         Math.exp (-0.5 * adblCounterPartyHazardRate[j] * (1. - adblCounterPartyRecoveryRate[j]) * (iNumStep - j)),
  466.                         Double.NaN,
  467.                         Double.NaN,
  468.                         Double.NaN
  469.                     ),
  470.                     latentStateVertexContainer
  471.                 );

  472.                 aadblCollateralBalance[i][j] = 0.;

  473.                 aHGVR[j] = new AlbaneseAndersen (
  474.                     adtVertex[j],
  475.                     aadblPortfolioValue[i][j],
  476.                     0.,
  477.                     0.
  478.                 );
  479.             }

  480.             MarketPath mp = MarketPath.FromMarketVertexArray (aMV);

  481.             CollateralGroupPath[] aHGP = new CollateralGroupPath[] {
  482.                 new CollateralGroupPath (
  483.                     aHGVR,
  484.                     mp
  485.                 )
  486.             };

  487.             aMPEA[i] = new MonoPathExposureAdjustment (
  488.                 new AlbaneseAndersenFundingGroupPath[] {
  489.                     new AlbaneseAndersenFundingGroupPath (
  490.                         new AlbaneseAndersenNettingGroupPath[] {
  491.                             new AlbaneseAndersenNettingGroupPath (
  492.                                 aHGP,
  493.                                 mp
  494.                             )
  495.                         },
  496.                         mp
  497.                     )
  498.                 }
  499.             );
  500.         }

  501.         ExposureAdjustmentAggregator eaa = new ExposureAdjustmentAggregator (aMPEA);

  502.         ExposureAdjustmentDigest ead = eaa.digest();

  503.         System.out.println();

  504.         UDTDump (
  505.             "\t|                                                                                COLLATERALIZED EXPOSURE                                                                                |",
  506.             eaa.vertexDates(),
  507.             ead.collateralizedExposure()
  508.         );

  509.         UDTDump (
  510.             "\t|                                                                               UNCOLLATERALIZED EXPOSURE                                                                               |",
  511.             eaa.vertexDates(),
  512.             ead.uncollateralizedExposure()
  513.         );

  514.         UDTDump (
  515.             "\t|                                                                                COLLATERALIZED EXPOSURE PV                                                                             |",
  516.             eaa.vertexDates(),
  517.             ead.collateralizedExposurePV()
  518.         );

  519.         UDTDump (
  520.             "\t|                                                                               UNCOLLATERALIZED EXPOSURE PV                                                                            |",
  521.             eaa.vertexDates(),
  522.             ead.uncollateralizedExposurePV()
  523.         );

  524.         UDTDump (
  525.             "\t|                                                                            COLLATERALIZED POSITIVE EXPOSURE PV                                                                        |",
  526.             eaa.vertexDates(),
  527.             ead.collateralizedPositiveExposure()
  528.         );

  529.         UDTDump (
  530.             "\t|                                                                           UNCOLLATERALIZED POSITIVE EXPOSURE PV                                                                       |",
  531.             eaa.vertexDates(),
  532.             ead.uncollateralizedPositiveExposure()
  533.         );

  534.         UDTDump (
  535.             "\t|                                                                            COLLATERALIZED NEGATIVE EXPOSURE PV                                                                        |",
  536.             eaa.vertexDates(),
  537.             ead.collateralizedNegativeExposure()
  538.         );

  539.         UDTDump (
  540.             "\t|                                                                           UNCOLLATERALIZED NEGATIVE EXPOSURE PV                                                                       |",
  541.             eaa.vertexDates(),
  542.             ead.uncollateralizedNegativeExposure()
  543.         );

  544.         System.out.println();

  545.         System.out.println ("\t||-----------------------------------------------------||");

  546.         System.out.println ("\t||  UCVA CVA FTDCVA DVA FCA UNIVARIATE THIN STATISTICS ||");

  547.         System.out.println ("\t||-----------------------------------------------------||");

  548.         System.out.println ("\t||    L -> R:                                          ||");

  549.         System.out.println ("\t||            - Path Average                           ||");

  550.         System.out.println ("\t||            - Path Maximum                           ||");

  551.         System.out.println ("\t||            - Path Minimum                           ||");

  552.         System.out.println ("\t||            - Monte Carlo Error                      ||");

  553.         System.out.println ("\t||-----------------------------------------------------||");

  554.         UDTDump (
  555.             "\t||  UCVA  => ",
  556.             ead.ucva()
  557.         );

  558.         UDTDump (
  559.             "\t|| FTDCVA => ",
  560.             ead.ftdcva()
  561.         );

  562.         UDTDump (
  563.             "\t||   CVA  => ",
  564.             ead.cva()
  565.         );

  566.         UDTDump (
  567.             "\t||  CVACL => ",
  568.             ead.cvacl()
  569.         );

  570.         UDTDump (
  571.             "\t||   DVA  => ",
  572.             ead.dva()
  573.         );

  574.         UDTDump (
  575.             "\t||   FVA  => ",
  576.             ead.fva()
  577.         );

  578.         UDTDump (
  579.             "\t||   FDA  => ",
  580.             ead.fda()
  581.         );

  582.         UDTDump (
  583.             "\t||   FCA  => ",
  584.             ead.fca()
  585.         );

  586.         UDTDump (
  587.             "\t||   FBA  => ",
  588.             ead.fba()
  589.         );

  590.         UDTDump (
  591.             "\t||  SFVA  => ",
  592.             ead.sfva()
  593.         );

  594.         System.out.println ("\t||-----------------------------------------------------||");

  595.         UDTDump (
  596.             "\t||  Total => ",
  597.             ead.totalVA()
  598.         );

  599.         System.out.println ("\t||-----------------------------------------------------||");

  600.         System.out.println();

  601.         EnvManager.TerminateEnv();
  602.     }
  603. }