SetOffUncollateralizedFunding.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>SetOffUncollateralizedFunding</i> examines the Basel BCBS 2012 OTC Accounting Impact to a Portfolio of
  96.  * 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 - 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         - Set Off
  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 SetOffUncollateralizedFunding {

  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.SetOff (
  323.                         adtVertex[j],
  324.                         aadblPortfolio1Value[i][j],
  325.                         0.,
  326.                         0.,
  327.                         new MarketEdge (
  328.                             aMV[j - 1],
  329.                             aMV[j]
  330.                         )
  331.                     );

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

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

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

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

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

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

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

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

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

  412.         UnivariateDiscreteThin udtUCOLVA = ead.ucolva();

  413.         UnivariateDiscreteThin udtFTDCOLVA = ead.ftdcolva();

  414.         UnivariateDiscreteThin udtUCVA = ead.ucva();

  415.         UnivariateDiscreteThin udtFTDCVA = ead.ftdcva();

  416.         UnivariateDiscreteThin udtCVACL = ead.cvacl();

  417.         UnivariateDiscreteThin udtCVA = ead.cva();

  418.         UnivariateDiscreteThin udtDVA = ead.dva();

  419.         UnivariateDiscreteThin udtFVA = ead.fva();

  420.         UnivariateDiscreteThin udtFDA = ead.fda();

  421.         UnivariateDiscreteThin udtFCA = ead.fca();

  422.         UnivariateDiscreteThin udtFBA = ead.fba();

  423.         UnivariateDiscreteThin udtSFVA = ead.sfva();

  424.         System.out.println (
  425.             "\t||-----------------------------------------------------------------------------------------------------------------------------------||"
  426.         );

  427.         System.out.println (strHeader);

  428.         System.out.println (
  429.             "\t||-----------------------------------------------------------------------------------------------------------------------------------||"
  430.         );

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

  434.         System.out.println (
  435.             "\t||-----------------------------------------------------------------------------------------------------------------------------------||"
  436.         );

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

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

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

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

  497.         System.out.println (
  498.             "\t||-----------------------------------------------------------------------------------------------------------------------------------||"
  499.         );
  500.     }

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

  508.         System.out.println (
  509.             "\t||-----------------------------------------------------------------------------------------------------------------------------------||"
  510.         );

  511.         System.out.println (strHeader);

  512.         System.out.println (
  513.             "\t||-----------------------------------------------------------------------------------------------------------------------------------||"
  514.         );

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

  518.         System.out.println (
  519.             "\t||-----------------------------------------------------------------------------------------------------------------------------------||"
  520.         );

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

  536.         System.out.println (
  537.             "\t||-----------------------------------------------------------------------------------------------------------------------------------||"
  538.         );
  539.     }

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

  547.         OTCAccountingModus oasFVAFDA = new OTCAccountingModusFVAFDA (cpgaGround);

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

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

  550.         System.out.println();

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

  554.         System.out.println (strHeader);

  555.         System.out.println (
  556.             "\t||---------------------------------------------------------------------||"
  557.         );

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

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

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

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

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

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

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

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

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

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

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

  601.         System.out.println (
  602.             "\t||---------------------------------------------------------------------||"
  603.         );

  604.         System.out.println();
  605.     }

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

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

  619.         ExposureAdjustmentAggregator cpgaGround = aCPGA[0];
  620.         ExposureAdjustmentAggregator cpgaExtended = aCPGA[1];

  621.         ExposureAdjustmentDigest cpgdGround = cpgaGround.digest();

  622.         ExposureAdjustmentDigest cpgdExtended = cpgaExtended.digest();

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

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

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

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

  641.         EnvManager.TerminateEnv();
  642.     }
  643. }