CPGAZeroThresholdCorrelated.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.mpor.CollateralAmountEstimator;
  5. import org.drip.exposure.universe.*;
  6. import org.drip.measure.bridge.BrokenDateInterpolatorLinearT;
  7. import org.drip.measure.discrete.SequenceGenerator;
  8. import org.drip.measure.dynamics.*;
  9. import org.drip.measure.process.DiffusionEvolver;
  10. import org.drip.measure.realization.*;
  11. import org.drip.measure.statistics.UnivariateDiscreteThin;
  12. import org.drip.numerical.common.FormatUtil;
  13. import org.drip.numerical.linearalgebra.Matrix;
  14. import org.drip.service.env.EnvManager;
  15. import org.drip.state.identifier.OTCFixFloatLabel;
  16. import org.drip.xva.gross.*;
  17. import org.drip.xva.netting.CollateralGroupPath;
  18. import org.drip.xva.proto.*;
  19. import org.drip.xva.settings.*;
  20. import org.drip.xva.strategy.*;
  21. import org.drip.xva.vertex.AlbaneseAndersen;

  22. /*
  23.  * -*- mode: java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  24.  */

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

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

  87. public class CPGAZeroThresholdCorrelated {

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

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

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

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

  117.         return adblNumeraireValue;
  118.     }

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

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

  132.         JumpDiffusionVertex[] aJDV = deNumeraireValue.vertexSequenceReverse (
  133.             new JumpDiffusionVertex (
  134.                 dblTime,
  135.                 dblNumeraireValueInitial,
  136.                 0.,
  137.                 false
  138.             ),
  139.             JumpDiffusionEdgeUnit.Diffusion (
  140.                 adblTimeWidth,
  141.                 adblRandom
  142.             ),
  143.             adblTimeWidth
  144.         );

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

  147.         return adblNumeraireValue;
  148.     }

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

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

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

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

  178.         return adblATMSwapRateOffset;
  179.     }

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

  191.         for (int i = 0; i < iNumStep; ++i)
  192.             adblSwapPortfolioValueRealization[i] = 0.;

  193.         for (int i = 0; i < iNumSwap; ++i) {
  194.             double[] adblATMSwapRateOffsetRealization = ATMSwapRateOffsetRealization (
  195.                 deATMSwapRate,
  196.                 dblATMSwapRateStart,
  197.                 adblRandom,
  198.                 dblTime,
  199.                 dblTimeWidth,
  200.                 iNumStep
  201.             );

  202.             for (int j = 0; j <= iNumStep; ++j)
  203.                 adblSwapPortfolioValueRealization[j] += dblTimeWidth * (iNumStep - j) * adblATMSwapRateOffsetRealization[j];
  204.         }

  205.         return adblSwapPortfolioValueRealization;
  206.     }

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

  214.         System.out.println (strHeader);

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

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

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

  219.         System.out.println (strDump);

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

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

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

  224.         System.out.println (strDump);

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

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

  228.         System.out.println (strDump);

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

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

  232.         System.out.println (strDump);

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

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

  236.         System.out.println (strDump);

  237.         System.out.println ("\t|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|");
  238.     }

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

  252.     public static final void main (
  253.         final String[] astrArgs)
  254.         throws Exception
  255.     {
  256.         EnvManager.InitEnv ("");

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

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

  297.         JulianDate dtSpot = DateUtil.Today();

  298.         PositionGroupSpecification positionGroupSpecification = PositionGroupSpecification.FixedThreshold (
  299.             "FIXEDTHRESHOLD",
  300.             0.,
  301.             0.,
  302.             PositionReplicationScheme.ALBANESE_ANDERSEN_VERTEX,
  303.             BrokenDateScheme.SQUARE_ROOT_OF_TIME,
  304.             0.,
  305.             CloseOutScheme.ISDA_92
  306.         );

  307.         double dblTimeWidth = dblTime / iNumStep;
  308.         JulianDate[] adtVertex = new JulianDate[iNumStep + 1];
  309.         double[][] aadblPortfolioValue = new double[iNumPath][iNumStep + 1];
  310.         MonoPathExposureAdjustment[] aMPEA = new MonoPathExposureAdjustment[iNumPath];
  311.         double dblBankFundingSpreadInitial = dblBankHazardRateInitial / (1. - dblBankRecoveryRateInitial);
  312.         double dblCounterPartyFundingSpreadInitial = dblCounterPartyHazardRateInitial / (1. - dblCounterPartyRecoveryRateInitial);

  313.         DiffusionEvolver deATMSwapRateOffset = new DiffusionEvolver (
  314.             DiffusionEvaluatorLinear.Standard (
  315.                 dblATMSwapRateOffsetDrift,
  316.                 dblATMSwapRateOffsetVolatility
  317.             )
  318.         );

  319.         DiffusionEvolver deOvernightNumeraire = new DiffusionEvolver (
  320.             DiffusionEvaluatorLogarithmic.Standard (
  321.                 dblOvernightNumeraireDrift,
  322.                 dblOvernightNumeraireVolatility
  323.             )
  324.         );

  325.         DiffusionEvolver deCSA = new DiffusionEvolver (
  326.             DiffusionEvaluatorLogarithmic.Standard (
  327.                 dblCSADrift,
  328.                 dblCSAVolatility
  329.             )
  330.         );

  331.         DiffusionEvolver deBankHazardRate = new DiffusionEvolver (
  332.             DiffusionEvaluatorLogarithmic.Standard (
  333.                 dblBankHazardRateDrift,
  334.                 dblBankHazardRateVolatility
  335.             )
  336.         );

  337.         DiffusionEvolver deCounterPartyHazardRate = new DiffusionEvolver (
  338.             DiffusionEvaluatorLogarithmic.Standard (
  339.                 dblCounterPartyHazardRateDrift,
  340.                 dblCounterPartyHazardRateVolatility
  341.             )
  342.         );

  343.         DiffusionEvolver deBankRecoveryRate = new DiffusionEvolver (
  344.             DiffusionEvaluatorLogarithmic.Standard (
  345.                 dblBankRecoveryRateDrift,
  346.                 dblBankRecoveryRateVolatility
  347.             )
  348.         );

  349.         DiffusionEvolver deCounterPartyRecoveryRate = new DiffusionEvolver (
  350.             DiffusionEvaluatorLogarithmic.Standard (
  351.                 dblCounterPartyRecoveryRateDrift,
  352.                 dblCounterPartyRecoveryRateVolatility
  353.             )
  354.         );

  355.         DiffusionEvolver deBankFundingSpread = new DiffusionEvolver (
  356.             DiffusionEvaluatorLinear.Standard (
  357.                 dblBankFundingSpreadDrift,
  358.                 dblBankFundingSpreadVolatility
  359.             )
  360.         );

  361.         DiffusionEvolver deCounterPartyFundingSpread = new DiffusionEvolver (
  362.             DiffusionEvaluatorLinear.Standard (
  363.                 dblCounterPartyFundingSpreadDrift,
  364.                 dblCounterPartyFundingSpreadVolatility
  365.             )
  366.         );

  367.         for (int i = 0; i < iNumPath; ++i) {
  368.             double[][] aadblNumeraire = Matrix.Transpose (
  369.                 SequenceGenerator.GaussianJoint (
  370.                     iNumStep,
  371.                     aadblCorrelation
  372.                 )
  373.             );

  374.             aadblPortfolioValue[i] = SwapPortfolioValueRealization (
  375.                 deATMSwapRateOffset,
  376.                 dblATMSwapRateOffsetStart,
  377.                 aadblNumeraire[0],
  378.                 iNumStep,
  379.                 dblTime,
  380.                 dblTimeWidth,
  381.                 iNumSwap
  382.             );

  383.             double[] adblOvernightNumeraire = VertexNumeraireRealization (
  384.                 deOvernightNumeraire,
  385.                 dblOvernightNumeraireInitial,
  386.                 dblTime,
  387.                 dblTimeWidth,
  388.                 aadblNumeraire[1],
  389.                 iNumStep
  390.             );

  391.             double[] adblCSA = VertexNumeraireRealization (
  392.                 deCSA,
  393.                 dblCSAInitial,
  394.                 dblTime,
  395.                 dblTimeWidth,
  396.                 aadblNumeraire[2],
  397.                 iNumStep
  398.             );

  399.             double[] adblBankHazardRate = NumeraireValueRealization (
  400.                 deBankHazardRate,
  401.                 dblBankHazardRateInitial,
  402.                 dblTime,
  403.                 dblTimeWidth,
  404.                 aadblNumeraire[3],
  405.                 iNumStep
  406.             );

  407.             double[] adblCounterPartyHazardRate = NumeraireValueRealization (
  408.                 deCounterPartyHazardRate,
  409.                 dblCounterPartyHazardRateInitial,
  410.                 dblTime,
  411.                 dblTimeWidth,
  412.                 aadblNumeraire[4],
  413.                 iNumStep
  414.             );

  415.             double[] adblBankRecoveryRate = NumeraireValueRealization (
  416.                 deBankRecoveryRate,
  417.                 dblBankRecoveryRateInitial,
  418.                 dblTime,
  419.                 dblTimeWidth,
  420.                 aadblNumeraire[5],
  421.                 iNumStep
  422.             );

  423.             double[] adblCounterPartyRecoveryRate = NumeraireValueRealization (
  424.                 deCounterPartyRecoveryRate,
  425.                 dblCounterPartyRecoveryRateInitial,
  426.                 dblTime,
  427.                 dblTimeWidth,
  428.                 aadblNumeraire[6],
  429.                 iNumStep
  430.             );

  431.             double[] adblBankFundingSpread = NumeraireValueRealization (
  432.                 deBankFundingSpread,
  433.                 dblBankFundingSpreadInitial,
  434.                 dblTime,
  435.                 dblTimeWidth,
  436.                 aadblNumeraire[7],
  437.                 iNumStep
  438.             );

  439.             double[] adblCounterPartyFundingSpread = NumeraireValueRealization (
  440.                 deCounterPartyFundingSpread,
  441.                 dblCounterPartyFundingSpreadInitial,
  442.                 dblTime,
  443.                 dblTimeWidth,
  444.                 aadblNumeraire[8],
  445.                 iNumStep
  446.             );

  447.             JulianDate dtStart = dtSpot;
  448.             MarketVertex[] aMV = new MarketVertex [iNumStep + 1];
  449.             double dblValueStart = dblTime * dblATMSwapRateOffsetStart;
  450.             AlbaneseAndersen[] aHGVR = new AlbaneseAndersen[iNumStep + 1];

  451.             for (int j = 0; j <= iNumStep; ++j)
  452.             {
  453.                 LatentStateVertexContainer latentStateVertexContainer = new LatentStateVertexContainer();

  454.                 latentStateVertexContainer.add (
  455.                     OTCFixFloatLabel.Standard ("USD-3M-10Y"),
  456.                     Double.NaN
  457.                 );

  458.                 aMV[j] = MarketVertex.Nodal (
  459.                     adtVertex[j] = dtSpot.addMonths (6 * j),
  460.                     dblOvernightNumeraireDrift,
  461.                     adblOvernightNumeraire[j],
  462.                     dblCSADrift,
  463.                     adblCSA[j],
  464.                     new MarketVertexEntity (
  465.                         Math.exp (-0.5 * adblBankHazardRate[j] * j),
  466.                         adblBankHazardRate[j],
  467.                         adblBankRecoveryRate[j],
  468.                         adblBankFundingSpread[j],
  469.                         Math.exp (-0.5 * adblBankHazardRate[j] * (1. - adblBankRecoveryRate[j]) * (iNumStep - j)),
  470.                         Double.NaN,
  471.                         Double.NaN,
  472.                         Double.NaN
  473.                     ),
  474.                     new MarketVertexEntity (
  475.                         Math.exp (-0.5 * adblCounterPartyHazardRate[j] * j),
  476.                         adblCounterPartyHazardRate[j],
  477.                         adblCounterPartyRecoveryRate[j],
  478.                         adblCounterPartyFundingSpread[j],
  479.                         Math.exp (-0.5 * adblCounterPartyHazardRate[j] * (1. - adblCounterPartyRecoveryRate[j]) * (iNumStep - j)),
  480.                         Double.NaN,
  481.                         Double.NaN,
  482.                         Double.NaN
  483.                     ),
  484.                     latentStateVertexContainer
  485.                 );

  486.                 JulianDate dtEnd = adtVertex[j];
  487.                 double dblCollateralBalance = 0.;
  488.                 double dblValueEnd = aadblPortfolioValue[i][j];

  489.                 if (0 != j) {
  490.                     CollateralAmountEstimator hae = new CollateralAmountEstimator (
  491.                         positionGroupSpecification,
  492.                         new BrokenDateInterpolatorLinearT (
  493.                             dtStart.julian(),
  494.                             dtEnd.julian(),
  495.                             dblValueStart,
  496.                             dblValueEnd
  497.                         ),
  498.                         Double.NaN
  499.                     );

  500.                     dblCollateralBalance = hae.postingRequirement (dtEnd);
  501.                 }

  502.                 aHGVR[j] = new AlbaneseAndersen (
  503.                     adtVertex[j],
  504.                     aadblPortfolioValue[i][j],
  505.                     0.,
  506.                     dblCollateralBalance
  507.                 );

  508.                 dtStart = dtEnd;
  509.                 dblValueStart = dblValueEnd;
  510.             }

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

  512.             CollateralGroupPath[] aHGP = new CollateralGroupPath[] {
  513.                 new CollateralGroupPath (
  514.                     aHGVR,
  515.                     mp
  516.                 )
  517.             };

  518.             aMPEA[i] = new MonoPathExposureAdjustment (
  519.                 new AlbaneseAndersenFundingGroupPath[] {
  520.                     new AlbaneseAndersenFundingGroupPath (
  521.                         new AlbaneseAndersenNettingGroupPath[] {
  522.                             new AlbaneseAndersenNettingGroupPath (
  523.                                 aHGP,
  524.                                 mp
  525.                             )
  526.                         },
  527.                         mp
  528.                     )
  529.                 }
  530.             );
  531.         }

  532.         ExposureAdjustmentAggregator eaa = new ExposureAdjustmentAggregator (aMPEA);

  533.         ExposureAdjustmentDigest ead = eaa.digest();

  534.         System.out.println();

  535.         UDTDump (
  536.             "\t|                                                                                COLLATERALIZED EXPOSURE                                                                                |",
  537.             eaa.vertexDates(),
  538.             ead.collateralizedExposure()
  539.         );

  540.         UDTDump (
  541.             "\t|                                                                               UNCOLLATERALIZED EXPOSURE                                                                               |",
  542.             eaa.vertexDates(),
  543.             ead.uncollateralizedExposure()
  544.         );

  545.         UDTDump (
  546.             "\t|                                                                                COLLATERALIZED EXPOSURE PV                                                                             |",
  547.             eaa.vertexDates(),
  548.             ead.collateralizedExposurePV()
  549.         );

  550.         UDTDump (
  551.             "\t|                                                                               UNCOLLATERALIZED EXPOSURE PV                                                                            |",
  552.             eaa.vertexDates(),
  553.             ead.uncollateralizedExposurePV()
  554.         );

  555.         UDTDump (
  556.             "\t|                                                                            COLLATERALIZED POSITIVE EXPOSURE PV                                                                        |",
  557.             eaa.vertexDates(),
  558.             ead.collateralizedPositiveExposure()
  559.         );

  560.         UDTDump (
  561.             "\t|                                                                           UNCOLLATERALIZED POSITIVE EXPOSURE PV                                                                       |",
  562.             eaa.vertexDates(),
  563.             ead.uncollateralizedPositiveExposure()
  564.         );

  565.         UDTDump (
  566.             "\t|                                                                            COLLATERALIZED NEGATIVE EXPOSURE PV                                                                        |",
  567.             eaa.vertexDates(),
  568.             ead.collateralizedNegativeExposure()
  569.         );

  570.         UDTDump (
  571.             "\t|                                                                           UNCOLLATERALIZED NEGATIVE EXPOSURE PV                                                                       |",
  572.             eaa.vertexDates(),
  573.             ead.uncollateralizedNegativeExposure()
  574.         );

  575.         System.out.println();

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

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

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

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

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

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

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

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

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

  585.         UDTDump (
  586.             "\t||  UCVA  => ",
  587.             ead.ucva()
  588.         );

  589.         UDTDump (
  590.             "\t|| FTDCVA => ",
  591.             ead.ftdcva()
  592.         );

  593.         UDTDump (
  594.             "\t||   CVA  => ",
  595.             ead.cva()
  596.         );

  597.         UDTDump (
  598.             "\t||  CVACL => ",
  599.             ead.cvacl()
  600.         );

  601.         UDTDump (
  602.             "\t||   DVA  => ",
  603.             ead.dva()
  604.         );

  605.         UDTDump (
  606.             "\t||   FVA  => ",
  607.             ead.fva()
  608.         );

  609.         UDTDump (
  610.             "\t||   FDA  => ",
  611.             ead.fda()
  612.         );

  613.         UDTDump (
  614.             "\t||   FCA  => ",
  615.             ead.fca()
  616.         );

  617.         UDTDump (
  618.             "\t||   FBA  => ",
  619.             ead.fba()
  620.         );

  621.         UDTDump (
  622.             "\t||  SFVA  => ",
  623.             ead.sfva()
  624.         );

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

  626.         UDTDump (
  627.             "\t||  Total => ",
  628.             ead.totalVA()
  629.         );

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

  631.         System.out.println();

  632.         EnvManager.TerminateEnv();
  633.     }
  634. }