PerfectReplicationCollateralizedFundingStochastic.java

  1. package org.drip.sample.burgard2013;

  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.crng.RandomNumberGenerator;
  8. import org.drip.measure.discrete.CorrelatedPathVertexDimension;
  9. import org.drip.measure.dynamics.*;
  10. import org.drip.measure.process.DiffusionEvolver;
  11. import org.drip.measure.realization.*;
  12. import org.drip.measure.statistics.UnivariateDiscreteThin;
  13. import org.drip.numerical.common.FormatUtil;
  14. import org.drip.numerical.linearalgebra.Matrix;
  15. import org.drip.service.env.EnvManager;
  16. import org.drip.state.identifier.OTCFixFloatLabel;
  17. import org.drip.xva.basel.*;
  18. import org.drip.xva.definition.*;
  19. import org.drip.xva.gross.*;
  20. import org.drip.xva.hypothecation.*;
  21. import org.drip.xva.netting.CollateralGroupPath;
  22. import org.drip.xva.proto.*;
  23. import org.drip.xva.settings.*;
  24. import org.drip.xva.strategy.*;
  25. import org.drip.xva.vertex.BurgardKjaerBuilder;

  26. /*
  27.  * -*- mode: java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  28.  */

  29. /*!
  30.  * Copyright (C) 2020 Lakshmi Krishnamurthy
  31.  * Copyright (C) 2019 Lakshmi Krishnamurthy
  32.  * Copyright (C) 2018 Lakshmi Krishnamurthy
  33.  * Copyright (C) 2017 Lakshmi Krishnamurthy
  34.  *
  35.  *  This file is part of DROP, an open-source library targeting analytics/risk, transaction cost analytics,
  36.  *      asset liability management analytics, capital, exposure, and margin analytics, valuation adjustment
  37.  *      analytics, and portfolio construction analytics within and across fixed income, credit, commodity,
  38.  *      equity, FX, and structured products. It also includes auxiliary libraries for algorithm support,
  39.  *      numerical analysis, numerical optimization, spline builder, model validation, statistical learning,
  40.  *      and computational support.
  41.  *  
  42.  *      https://lakshmidrip.github.io/DROP/
  43.  *  
  44.  *  DROP is composed of three modules:
  45.  *  
  46.  *  - DROP Product Core - https://lakshmidrip.github.io/DROP-Product-Core/
  47.  *  - DROP Portfolio Core - https://lakshmidrip.github.io/DROP-Portfolio-Core/
  48.  *  - DROP Computational Core - https://lakshmidrip.github.io/DROP-Computational-Core/
  49.  *
  50.  *  DROP Product Core implements libraries for the following:
  51.  *  - Fixed Income Analytics
  52.  *  - Loan Analytics
  53.  *  - Transaction Cost Analytics
  54.  *
  55.  *  DROP Portfolio Core implements libraries for the following:
  56.  *  - Asset Allocation Analytics
  57.  *  - Asset Liability Management Analytics
  58.  *  - Capital Estimation Analytics
  59.  *  - Exposure Analytics
  60.  *  - Margin Analytics
  61.  *  - XVA Analytics
  62.  *
  63.  *  DROP Computational Core implements libraries for the following:
  64.  *  - Algorithm Support
  65.  *  - Computation Support
  66.  *  - Function Analysis
  67.  *  - Model Validation
  68.  *  - Numerical Analysis
  69.  *  - Numerical Optimizer
  70.  *  - Spline Builder
  71.  *  - Statistical Learning
  72.  *
  73.  *  Documentation for DROP is Spread Over:
  74.  *
  75.  *  - Main                     => https://lakshmidrip.github.io/DROP/
  76.  *  - Wiki                     => https://github.com/lakshmiDRIP/DROP/wiki
  77.  *  - GitHub                   => https://github.com/lakshmiDRIP/DROP
  78.  *  - Repo Layout Taxonomy     => https://github.com/lakshmiDRIP/DROP/blob/master/Taxonomy.md
  79.  *  - Javadoc                  => https://lakshmidrip.github.io/DROP/Javadoc/index.html
  80.  *  - Technical Specifications => https://github.com/lakshmiDRIP/DROP/tree/master/Docs/Internal
  81.  *  - Release Versions         => https://lakshmidrip.github.io/DROP/version.html
  82.  *  - Community Credits        => https://lakshmidrip.github.io/DROP/credits.html
  83.  *  - Issues Catalog           => https://github.com/lakshmiDRIP/DROP/issues
  84.  *  - JUnit                    => https://lakshmidrip.github.io/DROP/junit/index.html
  85.  *  - Jacoco                   => https://lakshmidrip.github.io/DROP/jacoco/index.html
  86.  *
  87.  *  Licensed under the Apache License, Version 2.0 (the "License");
  88.  *      you may not use this file except in compliance with the License.
  89.  *  
  90.  *  You may obtain a copy of the License at
  91.  *      http://www.apache.org/licenses/LICENSE-2.0
  92.  *  
  93.  *  Unless required by applicable law or agreed to in writing, software
  94.  *      distributed under the License is distributed on an "AS IS" BASIS,
  95.  *      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  96.  *  
  97.  *  See the License for the specific language governing permissions and
  98.  *      limitations under the License.
  99.  */

  100. /**
  101.  * <i>PerfectReplicationCollateralizedFundingStochastic</i> examines the Basel BCBS 2012 OTC Accounting
  102.  * Impact to a Portfolio of 10 Swaps resulting from the Addition of a New Swap - Comparison via both FVA/FDA
  103.  * and FCA/FBA Schemes. Simulation is carried out under the following Criteria using one of the Generalized
  104.  * Burgard Kjaer (2013) Scheme.
  105.  *  
  106.  * <br><br>
  107.  *  <ul>
  108.  *      <li>
  109.  *          Collateralization Status - Collateralized
  110.  *      </li>
  111.  *      <li>
  112.  *          Aggregation Unit         - Funding Group
  113.  *      </li>
  114.  *      <li>
  115.  *          Added Swap Type          - Zero Upfront Par Swap (Neutral)
  116.  *      </li>
  117.  *      <li>
  118.  *          Market Dynamics          - Stochastic (Dynamic Market Evolution)
  119.  *      </li>
  120.  *      <li>
  121.  *          Funding Strategy         - Perfect Replication
  122.  *      </li>
  123.  *  </ul>
  124.  *  
  125.  * The References are:
  126.  *  
  127.  * <br><br>
  128.  *  <ul>
  129.  *      <li>
  130.  *          Burgard, C., and M. Kjaer (2014): PDE Representations of Derivatives with Bilateral Counter-party
  131.  *              Risk and Funding Costs <i>Journal of Credit Risk</i> <b>7 (3)</b> 1-19
  132.  *      </li>
  133.  *      <li>
  134.  *          Burgard, C., and M. Kjaer (2014): In the Balance <i>Risk</i> <b>24 (11)</b> 72-75
  135.  *      </li>
  136.  *      <li>
  137.  *          Gregory, J. (2009): Being Two-faced over Counter-party Credit Risk <i>Risk</i> <b>20 (2)</b>
  138.  *              86-90
  139.  *      </li>
  140.  *      <li>
  141.  *          Li, B., and Y. Tang (2007): <i>Quantitative Analysis, Derivatives Modeling, and Trading
  142.  *              Strategies in the Presence of Counter-party Credit Risk for the Fixed Income Market</i>
  143.  *              <b>World Scientific Publishing</b> Singapore
  144.  *      </li>
  145.  *      <li>
  146.  *          Piterbarg, V. (2010): Funding Beyond Discounting: Collateral Agreements and Derivatives Pricing
  147.  *              <i>Risk</i> <b>21 (2)</b> 97-102
  148.  *      </li>
  149.  *  </ul>
  150.  *  
  151.  * <br><br>
  152.  *  <ul>
  153.  *      <li><b>Module </b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/PortfolioCore.md">Portfolio Core Module</a></li>
  154.  *      <li><b>Library</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/XVAAnalyticsLibrary.md">XVA Analytics Library</a></li>
  155.  *      <li><b>Project</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/sample/README.md">DROP API Construction and Usage</a></li>
  156.  *      <li><b>Package</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/sample/burgard2013/README.md">Burgard Kjaer (2013) Valuation Adjustments</a></li>
  157.  *  </ul>
  158.  * <br><br>
  159.  *
  160.  * @author Lakshmi Krishnamurthy
  161.  */

  162. public class PerfectReplicationCollateralizedFundingStochastic {

  163.     private static final double[] NumeraireValueRealization (
  164.         final DiffusionEvolver deNumeraireValue,
  165.         final double dblNumeraireValueInitial,
  166.         final double dblTime,
  167.         final double dblTimeWidth,
  168.         final double[] adblRandom,
  169.         final int iNumStep)
  170.         throws Exception
  171.     {
  172.         double[] adblNumeraireValue = new double[iNumStep + 1];
  173.         adblNumeraireValue[0] = dblNumeraireValueInitial;
  174.         double[] adblTimeWidth = new double[iNumStep];

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

  177.         JumpDiffusionEdge[] aJDE = deNumeraireValue.incrementSequence (
  178.             new JumpDiffusionVertex (
  179.                 dblTime,
  180.                 dblNumeraireValueInitial,
  181.                 0.,
  182.                 false
  183.             ),
  184.             JumpDiffusionEdgeUnit.Diffusion (
  185.                 adblTimeWidth,
  186.                 adblRandom
  187.             ),
  188.             dblTimeWidth
  189.         );

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

  192.         return adblNumeraireValue;
  193.     }

  194.     private static final double[] VertexNumeraireRealization (
  195.         final DiffusionEvolver deNumeraireValue,
  196.         final double dblNumeraireValueInitial,
  197.         final double dblTime,
  198.         final double dblTimeWidth,
  199.         final double[] adblRandom,
  200.         final int iNumStep)
  201.         throws Exception
  202.     {
  203.         double[] adblNumeraireValue = new double[iNumStep + 1];
  204.         double[] adblTimeWidth = new double[iNumStep];

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

  207.         JumpDiffusionVertex[] aJDV = deNumeraireValue.vertexSequenceReverse (
  208.             new JumpDiffusionVertex (
  209.                 dblTime,
  210.                 dblNumeraireValueInitial,
  211.                 0.,
  212.                 false
  213.             ),
  214.             JumpDiffusionEdgeUnit.Diffusion (
  215.                 adblTimeWidth,
  216.                 adblRandom
  217.             ),
  218.             adblTimeWidth
  219.         );

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

  222.         return adblNumeraireValue;
  223.     }

  224.     private static final double[] ATMSwapRateOffsetRealization (
  225.         final DiffusionEvolver deATMSwapRateOffset,
  226.         final double dblATMSwapRateOffsetInitial,
  227.         final double[] adblRandom,
  228.         final double dblTime,
  229.         final double dblTimeWidth,
  230.         final int iNumStep)
  231.         throws Exception
  232.     {
  233.         double[] adblATMSwapRateOffset = new double[iNumStep + 1];
  234.         adblATMSwapRateOffset[0] = dblATMSwapRateOffsetInitial;
  235.         double[] adblTimeWidth = new double[iNumStep];

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

  238.         JumpDiffusionEdge[] aJDE = deATMSwapRateOffset.incrementSequence (
  239.             new JumpDiffusionVertex (
  240.                 dblTime,
  241.                 dblATMSwapRateOffsetInitial,
  242.                 0.,
  243.                 false
  244.             ),
  245.             JumpDiffusionEdgeUnit.Diffusion (
  246.                 adblTimeWidth,
  247.                 adblRandom
  248.             ),
  249.             dblTimeWidth
  250.         );

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

  253.         return adblATMSwapRateOffset;
  254.     }

  255.     private static final double[] SwapPortfolioValueRealization (
  256.         final DiffusionEvolver deATMSwapRate,
  257.         final double dblATMSwapRateStart,
  258.         final double[] adblRandom,
  259.         final int iNumStep,
  260.         final double dblTime,
  261.         final double dblTimeWidth,
  262.         final double dblTimeMaturity,
  263.         final double dblSwapNotional)
  264.         throws Exception
  265.     {
  266.         double[] adblSwapPortfolioValueRealization = new double[iNumStep + 1];
  267.         int iMaturityStep = (int) (dblTimeMaturity / dblTimeWidth);

  268.         for (int i = 0; i < iNumStep; ++i)
  269.             adblSwapPortfolioValueRealization[i] = 0.;

  270.         double[] adblATMSwapRateOffsetRealization = ATMSwapRateOffsetRealization (
  271.             deATMSwapRate,
  272.             dblATMSwapRateStart,
  273.             adblRandom,
  274.             dblTime,
  275.             dblTimeWidth,
  276.             iNumStep
  277.         );

  278.         for (int j = 0; j <= iNumStep; ++j)
  279.             adblSwapPortfolioValueRealization[j] = j > iMaturityStep ? 0. :
  280.                 dblSwapNotional * dblTimeWidth * (iMaturityStep - j) * adblATMSwapRateOffsetRealization[j];

  281.         return adblSwapPortfolioValueRealization;
  282.     }

  283.     private static final double[][] Path (
  284.         final double[][] aadblCorrelation,
  285.         final int iNumVertex)
  286.         throws Exception
  287.     {
  288.         CorrelatedPathVertexDimension cpvd = new CorrelatedPathVertexDimension (
  289.             new RandomNumberGenerator(),
  290.             aadblCorrelation,
  291.             iNumVertex,
  292.             1,
  293.             false,
  294.             null
  295.         );

  296.         return cpvd.multiPathVertexRd()[0].flatform();
  297.     }

  298.     private static final ExposureAdjustmentAggregator[] Mix (
  299.         final double dblTimeMaturity1,
  300.         final double dblATMSwapRateOffsetStart1,
  301.         final double dblSwapNotional1,
  302.         final double dblTimeMaturity2,
  303.         final double dblATMSwapRateOffsetStart2,
  304.         final double dblSwapNotional2)
  305.         throws Exception
  306.     {
  307.         int iNumStep = 10;
  308.         int iNumPath = 60000;
  309.         int iNumVertex = 10;
  310.         double dblTime = 5.;
  311.         double dblATMSwapRateOffsetDrift = 0.0;
  312.         double dblATMSwapRateOffsetVolatility = 0.25;
  313.         double dblOvernightNumeraireDrift = 0.004;
  314.         double dblOvernightNumeraireVolatility = 0.02;
  315.         double dblOvernightNumeraireInitial = 1.;
  316.         double dblCSADrift = 0.01;
  317.         double dblCSAVolatility = 0.05;
  318.         double dblCSAInitial = 1.;
  319.         double dblBankHazardRateDrift = 0.002;
  320.         double dblBankHazardRateVolatility = 0.20;
  321.         double dblBankHazardRateInitial = 0.015;
  322.         double dblBankSeniorRecoveryRateDrift = 0.002;
  323.         double dblBankSeniorRecoveryRateVolatility = 0.02;
  324.         double dblBankSeniorRecoveryRateInitial = 0.40;
  325.         double dblBankSubordinateRecoveryRateDrift = 0.001;
  326.         double dblBankSubordinateRecoveryRateVolatility = 0.01;
  327.         double dblBankSubordinateRecoveryRateInitial = 0.15;
  328.         double dblCounterPartyHazardRateDrift = 0.002;
  329.         double dblCounterPartyHazardRateVolatility = 0.30;
  330.         double dblCounterPartyHazardRateInitial = 0.030;
  331.         double dblCounterPartyRecoveryRateDrift = 0.002;
  332.         double dblCounterPartyRecoveryRateVolatility = 0.02;
  333.         double dblCounterPartyRecoveryRateInitial = 0.30;
  334.         double dblBankSeniorFundingSpreadDrift = 0.00002;
  335.         double dblBankSeniorFundingSpreadVolatility = 0.002;
  336.         double dblBankSubordinateFundingSpreadDrift = 0.00001;
  337.         double dblBankSubordinateFundingSpreadVolatility = 0.001;
  338.         double dblCounterPartyFundingSpreadDrift = 0.000022;
  339.         double dblCounterPartyFundingSpreadVolatility = 0.0022;
  340.         double dblBankThreshold = -0.1;
  341.         double dblCounterPartyThreshold = 0.1;

  342.         double[][] aadblCorrelation = new double[][] {
  343.             {1.00,  0.00,  0.03,  0.07,  0.04,  0.05,  0.00,  0.08,  0.00,  0.00,  0.00},  // PORTFOLIO
  344.             {0.00,  1.00,  0.00,  0.00,  0.00,  0.00,  0.00,  0.00,  0.00,  0.00,  0.00},  // OVERNIGHT
  345.             {0.03,  0.00,  1.00,  0.26,  0.33,  0.21,  0.00,  0.35,  0.13,  0.00,  0.00},  // CSA
  346.             {0.07,  0.00,  0.26,  1.00,  0.45, -0.17,  0.00,  0.07,  0.77,  0.00,  0.00},  // BANK HAZARD
  347.             {0.04,  0.00,  0.33,  0.45,  1.00, -0.22,  0.00, -0.54,  0.58,  0.00,  0.00},  // COUNTER PARTY HAZARD
  348.             {0.05,  0.00,  0.21, -0.17, -0.22,  1.00,  0.00,  0.47, -0.23,  0.00,  0.00},  // BANK SENIOR RECOVERY
  349.             {0.00,  0.00,  0.00,  0.00,  0.00,  0.00,  1.00,  0.00,  0.00,  0.00,  0.00},  // BANK SUBORDINATE RECOVERY
  350.             {0.08,  0.00,  0.35,  0.07, -0.54,  0.47,  0.00,  1.00,  0.01,  0.00,  0.00},  // COUNTER PARTY RECOVERY
  351.             {0.00,  0.00,  0.13,  0.77,  0.58, -0.23,  0.00,  0.01,  1.00,  0.00,  0.00},  // BANK SENIOR FUNDING SPREAD
  352.             {0.00,  0.00,  0.00,  0.00,  0.00,  0.00,  0.00,  0.00,  0.00,  1.00,  0.00},  // BANK SUBORDINATE FUNDING SPREAD
  353.             {0.00,  0.00,  0.00,  0.00,  0.00,  0.00,  0.00,  0.00,  0.00,  0.00,  1.00}   // COUNTER PARTY FUNDING SPREAD
  354.         };

  355.         PositionGroupSpecification positionGroupSpecification = PositionGroupSpecification.FixedThreshold (
  356.             "FIXEDTHRESHOLD",
  357.             dblCounterPartyThreshold,
  358.             dblBankThreshold,
  359.             PositionReplicationScheme.BURGARD_KJAER_HEDGE_ERROR_DUAL_BOND_VERTEX,
  360.             BrokenDateScheme.LINEAR_TIME,
  361.             0.,
  362.             CloseOutScheme.BILATERAL
  363.         );

  364.         JulianDate dtSpot = DateUtil.Today();

  365.         double dblTimeWidth = dblTime / iNumStep;
  366.         JulianDate[] adtVertex = new JulianDate[iNumStep + 1];
  367.         double[][] aadblPortfolio1Value = new double[iNumPath][iNumStep + 1];
  368.         double[][] aadblPortfolio2Value = new double[iNumPath][iNumStep + 1];
  369.         MonoPathExposureAdjustment[] aMPEAGround = new MonoPathExposureAdjustment[iNumPath];
  370.         MonoPathExposureAdjustment[] aMPEAExtended = new MonoPathExposureAdjustment[iNumPath];
  371.         double dblBankSeniorFundingSpreadInitial = dblBankHazardRateInitial / (1. - dblBankSeniorRecoveryRateInitial);
  372.         double dblBankSubordinateFundingSpreadInitial = dblBankHazardRateInitial / (1. - dblBankSubordinateRecoveryRateInitial);
  373.         double dblCounterPartyFundingSpreadInitial = dblCounterPartyHazardRateInitial / (1. - dblCounterPartyRecoveryRateInitial);

  374.         DiffusionEvolver deATMSwapRateOffset = new DiffusionEvolver (
  375.             DiffusionEvaluatorLinear.Standard (
  376.                 dblATMSwapRateOffsetDrift,
  377.                 dblATMSwapRateOffsetVolatility
  378.             )
  379.         );

  380.         DiffusionEvolver deOvernightNumeraire = new DiffusionEvolver (
  381.             DiffusionEvaluatorLogarithmic.Standard (
  382.                 dblOvernightNumeraireDrift,
  383.                 dblOvernightNumeraireVolatility
  384.             )
  385.         );

  386.         DiffusionEvolver deCSA = new DiffusionEvolver (
  387.             DiffusionEvaluatorLogarithmic.Standard (
  388.                 dblCSADrift,
  389.                 dblCSAVolatility
  390.             )
  391.         );

  392.         DiffusionEvolver deBankHazardRate = new DiffusionEvolver (
  393.             DiffusionEvaluatorLogarithmic.Standard (
  394.                 dblBankHazardRateDrift,
  395.                 dblBankHazardRateVolatility
  396.             )
  397.         );

  398.         DiffusionEvolver deBankSeniorRecoveryRate = new DiffusionEvolver (
  399.             DiffusionEvaluatorLogarithmic.Standard (
  400.                 dblBankSeniorRecoveryRateDrift,
  401.                 dblBankSeniorRecoveryRateVolatility
  402.             )
  403.         );

  404.         DiffusionEvolver deBankSubordinateRecoveryRate = new DiffusionEvolver (
  405.             DiffusionEvaluatorLogarithmic.Standard (
  406.                 dblBankSubordinateRecoveryRateDrift,
  407.                 dblBankSubordinateRecoveryRateVolatility
  408.             )
  409.         );

  410.         DiffusionEvolver deCounterPartyHazardRate = new DiffusionEvolver (
  411.             DiffusionEvaluatorLogarithmic.Standard (
  412.                 dblCounterPartyHazardRateDrift,
  413.                 dblCounterPartyHazardRateVolatility
  414.             )
  415.         );

  416.         DiffusionEvolver deCounterPartyRecoveryRate = new DiffusionEvolver (
  417.             DiffusionEvaluatorLogarithmic.Standard (
  418.                 dblCounterPartyRecoveryRateDrift,
  419.                 dblCounterPartyRecoveryRateVolatility
  420.             )
  421.         );

  422.         DiffusionEvolver deBankSeniorFundingSpread = new DiffusionEvolver (
  423.             DiffusionEvaluatorLinear.Standard (
  424.                 dblBankSeniorFundingSpreadDrift,
  425.                 dblBankSeniorFundingSpreadVolatility
  426.             )
  427.         );

  428.         DiffusionEvolver deBankSubordinateFundingSpread = new DiffusionEvolver (
  429.             DiffusionEvaluatorLinear.Standard (
  430.                 dblBankSubordinateFundingSpreadDrift,
  431.                 dblBankSubordinateFundingSpreadVolatility
  432.             )
  433.         );

  434.         DiffusionEvolver deCounterPartyFundingSpread = new DiffusionEvolver (
  435.             DiffusionEvaluatorLinear.Standard (
  436.                 dblCounterPartyFundingSpreadDrift,
  437.                 dblCounterPartyFundingSpreadVolatility
  438.             )
  439.         );

  440.         for (int i = 0; i < iNumPath; ++i) {
  441.             double[][] aadblNumeraire = Matrix.Transpose (
  442.                 Path (
  443.                     aadblCorrelation,
  444.                     iNumVertex
  445.                 )
  446.             );

  447.             aadblPortfolio1Value[i] = SwapPortfolioValueRealization (
  448.                 deATMSwapRateOffset,
  449.                 dblATMSwapRateOffsetStart1,
  450.                 aadblNumeraire[0],
  451.                 iNumVertex,
  452.                 dblTime,
  453.                 dblTimeWidth,
  454.                 dblTimeMaturity1,
  455.                 dblSwapNotional1
  456.             );

  457.             aadblPortfolio2Value[i] = SwapPortfolioValueRealization (
  458.                 deATMSwapRateOffset,
  459.                 dblATMSwapRateOffsetStart2,
  460.                 aadblNumeraire[0],
  461.                 iNumVertex,
  462.                 dblTime,
  463.                 dblTimeWidth,
  464.                 dblTimeMaturity2,
  465.                 dblSwapNotional2
  466.             );

  467.             double[] adblOvernightNumeraire = VertexNumeraireRealization (
  468.                 deOvernightNumeraire,
  469.                 dblOvernightNumeraireInitial,
  470.                 dblTime,
  471.                 dblTimeWidth,
  472.                 aadblNumeraire[1],
  473.                 iNumStep
  474.             );

  475.             double[] adblCSA = VertexNumeraireRealization (
  476.                 deCSA,
  477.                 dblCSAInitial,
  478.                 dblTime,
  479.                 dblTimeWidth,
  480.                 aadblNumeraire[2],
  481.                 iNumStep
  482.             );

  483.             double[] adblBankHazardRate = NumeraireValueRealization (
  484.                 deBankHazardRate,
  485.                 dblBankHazardRateInitial,
  486.                 dblTime,
  487.                 dblTimeWidth,
  488.                 aadblNumeraire[3],
  489.                 iNumStep
  490.             );

  491.             double[] adblCounterPartyHazardRate = NumeraireValueRealization (
  492.                 deCounterPartyHazardRate,
  493.                 dblCounterPartyHazardRateInitial,
  494.                 dblTime,
  495.                 dblTimeWidth,
  496.                 aadblNumeraire[4],
  497.                 iNumStep
  498.             );

  499.             double[] adblBankSeniorRecoveryRate = NumeraireValueRealization (
  500.                 deBankSeniorRecoveryRate,
  501.                 dblBankSeniorRecoveryRateInitial,
  502.                 dblTime,
  503.                 dblTimeWidth,
  504.                 aadblNumeraire[5],
  505.                 iNumStep
  506.             );

  507.             double[] adblBankSubordinateRecoveryRate = NumeraireValueRealization (
  508.                 deBankSubordinateRecoveryRate,
  509.                 dblBankSubordinateRecoveryRateInitial,
  510.                 dblTime,
  511.                 dblTimeWidth,
  512.                 aadblNumeraire[6],
  513.                 iNumStep
  514.             );

  515.             double[] adblCounterPartyRecoveryRate = NumeraireValueRealization (
  516.                 deCounterPartyRecoveryRate,
  517.                 dblCounterPartyRecoveryRateInitial,
  518.                 dblTime,
  519.                 dblTimeWidth,
  520.                 aadblNumeraire[7],
  521.                 iNumStep
  522.             );

  523.             double[] adblBankSeniorFundingSpread = NumeraireValueRealization (
  524.                 deBankSeniorFundingSpread,
  525.                 dblBankSeniorFundingSpreadInitial,
  526.                 dblTime,
  527.                 dblTimeWidth,
  528.                 aadblNumeraire[8],
  529.                 iNumStep
  530.             );

  531.             double[] adblBankSubordinateFundingSpread = NumeraireValueRealization (
  532.                 deBankSubordinateFundingSpread,
  533.                 dblBankSubordinateFundingSpreadInitial,
  534.                 dblTime,
  535.                 dblTimeWidth,
  536.                 aadblNumeraire[9],
  537.                 iNumStep
  538.             );

  539.             double[] adblCounterPartyFundingSpread = NumeraireValueRealization (
  540.                 deCounterPartyFundingSpread,
  541.                 dblCounterPartyFundingSpreadInitial,
  542.                 dblTime,
  543.                 dblTimeWidth,
  544.                 aadblNumeraire[10],
  545.                 iNumStep
  546.             );

  547.             JulianDate dtStart = dtSpot;
  548.             MarketVertex[] aMV = new MarketVertex [iNumStep + 1];
  549.             double dblValueStart1 = dblTime * dblATMSwapRateOffsetStart1;
  550.             double dblValueStart2 = dblTime * dblATMSwapRateOffsetStart2;
  551.             CollateralGroupVertex[] aCGV1 = new CollateralGroupVertex[iNumStep + 1];
  552.             CollateralGroupVertex[] aCGV2 = new CollateralGroupVertex[iNumStep + 1];

  553.             for (int j = 0; j <= iNumStep; ++j) {
  554.                 JulianDate dtEnd = (adtVertex[j] = dtSpot.addMonths (6 * j + 6));

  555.                 double dblCollateralBalance1 = 0.;
  556.                 double dblCollateralBalance2 = 0.;
  557.                 double dblValueEnd1 = aadblPortfolio1Value[i][j];
  558.                 double dblValueEnd2 = aadblPortfolio2Value[i][j];

  559.                 CloseOut cog = new CloseOutBilateral (
  560.                     adblBankSeniorRecoveryRate[j],
  561.                     adblCounterPartyRecoveryRate[j]
  562.                 );

  563.                 LatentStateVertexContainer latentStateVertexContainer = new LatentStateVertexContainer();

  564.                 latentStateVertexContainer.add (
  565.                     OTCFixFloatLabel.Standard ("USD-3M-10Y"),
  566.                     Double.NaN
  567.                 );

  568.                 aMV[j] = MarketVertex.Nodal (
  569.                     adtVertex[j] = dtSpot.addMonths (6 * j),
  570.                     dblOvernightNumeraireDrift,
  571.                     adblOvernightNumeraire[j],
  572.                     dblCSADrift,
  573.                     adblCSA[j],
  574.                     new MarketVertexEntity (
  575.                         Math.exp (-0.5 * adblBankHazardRate[j] * j),
  576.                         adblBankHazardRate[j],
  577.                         adblBankSeniorRecoveryRate[j],
  578.                         adblBankSeniorFundingSpread[j],
  579.                         Math.exp (-0.5 * adblBankHazardRate[j] * (1. - adblBankSeniorRecoveryRate[j]) * iNumStep),
  580.                         adblBankSubordinateRecoveryRate[j],
  581.                         adblBankSubordinateFundingSpread[j],
  582.                         Math.exp (-0.5 * adblBankHazardRate[j] * (1. - adblBankSubordinateRecoveryRate[j]) * iNumStep)
  583.                     ),
  584.                     new MarketVertexEntity (
  585.                         Math.exp (-0.5 * adblCounterPartyHazardRate[j] * j),
  586.                         adblCounterPartyHazardRate[j],
  587.                         adblCounterPartyRecoveryRate[j],
  588.                         adblCounterPartyFundingSpread[j],
  589.                         Math.exp (-0.5 * adblCounterPartyHazardRate[j] * (1. - adblCounterPartyRecoveryRate[j]) * iNumStep),
  590.                         Double.NaN,
  591.                         Double.NaN,
  592.                         Double.NaN
  593.                     ),
  594.                     latentStateVertexContainer
  595.                 );

  596.                 if (0 != j) {
  597.                     CollateralAmountEstimator hae1 = new CollateralAmountEstimator (
  598.                         positionGroupSpecification,
  599.                         new BrokenDateInterpolatorLinearT (
  600.                             dtStart.julian(),
  601.                             dtEnd.julian(),
  602.                             dblValueStart1,
  603.                             dblValueEnd1
  604.                         ),
  605.                         Double.NaN
  606.                     );

  607.                     dblCollateralBalance1 = hae1.postingRequirement (dtEnd);

  608.                     CollateralAmountEstimator hae2 = new CollateralAmountEstimator (
  609.                         positionGroupSpecification,
  610.                         new BrokenDateInterpolatorLinearT (
  611.                             dtStart.julian(),
  612.                             dtEnd.julian(),
  613.                             dblValueStart2,
  614.                             dblValueEnd2
  615.                         ),
  616.                         Double.NaN
  617.                     );

  618.                     dblCollateralBalance2 = hae2.postingRequirement (dtEnd);

  619.                     aCGV1[j] = BurgardKjaerBuilder.HedgeErrorDualBond (
  620.                         adtVertex[j],
  621.                         aadblPortfolio1Value[i][j],
  622.                         0.,
  623.                         dblCollateralBalance1,
  624.                         0.,
  625.                         new MarketEdge (
  626.                             aMV[j - 1],
  627.                             aMV[j]
  628.                         ),
  629.                         cog
  630.                     );

  631.                     aCGV2[j] = BurgardKjaerBuilder.HedgeErrorDualBond (
  632.                         adtVertex[j],
  633.                         aadblPortfolio2Value[i][j],
  634.                         0.,
  635.                         dblCollateralBalance2,
  636.                         0.,
  637.                         new MarketEdge (
  638.                             aMV[j - 1],
  639.                             aMV[j]
  640.                         ),
  641.                         cog
  642.                     );
  643.                 } else {
  644.                     aCGV1[j] = BurgardKjaerBuilder.Initial (
  645.                         adtVertex[j],
  646.                         aadblPortfolio1Value[i][0],
  647.                         aMV[j],
  648.                         cog
  649.                     );

  650.                     aCGV2[j] = BurgardKjaerBuilder.Initial (
  651.                         adtVertex[j],
  652.                         aadblPortfolio2Value[i][0],
  653.                         aMV[j],
  654.                         cog
  655.                     );
  656.                 }
  657.             }

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

  659.             CollateralGroupPath[] aHGPGround = new CollateralGroupPath[] {
  660.                 new CollateralGroupPath (
  661.                     aCGV1,
  662.                     mp
  663.                 )
  664.             };

  665.             aMPEAGround[i] = new MonoPathExposureAdjustment (
  666.                 new AlbaneseAndersenFundingGroupPath[] {
  667.                     new AlbaneseAndersenFundingGroupPath (
  668.                         new AlbaneseAndersenNettingGroupPath[] {
  669.                             new AlbaneseAndersenNettingGroupPath (
  670.                                 aHGPGround,
  671.                                 mp
  672.                             )
  673.                         },
  674.                         mp
  675.                     )
  676.                 }
  677.             );

  678.             CollateralGroupPath[] aHGPExtended = new CollateralGroupPath[] {
  679.                 new CollateralGroupPath (
  680.                     aCGV1,
  681.                     mp
  682.                 ),
  683.                 new CollateralGroupPath (
  684.                     aCGV2,
  685.                     mp
  686.                 )
  687.             };

  688.             aMPEAExtended[i] = new MonoPathExposureAdjustment (
  689.                 new AlbaneseAndersenFundingGroupPath[] {
  690.                     new AlbaneseAndersenFundingGroupPath (
  691.                         new AlbaneseAndersenNettingGroupPath[] {
  692.                             new AlbaneseAndersenNettingGroupPath (
  693.                                 aHGPExtended,
  694.                                 mp
  695.                             )
  696.                         },
  697.                         mp
  698.                     )
  699.                 }
  700.             );
  701.         }

  702.         return new ExposureAdjustmentAggregator[] {
  703.             new ExposureAdjustmentAggregator (aMPEAGround),
  704.             new ExposureAdjustmentAggregator (aMPEAExtended)
  705.         };
  706.     }

  707.     private static final void CPGDDump (
  708.         final String strHeader,
  709.         final ExposureAdjustmentDigest ead)
  710.         throws Exception
  711.     {
  712.         System.out.println();

  713.         UnivariateDiscreteThin udtUCOLVA = ead.ucolva();

  714.         UnivariateDiscreteThin udtFTDCOLVA = ead.ftdcolva();

  715.         UnivariateDiscreteThin udtUCVA = ead.ucva();

  716.         UnivariateDiscreteThin udtFTDCVA = ead.ftdcva();

  717.         UnivariateDiscreteThin udtCVACL = ead.cvacl();

  718.         UnivariateDiscreteThin udtCVA = ead.cva();

  719.         UnivariateDiscreteThin udtDVA = ead.dva();

  720.         UnivariateDiscreteThin udtFVA = ead.fva();

  721.         UnivariateDiscreteThin udtFDA = ead.fda();

  722.         UnivariateDiscreteThin udtFCA = ead.fca();

  723.         UnivariateDiscreteThin udtFBA = ead.fba();

  724.         UnivariateDiscreteThin udtSFVA = ead.sfva();

  725.         System.out.println (
  726.             "\t||-----------------------------------------------------------------------------------------------------------------------------------||"
  727.         );

  728.         System.out.println (strHeader);

  729.         System.out.println (
  730.             "\t||-----------------------------------------------------------------------------------------------------------------------------------||"
  731.         );

  732.         System.out.println (
  733.             "\t||  OODLE  => UCOLVA  | FTDCOLVA |  UCVA   | FTDCVA  |  CVACL  |   CVA   |   DVA   |   FVA   |   FDA   |   FCA   |   FBA   |   SFVA  ||"
  734.         );

  735.         System.out.println (
  736.             "\t||-----------------------------------------------------------------------------------------------------------------------------------||"
  737.         );

  738.         System.out.println (
  739.             "\t|| Average => " +
  740.             FormatUtil.FormatDouble (udtUCOLVA.average(), 2, 2, 1.) + "  |  " +
  741.             FormatUtil.FormatDouble (udtFTDCOLVA.average(), 2, 2, 1.) + "  | " +
  742.             FormatUtil.FormatDouble (udtUCVA.average(), 2, 2, 1.) + "  | " +
  743.             FormatUtil.FormatDouble (udtFTDCVA.average(), 2, 2, 1.) + "  | " +
  744.             FormatUtil.FormatDouble (udtCVACL.average(), 2, 2, 1.) + "  | " +
  745.             FormatUtil.FormatDouble (udtCVA.average(), 2, 2, 1.) + "  | " +
  746.             FormatUtil.FormatDouble (udtDVA.average(), 2, 2, 1.) + "  | " +
  747.             FormatUtil.FormatDouble (udtFVA.average(), 2, 2, 1.) + "  | " +
  748.             FormatUtil.FormatDouble (udtFDA.average(), 2, 2, 1.) + "  | " +
  749.             FormatUtil.FormatDouble (udtFCA.average(), 2, 2, 1.) + "  | " +
  750.             FormatUtil.FormatDouble (udtFBA.average(), 2, 2, 1.) + "  | " +
  751.             FormatUtil.FormatDouble (udtSFVA.average(), 2, 2, 1.) + "  ||"
  752.         );

  753.         System.out.println (
  754.             "\t|| Minimum => " +
  755.             FormatUtil.FormatDouble (udtUCOLVA.minimum(), 2, 2, 1.) + "  |  " +
  756.             FormatUtil.FormatDouble (udtFTDCOLVA.minimum(), 2, 2, 1.) + "  | " +
  757.             FormatUtil.FormatDouble (udtUCVA.minimum(), 2, 2, 1.) + "  | " +
  758.             FormatUtil.FormatDouble (udtFTDCVA.minimum(), 2, 2, 1.) + "  | " +
  759.             FormatUtil.FormatDouble (udtCVACL.minimum(), 2, 2, 1.) + "  | " +
  760.             FormatUtil.FormatDouble (udtCVA.minimum(), 2, 2, 1.) + "  | " +
  761.             FormatUtil.FormatDouble (udtDVA.minimum(), 2, 2, 1.) + "  | " +
  762.             FormatUtil.FormatDouble (udtFVA.minimum(), 2, 2, 1.) + "  | " +
  763.             FormatUtil.FormatDouble (udtFDA.minimum(), 2, 2, 1.) + "  | " +
  764.             FormatUtil.FormatDouble (udtFCA.minimum(), 2, 2, 1.) + "  | " +
  765.             FormatUtil.FormatDouble (udtFBA.minimum(), 2, 2, 1.) + "  | " +
  766.             FormatUtil.FormatDouble (udtSFVA.minimum(), 2, 2, 1.) + "  ||"
  767.         );

  768.         System.out.println (
  769.             "\t|| Maximum => " +
  770.             FormatUtil.FormatDouble (udtUCOLVA.maximum(), 2, 2, 1.) + "  |  " +
  771.             FormatUtil.FormatDouble (udtFTDCOLVA.maximum(), 2, 2, 1.) + "  | " +
  772.             FormatUtil.FormatDouble (udtUCVA.maximum(), 2, 2, 1.) + "  | " +
  773.             FormatUtil.FormatDouble (udtFTDCVA.maximum(), 2, 2, 1.) + "  | " +
  774.             FormatUtil.FormatDouble (udtCVACL.maximum(), 2, 2, 1.) + "  | " +
  775.             FormatUtil.FormatDouble (udtCVA.maximum(), 2, 2, 1.) + "  | " +
  776.             FormatUtil.FormatDouble (udtDVA.maximum(), 2, 2, 1.) + "  | " +
  777.             FormatUtil.FormatDouble (udtFVA.maximum(), 2, 2, 1.) + "  | " +
  778.             FormatUtil.FormatDouble (udtFDA.maximum(), 2, 2, 1.) + "  | " +
  779.             FormatUtil.FormatDouble (udtFCA.maximum(), 2, 2, 1.) + "  | " +
  780.             FormatUtil.FormatDouble (udtFBA.maximum(), 2, 2, 1.) + "  | " +
  781.             FormatUtil.FormatDouble (udtSFVA.maximum(), 2, 2, 1.) + "  ||"
  782.         );

  783.         System.out.println (
  784.             "\t||  Error  => " +
  785.             FormatUtil.FormatDouble (udtUCOLVA.error(), 2, 2, 1.) + "  |  " +
  786.             FormatUtil.FormatDouble (udtFTDCOLVA.error(), 2, 2, 1.) + "  | " +
  787.             FormatUtil.FormatDouble (udtUCVA.error(), 2, 2, 1.) + "  | " +
  788.             FormatUtil.FormatDouble (udtFTDCVA.error(), 2, 2, 1.) + "  | " +
  789.             FormatUtil.FormatDouble (udtCVACL.error(), 2, 2, 1.) + "  | " +
  790.             FormatUtil.FormatDouble (udtCVA.error(), 2, 2, 1.) + "  | " +
  791.             FormatUtil.FormatDouble (udtDVA.error(), 2, 2, 1.) + "  | " +
  792.             FormatUtil.FormatDouble (udtFVA.error(), 2, 2, 1.) + "  | " +
  793.             FormatUtil.FormatDouble (udtFDA.error(), 2, 2, 1.) + "  | " +
  794.             FormatUtil.FormatDouble (udtFCA.error(), 2, 2, 1.) + "  | " +
  795.             FormatUtil.FormatDouble (udtFBA.error(), 2, 2, 1.) + "  | " +
  796.             FormatUtil.FormatDouble (udtSFVA.error(), 2, 2, 1.) + "  ||"
  797.         );

  798.         System.out.println (
  799.             "\t||-----------------------------------------------------------------------------------------------------------------------------------||"
  800.         );
  801.     }

  802.     private static final void CPGDDiffDump (
  803.         final String strHeader,
  804.         final ExposureAdjustmentDigest eadGround,
  805.         final ExposureAdjustmentDigest eadExpanded)
  806.         throws Exception
  807.     {
  808.         System.out.println();

  809.         System.out.println (
  810.             "\t||-----------------------------------------------------------------------------------------------------------------------------------||"
  811.         );

  812.         System.out.println (strHeader);

  813.         System.out.println (
  814.             "\t||-----------------------------------------------------------------------------------------------------------------------------------||"
  815.         );

  816.         System.out.println (
  817.             "\t||  OODLE  => UCOLVA  | FTDCOLVA |  UCVA   | FTDCVA  |  CVACL  |   CVA   |   DVA   |   FVA   |   FDA   |   FCA   |   FBA   |   SFVA  ||"
  818.         );

  819.         System.out.println (
  820.             "\t||-----------------------------------------------------------------------------------------------------------------------------------||"
  821.         );

  822.         System.out.println (
  823.             "\t|| Average => " +
  824.             FormatUtil.FormatDouble (eadExpanded.ucolva().average() - eadGround.ucolva().average(), 3, 1, 10000.) + "  |  " +
  825.             FormatUtil.FormatDouble (eadExpanded.ftdcolva().average() - eadGround.ftdcolva().average(), 3, 1, 10000.) + "  | " +
  826.             FormatUtil.FormatDouble (eadExpanded.ucva().average() - eadGround.ucva().average(), 3, 1, 10000.) + "  | " +
  827.             FormatUtil.FormatDouble (eadExpanded.ftdcva().average() - eadGround.ftdcva().average(), 3, 1, 10000.) + "  | " +
  828.             FormatUtil.FormatDouble (eadExpanded.cvacl().average() - eadGround.cvacl().average(), 3, 1, 10000.) + "  | " +
  829.             FormatUtil.FormatDouble (eadExpanded.cva().average() - eadGround.cva().average(), 3, 1, 10000.) + "  | " +
  830.             FormatUtil.FormatDouble (eadExpanded.dva().average() - eadGround.dva().average(), 3, 1, 10000.) + "  | " +
  831.             FormatUtil.FormatDouble (eadExpanded.fva().average() - eadGround.fva().average(), 3, 1, 10000.) + "  | " +
  832.             FormatUtil.FormatDouble (eadExpanded.fda().average() - eadGround.fda().average(), 3, 1, 10000.) + "  | " +
  833.             FormatUtil.FormatDouble (eadExpanded.fca().average() - eadGround.fca().average(), 3, 1, 10000.) + "  | " +
  834.             FormatUtil.FormatDouble (eadExpanded.fba().average() - eadGround.fba().average(), 3, 1, 10000.) + "  | " +
  835.             FormatUtil.FormatDouble (eadExpanded.sfva().average() - eadGround.sfva().average(), 3, 1, 10000.) + "  ||"
  836.         );

  837.         System.out.println (
  838.             "\t||-----------------------------------------------------------------------------------------------------------------------------------||"
  839.         );
  840.     }

  841.     private static final void BaselAccountingMetrics (
  842.         final String strHeader,
  843.         final ExposureAdjustmentAggregator eaaGround,
  844.         final ExposureAdjustmentAggregator eaaExpanded)
  845.         throws Exception
  846.     {
  847.         OTCAccountingModus oasFCAFBA = new OTCAccountingModusFCAFBA (eaaGround);

  848.         OTCAccountingModus oasFVAFDA = new OTCAccountingModusFVAFDA (eaaGround);

  849.         OTCAccountingPolicy oapFCAFBA = oasFCAFBA.feePolicy (eaaExpanded);

  850.         OTCAccountingPolicy oapFVAFDA = oasFVAFDA.feePolicy (eaaExpanded);

  851.         System.out.println();

  852.         System.out.println (
  853.             "\t||---------------------------------------------------------------------||"
  854.         );

  855.         System.out.println (strHeader);

  856.         System.out.println (
  857.             "\t||---------------------------------------------------------------------||"
  858.         );

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

  862.         System.out.println (
  863.             "\t||         - Accounting Type (FCA/FBA vs. FVA/FDA)                     ||"
  864.         );

  865.         System.out.println (
  866.             "\t||         - Contra Asset Adjustment                                   ||"
  867.         );

  868.         System.out.println (
  869.             "\t||         - Contra Liability Adjustment                               ||"
  870.         );

  871.         System.out.println (
  872.             "\t||         - FTP (Funding Transfer Pricing) (bp)                       ||"
  873.         );

  874.         System.out.println (
  875.             "\t||         - CET1 (Common Equity Tier I) Change (bp)                   ||"
  876.         );

  877.         System.out.println (
  878.             "\t||         - CL (Contra Liability) Change (bp)                         ||"
  879.         );

  880.         System.out.println (
  881.             "\t||         - PFV (Porfolio Value) Change (Income) (bp)                 ||"
  882.         );

  883.         System.out.println (
  884.             "\t||---------------------------------------------------------------------||"
  885.         );

  886.         System.out.println ("\t|| FCA/FBA Accounting => " +
  887.             FormatUtil.FormatDouble (oasFCAFBA.contraAssetAdjustment(), 1, 4, 1.) + " | " +
  888.             FormatUtil.FormatDouble (oasFCAFBA.contraLiabilityAdjustment(), 1, 4, 1.) + " | " +
  889.             FormatUtil.FormatDouble (oapFCAFBA.fundingTransferPricing(), 3, 0, 10000.) + " | " +
  890.             FormatUtil.FormatDouble (oapFCAFBA.cet1Change(), 3, 0, 10000.) + " | " +
  891.             FormatUtil.FormatDouble (oapFCAFBA.contraLiabilityChange(), 3, 0, 10000.) + " | " +
  892.             FormatUtil.FormatDouble (oapFCAFBA.portfolioValueChange(), 3, 0, 10000.) + " || "
  893.         );

  894.         System.out.println ("\t|| FVA/FDA Accounting => " +
  895.             FormatUtil.FormatDouble (oasFVAFDA.contraAssetAdjustment(), 1, 4, 1.) + " | " +
  896.             FormatUtil.FormatDouble (oasFVAFDA.contraLiabilityAdjustment(), 1, 4, 1.) + " | " +
  897.             FormatUtil.FormatDouble (oapFVAFDA.fundingTransferPricing(), 3, 0, 10000.) + " | " +
  898.             FormatUtil.FormatDouble (oapFVAFDA.cet1Change(), 3, 0, 10000.) + " | " +
  899.             FormatUtil.FormatDouble (oapFVAFDA.contraLiabilityChange(), 3, 0, 10000.) + " | " +
  900.             FormatUtil.FormatDouble (oapFVAFDA.portfolioValueChange(), 3, 0, 10000.) + " || "
  901.         );

  902.         System.out.println (
  903.             "\t||---------------------------------------------------------------------||"
  904.         );

  905.         System.out.println();
  906.     }

  907.     public static final void main (
  908.         final String[] astrArgs)
  909.         throws Exception
  910.     {
  911.         EnvManager.InitEnv ("");

  912.         ExposureAdjustmentAggregator[] aCPGA = Mix (
  913.             5.,
  914.             0.,
  915.             100.,
  916.             5.,
  917.             0.,
  918.             1.
  919.         );

  920.         ExposureAdjustmentAggregator eaaGround = aCPGA[0];
  921.         ExposureAdjustmentAggregator eaaExtended = aCPGA[1];

  922.         ExposureAdjustmentDigest eadGround = eaaGround.digest();

  923.         ExposureAdjustmentDigest eadExtended = eaaExtended.digest();

  924.         CPGDDump (
  925.             "\t||                                                  GROUND BOOK ADJUSTMENT METRICS                                                   ||",
  926.             eadGround
  927.         );

  928.         CPGDDump (
  929.             "\t||                                                 EXTENDED BOOK ADJUSTMENT METRICS                                                  ||",
  930.             eadExtended
  931.         );

  932.         CPGDDiffDump (
  933.             "\t||                                             TRADE INCREMENT ADJUSTMENT METRICS (bp)                                               ||",
  934.             eadGround,
  935.             eadExtended
  936.         );

  937.         BaselAccountingMetrics (
  938.             "\t||           ALBANESE & ANDERSEN (2015) BCBS OTC ACCOUNTING            ||",
  939.             eaaGround,
  940.             eaaExtended
  941.         );

  942.         EnvManager.TerminateEnv();
  943.     }
  944. }