UncollateralizedCollateralReceivable.java

  1. package org.drip.sample.xvabasel;

  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.*;
  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.gross.*;
  15. import org.drip.xva.netting.CollateralGroupPath;
  16. import org.drip.xva.strategy.*;
  17. import org.drip.xva.vertex.AlbaneseAndersen;

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

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

  62. /**
  63.  * UncollateralizedCollateralReceivable examines the Basel BCBS 2012 OTC Accounting Impact to a Portfolio of
  64.  *  10 Swaps resulting from the Addition of a New Swap - Comparison via both FVA/FDA and FCA/FBA Schemes.
  65.  *  Simulation is carried out under the following Criteria:
  66.  *  
  67.  *    - Collateralization Status - Uncollateralized
  68.  *    - Aggregation Unit         - Collateral Group
  69.  *    - Added Swap Type          - Negative Upfront Swap (Receivable)
  70.  *    - Market Dynamics          - Deterministic (Static Market Evolution)
  71.  *  
  72.  *  
  73.  *  The References are:
  74.  *  
  75.  *  - Burgard, C., and M. Kjaer (2014): PDE Representations of Derivatives with Bilateral Counter-party Risk
  76.  *      and Funding Costs, Journal of Credit Risk, 7 (3) 1-19.
  77.  *  
  78.  *  - Burgard, C., and M. Kjaer (2014): In the Balance, Risk, 24 (11) 72-75.
  79.  *  
  80.  *  - Gregory, J. (2009): Being Two-faced over Counter-party Credit Risk, Risk 20 (2) 86-90.
  81.  *  
  82.  *  - Li, B., and Y. Tang (2007): Quantitative Analysis, Derivatives Modeling, and Trading Strategies in the
  83.  *      Presence of Counter-party Credit Risk for the Fixed Income Market, World Scientific Publishing,
  84.  *      Singapore.
  85.  *
  86.  *  - Piterbarg, V. (2010): Funding Beyond Discounting: Collateral Agreements and Derivatives Pricing, Risk
  87.  *      21 (2) 97-102.
  88.  *
  89.  * @author Lakshmi Krishnamurthy
  90.  */

  91. public class UncollateralizedCollateralReceivable {

  92.     private static final double[] ATMSwapRateOffsetRealization (
  93.         final DiffusionEvolver deATMSwapRateOffset,
  94.         final double dblATMSwapRateOffsetInitial,
  95.         final double[] adblRandom,
  96.         final double dblTime,
  97.         final double dblTimeWidth,
  98.         final int iNumStep)
  99.         throws Exception
  100.     {
  101.         double[] adblATMSwapRateOffset = new double[iNumStep + 1];
  102.         adblATMSwapRateOffset[0] = dblATMSwapRateOffsetInitial;
  103.         double[] adblTimeWidth = new double[iNumStep];

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

  106.         JumpDiffusionEdge[] aJDE = deATMSwapRateOffset.incrementSequence (
  107.             new JumpDiffusionVertex (
  108.                 dblTime,
  109.                 dblATMSwapRateOffsetInitial,
  110.                 0.,
  111.                 false
  112.             ),
  113.             JumpDiffusionEdgeUnit.Diffusion (
  114.                 adblTimeWidth,
  115.                 adblRandom
  116.             ),
  117.             dblTimeWidth
  118.         );

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

  121.         return adblATMSwapRateOffset;
  122.     }

  123.     private static final double[] SwapPortfolioValueRealization (
  124.         final DiffusionEvolver deATMSwapRate,
  125.         final double dblATMSwapRateStart,
  126.         final double[] adblRandom,
  127.         final int iNumStep,
  128.         final double dblTime,
  129.         final double dblTimeWidth,
  130.         final double dblTimeMaturity,
  131.         final double dblSwapNotional)
  132.         throws Exception
  133.     {
  134.         double[] adblSwapPortfolioValueRealization = new double[iNumStep + 1];
  135.         int iMaturityStep = (int) (dblTimeMaturity / dblTimeWidth);

  136.         for (int i = 0; i < iNumStep; ++i)
  137.             adblSwapPortfolioValueRealization[i] = 0.;

  138.         double[] adblATMSwapRateOffsetRealization = ATMSwapRateOffsetRealization (
  139.             deATMSwapRate,
  140.             dblATMSwapRateStart,
  141.             adblRandom,
  142.             dblTime,
  143.             dblTimeWidth,
  144.             iNumStep
  145.         );

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

  149.         return adblSwapPortfolioValueRealization;
  150.     }

  151.     private static final ExposureAdjustmentAggregator[] Mix (
  152.         final double dblTimeMaturity1,
  153.         final double dblATMSwapRateOffsetStart1,
  154.         final double dblSwapNotional1,
  155.         final double dblTimeMaturity2,
  156.         final double dblATMSwapRateOffsetStart2,
  157.         final double dblSwapNotional2)
  158.         throws Exception
  159.     {
  160.         int iNumStep = 10;
  161.         int iNumPath = 100000;
  162.         int iNumVertex = 10;
  163.         double dblTime = 5.;
  164.         double dblATMSwapRateOffsetDrift = 0.0;
  165.         double dblATMSwapRateOffsetVolatility = 0.25;
  166.         double dblOvernightNumeraireDrift = 0.004;
  167.         double dblCSADrift = 0.01;
  168.         double dblBankHazardRate = 0.015;
  169.         double dblBankRecoveryRate = 0.40;
  170.         double dblCounterPartyHazardRate = 0.030;
  171.         double dblCounterPartyRecoveryRate = 0.30;

  172.         JulianDate dtSpot = DateUtil.Today();

  173.         double dblTimeWidth = dblTime / iNumStep;
  174.         JulianDate[] adtVertex = new JulianDate[iNumStep + 1];
  175.         MarketVertex[] aNV = new MarketVertex[iNumStep + 1];
  176.         double[][] aadblPortfolio1Value = new double[iNumPath][iNumStep + 1];
  177.         double[][] aadblPortfolio2Value = new double[iNumPath][iNumStep + 1];
  178.         double[][] aadblCollateralBalance = new double[iNumPath][iNumStep + 1];
  179.         double dblBankFundingSpread = dblBankHazardRate / (1. - dblBankRecoveryRate);
  180.         MonoPathExposureAdjustment[] aCPGPGround = new MonoPathExposureAdjustment[iNumPath];
  181.         MonoPathExposureAdjustment[] aCPGPExtended = new MonoPathExposureAdjustment[iNumPath];
  182.         double dblCounterPartyFundingSpread = dblCounterPartyHazardRate / (1. - dblCounterPartyRecoveryRate);

  183.         DiffusionEvolver deATMSwapRateOffset = new DiffusionEvolver (
  184.             DiffusionEvaluatorLinear.Standard (
  185.                 dblATMSwapRateOffsetDrift,
  186.                 dblATMSwapRateOffsetVolatility
  187.             )
  188.         );

  189.         for (int i = 0; i <= iNumStep; ++i)
  190.         {
  191.             LatentStateVertexContainer latentStateVertexContainer = new LatentStateVertexContainer();

  192.             latentStateVertexContainer.add (
  193.                 OTCFixFloatLabel.Standard ("USD-3M-10Y"),
  194.                 Double.NaN
  195.             );

  196.             aNV[i] = MarketVertex.Nodal (
  197.                 adtVertex[i] = dtSpot.addMonths (6 * i),
  198.                 dblOvernightNumeraireDrift,
  199.                 Math.exp (-0.5 * dblOvernightNumeraireDrift * iNumStep),
  200.                 dblCSADrift,
  201.                 Math.exp (-0.5 * dblCSADrift * iNumStep),
  202.                 new MarketVertexEntity (
  203.                     Math.exp (-0.5 * dblBankHazardRate * i),
  204.                     dblBankHazardRate,
  205.                     dblBankRecoveryRate,
  206.                     dblBankFundingSpread,
  207.                     Math.exp (-0.5 * dblBankHazardRate * (1. - dblBankRecoveryRate) * iNumStep),
  208.                     Double.NaN,
  209.                     Double.NaN,
  210.                     Double.NaN
  211.                 ),
  212.                 new MarketVertexEntity (
  213.                     Math.exp (-0.5 * dblCounterPartyHazardRate * i),
  214.                     dblCounterPartyHazardRate,
  215.                     dblCounterPartyRecoveryRate,
  216.                     dblCounterPartyFundingSpread,
  217.                     Math.exp (-0.5 * dblCounterPartyHazardRate * (1. - dblCounterPartyRecoveryRate) * iNumStep),
  218.                     Double.NaN,
  219.                     Double.NaN,
  220.                     Double.NaN
  221.                 ),
  222.                 latentStateVertexContainer
  223.             );
  224.         }

  225.         for (int i = 0; i < iNumPath; ++i) {
  226.             aadblPortfolio1Value[i] = SwapPortfolioValueRealization (
  227.                 deATMSwapRateOffset,
  228.                 dblATMSwapRateOffsetStart1,
  229.                 SequenceGenerator.Gaussian (iNumStep),
  230.                 iNumVertex,
  231.                 dblTime,
  232.                 dblTimeWidth,
  233.                 dblTimeMaturity1,
  234.                 dblSwapNotional1
  235.             );

  236.             aadblPortfolio2Value[i] = SwapPortfolioValueRealization (
  237.                 deATMSwapRateOffset,
  238.                 dblATMSwapRateOffsetStart2,
  239.                 SequenceGenerator.Gaussian (iNumStep),
  240.                 iNumVertex,
  241.                 dblTime,
  242.                 dblTimeWidth,
  243.                 dblTimeMaturity2,
  244.                 dblSwapNotional2
  245.             );

  246.             AlbaneseAndersen[] aCGV1 = new AlbaneseAndersen[iNumStep + 1];
  247.             AlbaneseAndersen[] aCGV2 = new AlbaneseAndersen[iNumStep + 1];

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

  250.                 aCGV1[j] = new AlbaneseAndersen (
  251.                     adtVertex[j],
  252.                     aadblPortfolio1Value[i][j],
  253.                     0.,
  254.                     0.
  255.                 );

  256.                 aCGV2[j] = new AlbaneseAndersen (
  257.                     adtVertex[j],
  258.                     aadblPortfolio2Value[i][j],
  259.                     0.,
  260.                     0.
  261.                 );
  262.             }

  263.             MarketPath np = MarketPath.FromMarketVertexArray (aNV);

  264.             CollateralGroupPath[] aCGPGround = new CollateralGroupPath[] {
  265.                 new CollateralGroupPath (
  266.                     aCGV1,
  267.                     np
  268.                 )
  269.             };

  270.             CollateralGroupPath[] aCGPExtended = new CollateralGroupPath[] {
  271.                 new CollateralGroupPath (
  272.                     aCGV2,
  273.                     np
  274.                 )
  275.             };

  276.             aCPGPGround[i] = new MonoPathExposureAdjustment (
  277.                 new AlbaneseAndersenFundingGroupPath[] {
  278.                     new AlbaneseAndersenFundingGroupPath (
  279.                         new AlbaneseAndersenNettingGroupPath[] {
  280.                             new AlbaneseAndersenNettingGroupPath (
  281.                                 aCGPGround,
  282.                                 np
  283.                             )
  284.                         },
  285.                         np
  286.                     )
  287.                 }
  288.             );

  289.             aCPGPExtended[i] = new MonoPathExposureAdjustment (
  290.                 new AlbaneseAndersenFundingGroupPath[] {
  291.                     new AlbaneseAndersenFundingGroupPath (
  292.                         new AlbaneseAndersenNettingGroupPath[] {
  293.                             new AlbaneseAndersenNettingGroupPath (
  294.                                 aCGPGround,
  295.                                 np
  296.                             ),
  297.                             new AlbaneseAndersenNettingGroupPath (
  298.                                 aCGPExtended,
  299.                                 np
  300.                             )
  301.                         },
  302.                         np
  303.                     )
  304.                 }
  305.             );
  306.         }

  307.         return new ExposureAdjustmentAggregator[] {
  308.             new ExposureAdjustmentAggregator (aCPGPGround),
  309.             new ExposureAdjustmentAggregator (aCPGPExtended)
  310.         };
  311.     }

  312.     private static final void CPGDDump (
  313.         final String strHeader,
  314.         final ExposureAdjustmentDigest ead)
  315.         throws Exception
  316.     {
  317.         System.out.println();

  318.         UnivariateDiscreteThin udtUCOLVA = ead.ucolva();

  319.         UnivariateDiscreteThin udtFTDCOLVA = ead.ftdcolva();

  320.         UnivariateDiscreteThin udtUCVA = ead.ucva();

  321.         UnivariateDiscreteThin udtFTDCVA = ead.ftdcva();

  322.         UnivariateDiscreteThin udtCVACL = ead.cvacl();

  323.         UnivariateDiscreteThin udtCVA = ead.cva();

  324.         UnivariateDiscreteThin udtDVA = ead.dva();

  325.         UnivariateDiscreteThin udtFVA = ead.fva();

  326.         UnivariateDiscreteThin udtFDA = ead.fda();

  327.         UnivariateDiscreteThin udtFCA = ead.fca();

  328.         UnivariateDiscreteThin udtFBA = ead.fba();

  329.         UnivariateDiscreteThin udtSFVA = ead.sfva();

  330.         System.out.println (
  331.             "\t||-----------------------------------------------------------------------------------------------------------------------------------||"
  332.         );

  333.         System.out.println (strHeader);

  334.         System.out.println (
  335.             "\t||-----------------------------------------------------------------------------------------------------------------------------------||"
  336.         );

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

  340.         System.out.println (
  341.             "\t||-----------------------------------------------------------------------------------------------------------------------------------||"
  342.         );

  343.         System.out.println (
  344.             "\t|| Average => " +
  345.             FormatUtil.FormatDouble (udtUCOLVA.average(), 2, 2, 1.) + "  |  " +
  346.             FormatUtil.FormatDouble (udtFTDCOLVA.average(), 2, 2, 1.) + "  | " +
  347.             FormatUtil.FormatDouble (udtUCVA.average(), 2, 2, 1.) + "  | " +
  348.             FormatUtil.FormatDouble (udtFTDCVA.average(), 2, 2, 1.) + "  | " +
  349.             FormatUtil.FormatDouble (udtCVACL.average(), 2, 2, 1.) + "  | " +
  350.             FormatUtil.FormatDouble (udtCVA.average(), 2, 2, 1.) + "  | " +
  351.             FormatUtil.FormatDouble (udtDVA.average(), 2, 2, 1.) + "  | " +
  352.             FormatUtil.FormatDouble (udtFVA.average(), 2, 2, 1.) + "  | " +
  353.             FormatUtil.FormatDouble (udtFDA.average(), 2, 2, 1.) + "  | " +
  354.             FormatUtil.FormatDouble (udtFCA.average(), 2, 2, 1.) + "  | " +
  355.             FormatUtil.FormatDouble (udtFBA.average(), 2, 2, 1.) + "  | " +
  356.             FormatUtil.FormatDouble (udtSFVA.average(), 2, 2, 1.) + "  ||"
  357.         );

  358.         System.out.println (
  359.             "\t|| Minimum => " +
  360.             FormatUtil.FormatDouble (udtUCOLVA.minimum(), 2, 2, 1.) + "  |  " +
  361.             FormatUtil.FormatDouble (udtFTDCOLVA.minimum(), 2, 2, 1.) + "  | " +
  362.             FormatUtil.FormatDouble (udtUCVA.minimum(), 2, 2, 1.) + "  | " +
  363.             FormatUtil.FormatDouble (udtFTDCVA.minimum(), 2, 2, 1.) + "  | " +
  364.             FormatUtil.FormatDouble (udtCVACL.minimum(), 2, 2, 1.) + "  | " +
  365.             FormatUtil.FormatDouble (udtCVA.minimum(), 2, 2, 1.) + "  | " +
  366.             FormatUtil.FormatDouble (udtDVA.minimum(), 2, 2, 1.) + "  | " +
  367.             FormatUtil.FormatDouble (udtFVA.minimum(), 2, 2, 1.) + "  | " +
  368.             FormatUtil.FormatDouble (udtFDA.minimum(), 2, 2, 1.) + "  | " +
  369.             FormatUtil.FormatDouble (udtFCA.minimum(), 2, 2, 1.) + "  | " +
  370.             FormatUtil.FormatDouble (udtFBA.minimum(), 2, 2, 1.) + "  | " +
  371.             FormatUtil.FormatDouble (udtSFVA.minimum(), 2, 2, 1.) + "  ||"
  372.         );

  373.         System.out.println (
  374.             "\t|| Maximum => " +
  375.             FormatUtil.FormatDouble (udtUCOLVA.maximum(), 2, 2, 1.) + "  |  " +
  376.             FormatUtil.FormatDouble (udtFTDCOLVA.maximum(), 2, 2, 1.) + "  | " +
  377.             FormatUtil.FormatDouble (udtUCVA.maximum(), 2, 2, 1.) + "  | " +
  378.             FormatUtil.FormatDouble (udtFTDCVA.maximum(), 2, 2, 1.) + "  | " +
  379.             FormatUtil.FormatDouble (udtCVACL.maximum(), 2, 2, 1.) + "  | " +
  380.             FormatUtil.FormatDouble (udtCVA.maximum(), 2, 2, 1.) + "  | " +
  381.             FormatUtil.FormatDouble (udtDVA.maximum(), 2, 2, 1.) + "  | " +
  382.             FormatUtil.FormatDouble (udtFVA.maximum(), 2, 2, 1.) + "  | " +
  383.             FormatUtil.FormatDouble (udtFDA.maximum(), 2, 2, 1.) + "  | " +
  384.             FormatUtil.FormatDouble (udtFCA.maximum(), 2, 2, 1.) + "  | " +
  385.             FormatUtil.FormatDouble (udtFBA.maximum(), 2, 2, 1.) + "  | " +
  386.             FormatUtil.FormatDouble (udtSFVA.maximum(), 2, 2, 1.) + "  ||"
  387.         );

  388.         System.out.println (
  389.             "\t||  Error  => " +
  390.             FormatUtil.FormatDouble (udtUCOLVA.error(), 2, 2, 1.) + "  |  " +
  391.             FormatUtil.FormatDouble (udtFTDCOLVA.error(), 2, 2, 1.) + "  | " +
  392.             FormatUtil.FormatDouble (udtUCVA.error(), 2, 2, 1.) + "  | " +
  393.             FormatUtil.FormatDouble (udtFTDCVA.error(), 2, 2, 1.) + "  | " +
  394.             FormatUtil.FormatDouble (udtCVACL.error(), 2, 2, 1.) + "  | " +
  395.             FormatUtil.FormatDouble (udtCVA.error(), 2, 2, 1.) + "  | " +
  396.             FormatUtil.FormatDouble (udtDVA.error(), 2, 2, 1.) + "  | " +
  397.             FormatUtil.FormatDouble (udtFVA.error(), 2, 2, 1.) + "  | " +
  398.             FormatUtil.FormatDouble (udtFDA.error(), 2, 2, 1.) + "  | " +
  399.             FormatUtil.FormatDouble (udtFCA.error(), 2, 2, 1.) + "  | " +
  400.             FormatUtil.FormatDouble (udtFBA.error(), 2, 2, 1.) + "  | " +
  401.             FormatUtil.FormatDouble (udtSFVA.error(), 2, 2, 1.) + "  ||"
  402.         );

  403.         System.out.println (
  404.             "\t||-----------------------------------------------------------------------------------------------------------------------------------||"
  405.         );
  406.     }

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

  414.         System.out.println (
  415.             "\t||-----------------------------------------------------------------------------------------------------------------------------------||"
  416.         );

  417.         System.out.println (strHeader);

  418.         System.out.println (
  419.             "\t||-----------------------------------------------------------------------------------------------------------------------------------||"
  420.         );

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

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

  427.         System.out.println (
  428.             "\t|| Average => " +
  429.             FormatUtil.FormatDouble (eadExpanded.ucolva().average() - eadGround.ucolva().average(), 3, 1, 10000.) + "  |  " +
  430.             FormatUtil.FormatDouble (eadExpanded.ftdcolva().average() - eadGround.ftdcolva().average(), 3, 1, 10000.) + "  | " +
  431.             FormatUtil.FormatDouble (eadExpanded.ucva().average() - eadGround.ucva().average(), 3, 1, 10000.) + "  | " +
  432.             FormatUtil.FormatDouble (eadExpanded.ftdcva().average() - eadGround.ftdcva().average(), 3, 1, 10000.) + "  | " +
  433.             FormatUtil.FormatDouble (eadExpanded.cvacl().average() - eadGround.cvacl().average(), 3, 1, 10000.) + "  | " +
  434.             FormatUtil.FormatDouble (eadExpanded.cva().average() - eadGround.cva().average(), 3, 1, 10000.) + "  | " +
  435.             FormatUtil.FormatDouble (eadExpanded.dva().average() - eadGround.dva().average(), 3, 1, 10000.) + "  | " +
  436.             FormatUtil.FormatDouble (eadExpanded.fva().average() - eadGround.fva().average(), 3, 1, 10000.) + "  | " +
  437.             FormatUtil.FormatDouble (eadExpanded.fda().average() - eadGround.fda().average(), 3, 1, 10000.) + "  | " +
  438.             FormatUtil.FormatDouble (eadExpanded.fca().average() - eadGround.fca().average(), 3, 1, 10000.) + "  | " +
  439.             FormatUtil.FormatDouble (eadExpanded.fba().average() - eadGround.fba().average(), 3, 1, 10000.) + "  | " +
  440.             FormatUtil.FormatDouble (eadExpanded.sfva().average() - eadGround.sfva().average(), 3, 1, 10000.) + "  ||"
  441.         );

  442.         System.out.println (
  443.             "\t||-----------------------------------------------------------------------------------------------------------------------------------||"
  444.         );
  445.     }

  446.     private static final void BaselAccountingMetrics (
  447.         final String strHeader,
  448.         final ExposureAdjustmentAggregator cpgaGround,
  449.         final ExposureAdjustmentAggregator cpgaExpanded)
  450.         throws Exception
  451.     {
  452.         OTCAccountingModus oasFCAFBA = new OTCAccountingModusFCAFBA (cpgaGround);

  453.         OTCAccountingModus oasFVAFDA = new OTCAccountingModusFVAFDA (cpgaGround);

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

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

  456.         System.out.println();

  457.         System.out.println (
  458.             "\t||---------------------------------------------------------------------||"
  459.         );

  460.         System.out.println (strHeader);

  461.         System.out.println (
  462.             "\t||---------------------------------------------------------------------||"
  463.         );

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

  467.         System.out.println (
  468.             "\t||         - Accounting Type (FCA/FBA vs. FVA/FDA)                     ||"
  469.         );

  470.         System.out.println (
  471.             "\t||         - Contra Asset Adjustment                                   ||"
  472.         );

  473.         System.out.println (
  474.             "\t||         - Contra Liability Adjustment                               ||"
  475.         );

  476.         System.out.println (
  477.             "\t||         - FTP (Funding Transfer Pricing) (bp)                       ||"
  478.         );

  479.         System.out.println (
  480.             "\t||         - CET1 (Common Equity Tier I) Change (bp)                   ||"
  481.         );

  482.         System.out.println (
  483.             "\t||         - CL (Contra Liability) Change (bp)                         ||"
  484.         );

  485.         System.out.println (
  486.             "\t||         - PFV (Porfolio Value) Change (Income) (bp)                 ||"
  487.         );

  488.         System.out.println (
  489.             "\t||---------------------------------------------------------------------||"
  490.         );

  491.         System.out.println ("\t|| FCA/FBA Accounting => " +
  492.             FormatUtil.FormatDouble (oasFCAFBA.contraAssetAdjustment(), 1, 4, 1.) + " | " +
  493.             FormatUtil.FormatDouble (oasFCAFBA.contraLiabilityAdjustment(), 1, 4, 1.) + " | " +
  494.             FormatUtil.FormatDouble (oapFCAFBA.fundingTransferPricing(), 3, 0, 10000.) + " | " +
  495.             FormatUtil.FormatDouble (oapFCAFBA.cet1Change(), 3, 0, 10000.) + " | " +
  496.             FormatUtil.FormatDouble (oapFCAFBA.contraLiabilityChange(), 3, 0, 10000.) + " | " +
  497.             FormatUtil.FormatDouble (oapFCAFBA.portfolioValueChange(), 3, 0, 10000.) + " || "
  498.         );

  499.         System.out.println ("\t|| FVA/FDA Accounting => " +
  500.             FormatUtil.FormatDouble (oasFVAFDA.contraAssetAdjustment(), 1, 4, 1.) + " | " +
  501.             FormatUtil.FormatDouble (oasFVAFDA.contraLiabilityAdjustment(), 1, 4, 1.) + " | " +
  502.             FormatUtil.FormatDouble (oapFVAFDA.fundingTransferPricing(), 3, 0, 10000.) + " | " +
  503.             FormatUtil.FormatDouble (oapFVAFDA.cet1Change(), 3, 0, 10000.) + " | " +
  504.             FormatUtil.FormatDouble (oapFVAFDA.contraLiabilityChange(), 3, 0, 10000.) + " | " +
  505.             FormatUtil.FormatDouble (oapFVAFDA.portfolioValueChange(), 3, 0, 10000.) + " || "
  506.         );

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

  510.         System.out.println();
  511.     }

  512.     public static final void main (
  513.         final String[] astrArgs)
  514.         throws Exception
  515.     {
  516.         EnvManager.InitEnv ("");

  517.         ExposureAdjustmentAggregator[] aCPGA = Mix (
  518.             5.,
  519.             0.,
  520.             100.,
  521.             5.,
  522.             -0.05,
  523.             1.
  524.         );

  525.         ExposureAdjustmentAggregator cpgaGround = aCPGA[0];
  526.         ExposureAdjustmentAggregator cpgaExtended = aCPGA[1];

  527.         ExposureAdjustmentDigest cpgdGround = cpgaGround.digest();

  528.         ExposureAdjustmentDigest cpgdExtended = cpgaExtended.digest();

  529.         CPGDDump (
  530.             "\t||                                                  GROUND BOOK ADJUSTMENT METRICS                                                   ||",
  531.             cpgdGround
  532.         );

  533.         CPGDDump (
  534.             "\t||                                                 EXTENDED BOOK ADJUSTMENT METRICS                                                  ||",
  535.             cpgdExtended
  536.         );

  537.         CPGDDiffDump (
  538.             "\t||                                             TRADE INCREMENT ADJUSTMENT METRICS (bp)                                               ||",
  539.             cpgdGround,
  540.             cpgdExtended
  541.         );

  542.         BaselAccountingMetrics (
  543.             "\t||           ALBANESE & ANDERSEN (2015) BCBS OTC ACCOUNTING            ||",
  544.             cpgaGround,
  545.             cpgaExtended
  546.         );
  547.     }
  548. }