SemiReplicationUncollateralizedFunding.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.universe.*;
  5. import org.drip.measure.discrete.SequenceGenerator;
  6. import org.drip.measure.dynamics.DiffusionEvaluatorLinear;
  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.service.env.EnvManager;
  12. import org.drip.state.identifier.OTCFixFloatLabel;
  13. import org.drip.xva.basel.*;
  14. import org.drip.xva.definition.*;
  15. import org.drip.xva.gross.*;
  16. import org.drip.xva.hypothecation.*;
  17. import org.drip.xva.netting.CollateralGroupPath;
  18. import org.drip.xva.strategy.*;
  19. import org.drip.xva.vertex.BurgardKjaerBuilder;

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

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

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

  156. public class SemiReplicationUncollateralizedFunding {

  157.     private static final double[] ATMSwapRateOffsetRealization (
  158.         final DiffusionEvolver deATMSwapRateOffset,
  159.         final double dblATMSwapRateOffsetInitial,
  160.         final double[] adblRandom,
  161.         final double dblTime,
  162.         final double dblTimeWidth,
  163.         final int iNumStep)
  164.         throws Exception
  165.     {
  166.         double[] adblATMSwapRateOffset = new double[iNumStep + 1];
  167.         adblATMSwapRateOffset[0] = dblATMSwapRateOffsetInitial;
  168.         double[] adblTimeWidth = new double[iNumStep];

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


  171.         JumpDiffusionEdge[] aJDE = deATMSwapRateOffset.incrementSequence (
  172.             new JumpDiffusionVertex (
  173.                 dblTime,
  174.                 dblATMSwapRateOffsetInitial,
  175.                 0.,
  176.                 false
  177.             ),
  178.             JumpDiffusionEdgeUnit.Diffusion (
  179.                 adblTimeWidth,
  180.                 adblRandom
  181.             ),
  182.             dblTimeWidth
  183.         );

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

  186.         return adblATMSwapRateOffset;
  187.     }

  188.     private static final double[] SwapPortfolioValueRealization (
  189.         final DiffusionEvolver deATMSwapRate,
  190.         final double dblATMSwapRateStart,
  191.         final double[] adblRandom,
  192.         final int iNumStep,
  193.         final double dblTime,
  194.         final double dblTimeWidth,
  195.         final double dblTimeMaturity,
  196.         final double dblSwapNotional)
  197.         throws Exception
  198.     {
  199.         double[] adblSwapPortfolioValueRealization = new double[iNumStep + 1];
  200.         int iMaturityStep = (int) (dblTimeMaturity / dblTimeWidth);

  201.         for (int i = 0; i < iNumStep; ++i)
  202.             adblSwapPortfolioValueRealization[i] = 0.;

  203.         double[] adblATMSwapRateOffsetRealization = ATMSwapRateOffsetRealization (
  204.             deATMSwapRate,
  205.             dblATMSwapRateStart,
  206.             adblRandom,
  207.             dblTime,
  208.             dblTimeWidth,
  209.             iNumStep
  210.         );

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

  214.         return adblSwapPortfolioValueRealization;
  215.     }

  216.     private static final ExposureAdjustmentAggregator[] Mix (
  217.         final double dblTimeMaturity1,
  218.         final double dblATMSwapRateOffsetStart1,
  219.         final double dblSwapNotional1,
  220.         final double dblTimeMaturity2,
  221.         final double dblATMSwapRateOffsetStart2,
  222.         final double dblSwapNotional2)
  223.         throws Exception
  224.     {
  225.         int iNumStep = 10;
  226.         int iNumPath = 100000;
  227.         int iNumVertex = 10;
  228.         double dblTime = 5.;
  229.         double dblATMSwapRateOffsetDrift = 0.0;
  230.         double dblATMSwapRateOffsetVolatility = 0.25;
  231.         double dblOvernightNumeraireDrift = 0.004;
  232.         double dblCSADrift = 0.01;
  233.         double dblBankHazardRate = 0.015;
  234.         double dblBankSeniorRecoveryRate = 0.40;
  235.         double dblBankSubordinateRecoveryRate = 0.15;
  236.         double dblCounterPartyHazardRate = 0.030;
  237.         double dblCounterPartyRecoveryRate = 0.30;

  238.         JulianDate dtSpot = DateUtil.Today();

  239.         double dblTimeWidth = dblTime / iNumStep;
  240.         JulianDate[] adtVertex = new JulianDate[iNumStep + 1];
  241.         MarketVertex[] aMV = new MarketVertex[iNumStep + 1];
  242.         double[][] aadblPortfolio1Value = new double[iNumPath][iNumStep + 1];
  243.         double[][] aadblPortfolio2Value = new double[iNumPath][iNumStep + 1];
  244.         double[][] aadblCollateralBalance = new double[iNumPath][iNumStep + 1];
  245.         MonoPathExposureAdjustment[] aCPGPGround = new MonoPathExposureAdjustment[iNumPath];
  246.         MonoPathExposureAdjustment[] aCPGPExtended = new MonoPathExposureAdjustment[iNumPath];
  247.         double dblBankSeniorFundingSpread = dblBankHazardRate / (1. - dblBankSeniorRecoveryRate);
  248.         double dblBankSubordinateFundingSpread = dblBankHazardRate / (1. - dblBankSubordinateRecoveryRate);
  249.         double dblCounterPartyFundingSpread = dblCounterPartyHazardRate / (1. - dblCounterPartyRecoveryRate);

  250.         CloseOut cog = new CloseOutBilateral (
  251.             dblBankSeniorRecoveryRate,
  252.             dblCounterPartyRecoveryRate
  253.         );

  254.         DiffusionEvolver deATMSwapRateOffset = new DiffusionEvolver (
  255.             DiffusionEvaluatorLinear.Standard (
  256.                 dblATMSwapRateOffsetDrift,
  257.                 dblATMSwapRateOffsetVolatility
  258.             )
  259.         );

  260.         for (int i = 0; i <= iNumStep; ++i)
  261.         {
  262.             LatentStateVertexContainer latentStateVertexContainer = new LatentStateVertexContainer();

  263.             latentStateVertexContainer.add (
  264.                 OTCFixFloatLabel.Standard ("USD-3M-10Y"),
  265.                 Double.NaN
  266.             );

  267.             aMV[i] = MarketVertex.Nodal (
  268.                 adtVertex[i] = dtSpot.addMonths (6 * i),
  269.                 dblOvernightNumeraireDrift,
  270.                 Math.exp (-0.5 * dblOvernightNumeraireDrift * iNumStep),
  271.                 dblCSADrift,
  272.                 Math.exp (-0.5 * dblCSADrift * iNumStep),
  273.                 new MarketVertexEntity (
  274.                     Math.exp (-0.5 * dblBankHazardRate * i),
  275.                     dblBankHazardRate,
  276.                     dblBankSeniorRecoveryRate,
  277.                     dblBankSeniorFundingSpread,
  278.                     Math.exp (-0.5 * dblBankHazardRate * (1. - dblBankSeniorRecoveryRate) * iNumStep),
  279.                     dblBankSubordinateRecoveryRate,
  280.                     dblBankSubordinateFundingSpread,
  281.                     Math.exp (-0.5 * dblBankHazardRate * (1. - dblBankSubordinateRecoveryRate) * iNumStep)
  282.                 ),
  283.                 new MarketVertexEntity (
  284.                     Math.exp (-0.5 * dblCounterPartyHazardRate * i),
  285.                     dblCounterPartyHazardRate,
  286.                     dblCounterPartyRecoveryRate,
  287.                     dblCounterPartyFundingSpread,
  288.                     Math.exp (-0.5 * dblCounterPartyHazardRate * (1. - dblCounterPartyRecoveryRate) * iNumStep),
  289.                     Double.NaN,
  290.                     Double.NaN,
  291.                     Double.NaN
  292.                 ),
  293.                 latentStateVertexContainer
  294.             );
  295.         }

  296.         for (int i = 0; i < iNumPath; ++i) {
  297.             aadblPortfolio1Value[i] = SwapPortfolioValueRealization (
  298.                 deATMSwapRateOffset,
  299.                 dblATMSwapRateOffsetStart1,
  300.                 SequenceGenerator.Gaussian (iNumStep),
  301.                 iNumVertex,
  302.                 dblTime,
  303.                 dblTimeWidth,
  304.                 dblTimeMaturity1,
  305.                 dblSwapNotional1
  306.             );

  307.             aadblPortfolio2Value[i] = SwapPortfolioValueRealization (
  308.                 deATMSwapRateOffset,
  309.                 dblATMSwapRateOffsetStart2,
  310.                 SequenceGenerator.Gaussian (iNumStep),
  311.                 iNumVertex,
  312.                 dblTime,
  313.                 dblTimeWidth,
  314.                 dblTimeMaturity2,
  315.                 dblSwapNotional2
  316.             );

  317.             CollateralGroupVertex[] aCGV1 = new CollateralGroupVertex[iNumStep + 1];
  318.             CollateralGroupVertex[] aCGV2 = new CollateralGroupVertex[iNumStep + 1];

  319.             for (int j = 0; j <= iNumStep; ++j) {
  320.                 aadblCollateralBalance[i][j] = 0.;

  321.                 if (0 != j) {
  322.                     aCGV1[j] = BurgardKjaerBuilder.SemiReplicationDualBond (
  323.                         adtVertex[j],
  324.                         aadblPortfolio1Value[i][j],
  325.                         0.,
  326.                         0.,
  327.                         new MarketEdge (
  328.                             aMV[j - 1],
  329.                             aMV[j]
  330.                         ),
  331.                         cog
  332.                     );

  333.                     aCGV2[j] = BurgardKjaerBuilder.SemiReplicationDualBond (
  334.                         adtVertex[j],
  335.                         aadblPortfolio2Value[i][j],
  336.                         0.,
  337.                         0.,
  338.                         new MarketEdge (
  339.                             aMV[j - 1],
  340.                             aMV[j]
  341.                         ),
  342.                         cog
  343.                     );
  344.                 } else {
  345.                     aCGV1[j] = BurgardKjaerBuilder.Initial (
  346.                         adtVertex[j],
  347.                         aadblPortfolio1Value[i][0],
  348.                         aMV[j],
  349.                         cog
  350.                     );

  351.                     aCGV2[j] = BurgardKjaerBuilder.Initial (
  352.                         adtVertex[j],
  353.                         aadblPortfolio2Value[i][0],
  354.                         aMV[j],
  355.                         cog
  356.                     );
  357.                 }
  358.             }

  359.             MarketPath np = MarketPath.FromMarketVertexArray (aMV);

  360.             CollateralGroupPath[] aCGP1 = new CollateralGroupPath[] {
  361.                 new CollateralGroupPath (
  362.                     aCGV1,
  363.                     np
  364.                 )
  365.             };

  366.             CollateralGroupPath[] aCGP2 = new CollateralGroupPath[] {
  367.                 new CollateralGroupPath (
  368.                     aCGV2,
  369.                     np
  370.                 )
  371.             };

  372.             aCPGPGround[i] = new MonoPathExposureAdjustment (
  373.                 new AlbaneseAndersenFundingGroupPath[] {
  374.                     new AlbaneseAndersenFundingGroupPath (
  375.                         new AlbaneseAndersenNettingGroupPath[] {
  376.                             new AlbaneseAndersenNettingGroupPath (
  377.                                 aCGP1,
  378.                                 np
  379.                             )
  380.                         },
  381.                         np
  382.                     )
  383.                 }
  384.             );

  385.             aCPGPExtended[i] = new MonoPathExposureAdjustment (
  386.                 new AlbaneseAndersenFundingGroupPath[] {
  387.                     new AlbaneseAndersenFundingGroupPath (
  388.                         new AlbaneseAndersenNettingGroupPath[] {
  389.                             new AlbaneseAndersenNettingGroupPath (
  390.                                 aCGP1,
  391.                                 np
  392.                             ),
  393.                             new AlbaneseAndersenNettingGroupPath (
  394.                                 aCGP2,
  395.                                 np
  396.                             )
  397.                         },
  398.                         np
  399.                     )
  400.                 }
  401.             );
  402.         }

  403.         return new ExposureAdjustmentAggregator[] {
  404.             new ExposureAdjustmentAggregator (aCPGPGround),
  405.             new ExposureAdjustmentAggregator (aCPGPExtended)
  406.         };
  407.     }

  408.     private static final void CPGDDump (
  409.         final String strHeader,
  410.         final ExposureAdjustmentDigest ead)
  411.         throws Exception
  412.     {
  413.         System.out.println();

  414.         UnivariateDiscreteThin udtUCOLVA = ead.ucolva();

  415.         UnivariateDiscreteThin udtFTDCOLVA = ead.ftdcolva();

  416.         UnivariateDiscreteThin udtUCVA = ead.ucva();

  417.         UnivariateDiscreteThin udtFTDCVA = ead.ftdcva();

  418.         UnivariateDiscreteThin udtCVACL = ead.cvacl();

  419.         UnivariateDiscreteThin udtCVA = ead.cva();

  420.         UnivariateDiscreteThin udtDVA = ead.dva();

  421.         UnivariateDiscreteThin udtFVA = ead.fva();

  422.         UnivariateDiscreteThin udtFDA = ead.fda();

  423.         UnivariateDiscreteThin udtFCA = ead.fca();

  424.         UnivariateDiscreteThin udtFBA = ead.fba();

  425.         UnivariateDiscreteThin udtSFVA = ead.sfva();

  426.         System.out.println (
  427.             "\t||-----------------------------------------------------------------------------------------------------------------------------------||"
  428.         );

  429.         System.out.println (strHeader);

  430.         System.out.println (
  431.             "\t||-----------------------------------------------------------------------------------------------------------------------------------||"
  432.         );

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

  436.         System.out.println (
  437.             "\t||-----------------------------------------------------------------------------------------------------------------------------------||"
  438.         );

  439.         System.out.println (
  440.             "\t|| Average => " +
  441.             FormatUtil.FormatDouble (udtUCOLVA.average(), 2, 2, 1.) + "  |  " +
  442.             FormatUtil.FormatDouble (udtFTDCOLVA.average(), 2, 2, 1.) + "  | " +
  443.             FormatUtil.FormatDouble (udtUCVA.average(), 2, 2, 1.) + "  | " +
  444.             FormatUtil.FormatDouble (udtFTDCVA.average(), 2, 2, 1.) + "  | " +
  445.             FormatUtil.FormatDouble (udtCVACL.average(), 2, 2, 1.) + "  | " +
  446.             FormatUtil.FormatDouble (udtCVA.average(), 2, 2, 1.) + "  | " +
  447.             FormatUtil.FormatDouble (udtDVA.average(), 2, 2, 1.) + "  | " +
  448.             FormatUtil.FormatDouble (udtFVA.average(), 2, 2, 1.) + "  | " +
  449.             FormatUtil.FormatDouble (udtFDA.average(), 2, 2, 1.) + "  | " +
  450.             FormatUtil.FormatDouble (udtFCA.average(), 2, 2, 1.) + "  | " +
  451.             FormatUtil.FormatDouble (udtFBA.average(), 2, 2, 1.) + "  | " +
  452.             FormatUtil.FormatDouble (udtSFVA.average(), 2, 2, 1.) + "  ||"
  453.         );

  454.         System.out.println (
  455.             "\t|| Minimum => " +
  456.             FormatUtil.FormatDouble (udtUCOLVA.minimum(), 2, 2, 1.) + "  |  " +
  457.             FormatUtil.FormatDouble (udtFTDCOLVA.minimum(), 2, 2, 1.) + "  | " +
  458.             FormatUtil.FormatDouble (udtUCVA.minimum(), 2, 2, 1.) + "  | " +
  459.             FormatUtil.FormatDouble (udtFTDCVA.minimum(), 2, 2, 1.) + "  | " +
  460.             FormatUtil.FormatDouble (udtCVACL.minimum(), 2, 2, 1.) + "  | " +
  461.             FormatUtil.FormatDouble (udtCVA.minimum(), 2, 2, 1.) + "  | " +
  462.             FormatUtil.FormatDouble (udtDVA.minimum(), 2, 2, 1.) + "  | " +
  463.             FormatUtil.FormatDouble (udtFVA.minimum(), 2, 2, 1.) + "  | " +
  464.             FormatUtil.FormatDouble (udtFDA.minimum(), 2, 2, 1.) + "  | " +
  465.             FormatUtil.FormatDouble (udtFCA.minimum(), 2, 2, 1.) + "  | " +
  466.             FormatUtil.FormatDouble (udtFBA.minimum(), 2, 2, 1.) + "  | " +
  467.             FormatUtil.FormatDouble (udtSFVA.minimum(), 2, 2, 1.) + "  ||"
  468.         );

  469.         System.out.println (
  470.             "\t|| Maximum => " +
  471.             FormatUtil.FormatDouble (udtUCOLVA.maximum(), 2, 2, 1.) + "  |  " +
  472.             FormatUtil.FormatDouble (udtFTDCOLVA.maximum(), 2, 2, 1.) + "  | " +
  473.             FormatUtil.FormatDouble (udtUCVA.maximum(), 2, 2, 1.) + "  | " +
  474.             FormatUtil.FormatDouble (udtFTDCVA.maximum(), 2, 2, 1.) + "  | " +
  475.             FormatUtil.FormatDouble (udtCVACL.maximum(), 2, 2, 1.) + "  | " +
  476.             FormatUtil.FormatDouble (udtCVA.maximum(), 2, 2, 1.) + "  | " +
  477.             FormatUtil.FormatDouble (udtDVA.maximum(), 2, 2, 1.) + "  | " +
  478.             FormatUtil.FormatDouble (udtFVA.maximum(), 2, 2, 1.) + "  | " +
  479.             FormatUtil.FormatDouble (udtFDA.maximum(), 2, 2, 1.) + "  | " +
  480.             FormatUtil.FormatDouble (udtFCA.maximum(), 2, 2, 1.) + "  | " +
  481.             FormatUtil.FormatDouble (udtFBA.maximum(), 2, 2, 1.) + "  | " +
  482.             FormatUtil.FormatDouble (udtSFVA.maximum(), 2, 2, 1.) + "  ||"
  483.         );

  484.         System.out.println (
  485.             "\t||  Error  => " +
  486.             FormatUtil.FormatDouble (udtUCOLVA.error(), 2, 2, 1.) + "  |  " +
  487.             FormatUtil.FormatDouble (udtFTDCOLVA.error(), 2, 2, 1.) + "  | " +
  488.             FormatUtil.FormatDouble (udtUCVA.error(), 2, 2, 1.) + "  | " +
  489.             FormatUtil.FormatDouble (udtFTDCVA.error(), 2, 2, 1.) + "  | " +
  490.             FormatUtil.FormatDouble (udtCVACL.error(), 2, 2, 1.) + "  | " +
  491.             FormatUtil.FormatDouble (udtCVA.error(), 2, 2, 1.) + "  | " +
  492.             FormatUtil.FormatDouble (udtDVA.error(), 2, 2, 1.) + "  | " +
  493.             FormatUtil.FormatDouble (udtFVA.error(), 2, 2, 1.) + "  | " +
  494.             FormatUtil.FormatDouble (udtFDA.error(), 2, 2, 1.) + "  | " +
  495.             FormatUtil.FormatDouble (udtFCA.error(), 2, 2, 1.) + "  | " +
  496.             FormatUtil.FormatDouble (udtFBA.error(), 2, 2, 1.) + "  | " +
  497.             FormatUtil.FormatDouble (udtSFVA.error(), 2, 2, 1.) + "  ||"
  498.         );

  499.         System.out.println (
  500.             "\t||-----------------------------------------------------------------------------------------------------------------------------------||"
  501.         );
  502.     }

  503.     private static final void CPGDDiffDump (
  504.         final String strHeader,
  505.         final ExposureAdjustmentDigest eadGround,
  506.         final ExposureAdjustmentDigest eadExpanded)
  507.         throws Exception
  508.     {
  509.         System.out.println();

  510.         System.out.println (
  511.             "\t||-----------------------------------------------------------------------------------------------------------------------------------||"
  512.         );

  513.         System.out.println (strHeader);

  514.         System.out.println (
  515.             "\t||-----------------------------------------------------------------------------------------------------------------------------------||"
  516.         );

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

  520.         System.out.println (
  521.             "\t||-----------------------------------------------------------------------------------------------------------------------------------||"
  522.         );

  523.         System.out.println (
  524.             "\t|| Average => " +
  525.             FormatUtil.FormatDouble (eadExpanded.ucolva().average() - eadGround.ucolva().average(), 3, 1, 10000.) + "  |  " +
  526.             FormatUtil.FormatDouble (eadExpanded.ftdcolva().average() - eadGround.ftdcolva().average(), 3, 1, 10000.) + "  | " +
  527.             FormatUtil.FormatDouble (eadExpanded.ucva().average() - eadGround.ucva().average(), 3, 1, 10000.) + "  | " +
  528.             FormatUtil.FormatDouble (eadExpanded.ftdcva().average() - eadGround.ftdcva().average(), 3, 1, 10000.) + "  | " +
  529.             FormatUtil.FormatDouble (eadExpanded.cvacl().average() - eadGround.cvacl().average(), 3, 1, 10000.) + "  | " +
  530.             FormatUtil.FormatDouble (eadExpanded.cva().average() - eadGround.cva().average(), 3, 1, 10000.) + "  | " +
  531.             FormatUtil.FormatDouble (eadExpanded.dva().average() - eadGround.dva().average(), 3, 1, 10000.) + "  | " +
  532.             FormatUtil.FormatDouble (eadExpanded.fva().average() - eadGround.fva().average(), 3, 1, 10000.) + "  | " +
  533.             FormatUtil.FormatDouble (eadExpanded.fda().average() - eadGround.fda().average(), 3, 1, 10000.) + "  | " +
  534.             FormatUtil.FormatDouble (eadExpanded.fca().average() - eadGround.fca().average(), 3, 1, 10000.) + "  | " +
  535.             FormatUtil.FormatDouble (eadExpanded.fba().average() - eadGround.fba().average(), 3, 1, 10000.) + "  | " +
  536.             FormatUtil.FormatDouble (eadExpanded.sfva().average() - eadGround.sfva().average(), 3, 1, 10000.) + "  ||"
  537.         );

  538.         System.out.println (
  539.             "\t||-----------------------------------------------------------------------------------------------------------------------------------||"
  540.         );
  541.     }

  542.     private static final void BaselAccountingMetrics (
  543.         final String strHeader,
  544.         final ExposureAdjustmentAggregator cpgaGround,
  545.         final ExposureAdjustmentAggregator cpgaExpanded)
  546.         throws Exception
  547.     {
  548.         OTCAccountingModus oasFCAFBA = new OTCAccountingModusFCAFBA (cpgaGround);

  549.         OTCAccountingModus oasFVAFDA = new OTCAccountingModusFVAFDA (cpgaGround);

  550.         OTCAccountingPolicy oapFCAFBA = oasFCAFBA.feePolicy (cpgaExpanded);

  551.         OTCAccountingPolicy oapFVAFDA = oasFVAFDA.feePolicy (cpgaExpanded);

  552.         System.out.println();

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

  556.         System.out.println (strHeader);

  557.         System.out.println (
  558.             "\t||---------------------------------------------------------------------||"
  559.         );

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

  563.         System.out.println (
  564.             "\t||         - Accounting Type (FCA/FBA vs. FVA/FDA)                     ||"
  565.         );

  566.         System.out.println (
  567.             "\t||         - Contra Asset Adjustment                                   ||"
  568.         );

  569.         System.out.println (
  570.             "\t||         - Contra Liability Adjustment                               ||"
  571.         );

  572.         System.out.println (
  573.             "\t||         - FTP (Funding Transfer Pricing) (bp)                       ||"
  574.         );

  575.         System.out.println (
  576.             "\t||         - CET1 (Common Equity Tier I) Change (bp)                   ||"
  577.         );

  578.         System.out.println (
  579.             "\t||         - CL (Contra Liability) Change (bp)                         ||"
  580.         );

  581.         System.out.println (
  582.             "\t||         - PFV (Porfolio Value) Change (Income) (bp)                 ||"
  583.         );

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

  587.         System.out.println ("\t|| FCA/FBA Accounting => " +
  588.             FormatUtil.FormatDouble (oasFCAFBA.contraAssetAdjustment(), 1, 4, 1.) + " | " +
  589.             FormatUtil.FormatDouble (oasFCAFBA.contraLiabilityAdjustment(), 1, 4, 1.) + " | " +
  590.             FormatUtil.FormatDouble (oapFCAFBA.fundingTransferPricing(), 3, 0, 10000.) + " | " +
  591.             FormatUtil.FormatDouble (oapFCAFBA.cet1Change(), 3, 0, 10000.) + " | " +
  592.             FormatUtil.FormatDouble (oapFCAFBA.contraLiabilityChange(), 3, 0, 10000.) + " | " +
  593.             FormatUtil.FormatDouble (oapFCAFBA.portfolioValueChange(), 3, 0, 10000.) + " || "
  594.         );

  595.         System.out.println ("\t|| FVA/FDA Accounting => " +
  596.             FormatUtil.FormatDouble (oasFVAFDA.contraAssetAdjustment(), 1, 4, 1.) + " | " +
  597.             FormatUtil.FormatDouble (oasFVAFDA.contraLiabilityAdjustment(), 1, 4, 1.) + " | " +
  598.             FormatUtil.FormatDouble (oapFVAFDA.fundingTransferPricing(), 3, 0, 10000.) + " | " +
  599.             FormatUtil.FormatDouble (oapFVAFDA.cet1Change(), 3, 0, 10000.) + " | " +
  600.             FormatUtil.FormatDouble (oapFVAFDA.contraLiabilityChange(), 3, 0, 10000.) + " | " +
  601.             FormatUtil.FormatDouble (oapFVAFDA.portfolioValueChange(), 3, 0, 10000.) + " || "
  602.         );

  603.         System.out.println (
  604.             "\t||---------------------------------------------------------------------||"
  605.         );

  606.         System.out.println();
  607.     }

  608.     public static final void main (
  609.         final String[] astrArgs)
  610.         throws Exception
  611.     {
  612.         EnvManager.InitEnv ("");

  613.         ExposureAdjustmentAggregator[] aCPGA = Mix (
  614.             5.,
  615.             0.,
  616.             100.,
  617.             5.,
  618.             0.,
  619.             1.
  620.         );

  621.         ExposureAdjustmentAggregator cpgaGround = aCPGA[0];
  622.         ExposureAdjustmentAggregator cpgaExtended = aCPGA[1];

  623.         ExposureAdjustmentDigest cpgdGround = cpgaGround.digest();

  624.         ExposureAdjustmentDigest cpgdExtended = cpgaExtended.digest();

  625.         CPGDDump (
  626.             "\t||                                                  GROUND BOOK ADJUSTMENT METRICS                                                   ||",
  627.             cpgdGround
  628.         );

  629.         CPGDDump (
  630.             "\t||                                                 EXTENDED BOOK ADJUSTMENT METRICS                                                  ||",
  631.             cpgdExtended
  632.         );

  633.         CPGDDiffDump (
  634.             "\t||                                             TRADE INCREMENT ADJUSTMENT METRICS (bp)                                               ||",
  635.             cpgdGround,
  636.             cpgdExtended
  637.         );

  638.         BaselAccountingMetrics (
  639.             "\t||           ALBANESE & ANDERSEN (2015) BCBS OTC ACCOUNTING            ||",
  640.             cpgaGround,
  641.             cpgaExtended
  642.         );

  643.         EnvManager.TerminateEnv();
  644.     }
  645. }