BilateralCSAZeroThresholdFunding.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>BilateralCSAZeroThresholdFunding</i> examines the Basel BCBS 2012 OTC Accounting Impact to a Portfolio
  96.  * of 10 Swaps resulting from the Addition of a New Swap - Comparison via both FVA/FDA and FCA/FBA Schemes.
  97.  * Simulation is carried out under the following Criteria using one of the Generalized Burgard Kjaer (2013)
  98.  * Scheme.
  99.  *  
  100.  * <br><br>
  101.  *  <ul>
  102.  *      <li>
  103.  *          Collateralization Status - Zero Threshold
  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         - Gold Plated Two Way CSA
  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 BilateralCSAZeroThresholdFunding {

  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.         MarketVertex[] aMV = new MarketVertex[iNumStep + 1];
  241.         JulianDate[] adtVertex = new JulianDate[iNumStep + 1];
  242.         double[][] aadblPortfolio1Value = new double[iNumPath][iNumStep + 1];
  243.         double[][] aadblPortfolio2Value = new double[iNumPath][iNumStep + 1];
  244.         MonoPathExposureAdjustment[] aCPGPGround = new MonoPathExposureAdjustment[iNumPath];
  245.         MonoPathExposureAdjustment[] aCPGPExtended = new MonoPathExposureAdjustment[iNumPath];
  246.         double dblBankSeniorFundingSpread = dblBankHazardRate / (1. - dblBankSeniorRecoveryRate);
  247.         double dblBankSubordinateFundingSpread = dblBankHazardRate / (1. - dblBankSubordinateRecoveryRate);
  248.         double dblCounterPartyFundingSpread = dblCounterPartyHazardRate / (1. - dblCounterPartyRecoveryRate);

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

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

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

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

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

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

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

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

  318.             for (int j = 0; j <= iNumStep; ++j) {
  319.                 if (0 != j) {
  320.                     aCGV1[j] = BurgardKjaerBuilder.GoldPlatedTwoWayCSA (
  321.                         adtVertex[j],
  322.                         aadblPortfolio1Value[i][j],
  323.                         0.,
  324.                         new MarketEdge (
  325.                             aMV[j - 1],
  326.                             aMV[j]
  327.                         ),
  328.                         cog
  329.                     );

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

  347.                     aCGV2[j] = BurgardKjaerBuilder.Initial (
  348.                         adtVertex[j],
  349.                         aadblPortfolio2Value[i][0],
  350.                         aMV[j],
  351.                         cog
  352.                     );
  353.                 }
  354.             }

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

  356.             CollateralGroupPath[] aCGP1 = new CollateralGroupPath[] {
  357.                 new CollateralGroupPath (
  358.                     aCGV1,
  359.                     np
  360.                 )
  361.             };

  362.             CollateralGroupPath[] aCGP2 = new CollateralGroupPath[] {
  363.                 new CollateralGroupPath (
  364.                     aCGV2,
  365.                     np
  366.                 )
  367.             };

  368.             aCPGPGround[i] = new MonoPathExposureAdjustment (
  369.                 new AlbaneseAndersenFundingGroupPath[] {
  370.                     new AlbaneseAndersenFundingGroupPath (
  371.                         new AlbaneseAndersenNettingGroupPath[] {
  372.                             new AlbaneseAndersenNettingGroupPath (
  373.                                 aCGP1,
  374.                                 np
  375.                             )
  376.                         },
  377.                         np
  378.                     )
  379.                 }
  380.             );

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

  399.         return new ExposureAdjustmentAggregator[] {
  400.             new ExposureAdjustmentAggregator (aCPGPGround),
  401.             new ExposureAdjustmentAggregator (aCPGPExtended)
  402.         };
  403.     }

  404.     private static final void CPGDDump (
  405.         final String strHeader,
  406.         final ExposureAdjustmentDigest ead)
  407.         throws Exception
  408.     {
  409.         System.out.println();

  410.         UnivariateDiscreteThin udtUCOLVA = ead.ucolva();

  411.         UnivariateDiscreteThin udtFTDCOLVA = ead.ftdcolva();

  412.         UnivariateDiscreteThin udtUCVA = ead.ucva();

  413.         UnivariateDiscreteThin udtFTDCVA = ead.ftdcva();

  414.         UnivariateDiscreteThin udtCVACL = ead.cvacl();

  415.         UnivariateDiscreteThin udtCVA = ead.cva();

  416.         UnivariateDiscreteThin udtDVA = ead.dva();

  417.         UnivariateDiscreteThin udtFVA = ead.fva();

  418.         UnivariateDiscreteThin udtFDA = ead.fda();

  419.         UnivariateDiscreteThin udtFCA = ead.fca();

  420.         UnivariateDiscreteThin udtFBA = ead.fba();

  421.         UnivariateDiscreteThin udtSFVA = ead.sfva();

  422.         System.out.println (
  423.             "\t||-----------------------------------------------------------------------------------------------------------------------------------||"
  424.         );

  425.         System.out.println (strHeader);

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

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

  432.         System.out.println (
  433.             "\t||-----------------------------------------------------------------------------------------------------------------------------------||"
  434.         );

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

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

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

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

  495.         System.out.println (
  496.             "\t||-----------------------------------------------------------------------------------------------------------------------------------||"
  497.         );
  498.     }

  499.     private static final void CPGDDiffDump (
  500.         final String strHeader,
  501.         final ExposureAdjustmentDigest eadGround,
  502.         final ExposureAdjustmentDigest eadExpanded)
  503.         throws Exception
  504.     {
  505.         System.out.println();

  506.         System.out.println (
  507.             "\t||-----------------------------------------------------------------------------------------------------------------------------------||"
  508.         );

  509.         System.out.println (strHeader);

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

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

  516.         System.out.println (
  517.             "\t||-----------------------------------------------------------------------------------------------------------------------------------||"
  518.         );

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

  534.         System.out.println (
  535.             "\t||-----------------------------------------------------------------------------------------------------------------------------------||"
  536.         );
  537.     }

  538.     private static final void BaselAccountingMetrics (
  539.         final String strHeader,
  540.         final ExposureAdjustmentAggregator cpgaGround,
  541.         final ExposureAdjustmentAggregator cpgaExpanded)
  542.         throws Exception
  543.     {
  544.         OTCAccountingModus oasFCAFBA = new OTCAccountingModusFCAFBA (cpgaGround);

  545.         OTCAccountingModus oasFVAFDA = new OTCAccountingModusFVAFDA (cpgaGround);

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

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

  548.         System.out.println();

  549.         System.out.println (
  550.             "\t||---------------------------------------------------------------------||"
  551.         );

  552.         System.out.println (strHeader);

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

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

  559.         System.out.println (
  560.             "\t||         - Accounting Type (FCA/FBA vs. FVA/FDA)                     ||"
  561.         );

  562.         System.out.println (
  563.             "\t||         - Contra Asset Adjustment                                   ||"
  564.         );

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

  568.         System.out.println (
  569.             "\t||         - FTP (Funding Transfer Pricing) (bp)                       ||"
  570.         );

  571.         System.out.println (
  572.             "\t||         - CET1 (Common Equity Tier I) Change (bp)                   ||"
  573.         );

  574.         System.out.println (
  575.             "\t||         - CL (Contra Liability) Change (bp)                         ||"
  576.         );

  577.         System.out.println (
  578.             "\t||         - PFV (Porfolio Value) Change (Income) (bp)                 ||"
  579.         );

  580.         System.out.println (
  581.             "\t||---------------------------------------------------------------------||"
  582.         );

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

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

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

  602.         System.out.println();
  603.     }

  604.     public static final void main (
  605.         final String[] astrArgs)
  606.         throws Exception
  607.     {
  608.         EnvManager.InitEnv ("");

  609.         ExposureAdjustmentAggregator[] aCPGA = Mix (
  610.             5.,
  611.             0.,
  612.             100.,
  613.             5.,
  614.             0.,
  615.             1.
  616.         );

  617.         ExposureAdjustmentAggregator cpgaGround = aCPGA[0];
  618.         ExposureAdjustmentAggregator cpgaExtended = aCPGA[1];

  619.         ExposureAdjustmentDigest cpgdGround = cpgaGround.digest();

  620.         ExposureAdjustmentDigest cpgdExtended = cpgaExtended.digest();

  621.         CPGDDump (
  622.             "\t||                                                  GROUND BOOK ADJUSTMENT METRICS                                                   ||",
  623.             cpgdGround
  624.         );

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

  629.         CPGDDiffDump (
  630.             "\t||                                             TRADE INCREMENT ADJUSTMENT METRICS (bp)                                               ||",
  631.             cpgdGround,
  632.             cpgdExtended
  633.         );

  634.         BaselAccountingMetrics (
  635.             "\t||           ALBANESE & ANDERSEN (2015) BCBS OTC ACCOUNTING            ||",
  636.             cpgaGround,
  637.             cpgaExtended
  638.         );

  639.         EnvManager.TerminateEnv();
  640.     }
  641. }