AlbaneseAndersenBaselProxy.java

  1. package org.drip.sample.xvafixfloat;

  2. import java.util.ArrayList;
  3. import java.util.List;

  4. import org.drip.analytics.date.*;
  5. import org.drip.exposure.evolver.*;
  6. import org.drip.exposure.holdings.*;
  7. import org.drip.exposure.universe.*;
  8. import org.drip.measure.crng.*;
  9. import org.drip.measure.discrete.CorrelatedPathVertexDimension;
  10. import org.drip.measure.dynamics.*;
  11. import org.drip.measure.process.*;
  12. import org.drip.measure.statistics.UnivariateDiscreteThin;
  13. import org.drip.numerical.common.FormatUtil;
  14. import org.drip.numerical.common.StringUtil;
  15. import org.drip.numerical.linearalgebra.Matrix;
  16. import org.drip.service.env.EnvManager;
  17. import org.drip.state.identifier.*;
  18. import org.drip.xva.dynamics.*;
  19. import org.drip.xva.gross.*;
  20. import org.drip.xva.proto.*;
  21. import org.drip.xva.settings.*;

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

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

  65. /**
  66.  * AlbaneseAndersenBaselProxy simulates for various Latent States and Exposures for an Fix Float Swap and
  67.  *  computes the XVA Metrics using the Basel Proxy-Style Exposure Generator using Albanese Andersen
  68.  *  Vertexes. The References are:
  69.  *  
  70.  *  - Burgard, C., and M. Kjaer (2014): PDE Representations of Derivatives with Bilateral Counter-party Risk
  71.  *      and Funding Costs, Journal of Credit Risk, 7 (3) 1-19.
  72.  *  
  73.  *  - Burgard, C., and M. Kjaer (2014): In the Balance, Risk, 24 (11) 72-75.
  74.  *  
  75.  *  - Albanese, C., and L. Andersen (2014): Accounting for OTC Derivatives: Funding Adjustments and the
  76.  *      Re-Hypothecation Option, eSSRN, https://papers.ssrn.com/sol3/papers.cfm?abstract_id=2482955.
  77.  *  
  78.  *  - Burgard, C., and M. Kjaer (2017): Derivatives Funding, Netting, and Accounting, eSSRN,
  79.  *      https://papers.ssrn.com/sol3/papers.cfm?abstract_id=2534011.
  80.  *
  81.  *  - Piterbarg, V. (2010): Funding Beyond Discounting: Collateral Agreements and Derivatives Pricing, Risk
  82.  *      21 (2) 97-102.
  83.  *
  84.  * @author Lakshmi Krishnamurthy
  85.  */

  86. public class AlbaneseAndersenBaselProxy
  87. {

  88.     private static final PrimarySecurity OvernightReplicator (
  89.         final String currency,
  90.         final List<LatentStateLabel> latentStateLabelList)
  91.         throws Exception
  92.     {
  93.         double overnightReplicatorDrift = 0.0025;
  94.         double overnightReplicatorVolatility = 0.001;
  95.         double overnightReplicatorRepo = 0.0;

  96.         LatentStateLabel overnightLabel = OvernightLabel.Create (currency);

  97.         latentStateLabelList.add (overnightLabel);

  98.         return new PrimarySecurity (
  99.             currency + "_OVERNIGHT",
  100.             overnightLabel,
  101.             new DiffusionEvolver (
  102.                 DiffusionEvaluatorLogarithmic.Standard (
  103.                     overnightReplicatorDrift,
  104.                     overnightReplicatorVolatility
  105.                 )
  106.             ),
  107.             overnightReplicatorRepo
  108.         );
  109.     }

  110.     private static final PrimarySecurity CSAReplicator (
  111.         final String currency,
  112.         final List<LatentStateLabel> latentStateLabelList)
  113.         throws Exception
  114.     {
  115.         double csaReplicatorDrift = 0.01;
  116.         double csaReplicatorVolatility = 0.002;
  117.         double csaReplicatorRepo = 0.005;

  118.         LatentStateLabel csaLabel = CSALabel.ISDA (currency);

  119.         latentStateLabelList.add (csaLabel);

  120.         return new PrimarySecurity (
  121.             currency + "_CSA",
  122.             csaLabel,
  123.             new DiffusionEvolver (
  124.                 DiffusionEvaluatorLogarithmic.Standard (
  125.                     csaReplicatorDrift,
  126.                     csaReplicatorVolatility
  127.                 )
  128.             ),
  129.             csaReplicatorRepo
  130.         );
  131.     }

  132.     private static final PrimarySecurity DealerSeniorFundingReplicator (
  133.         final String currency,
  134.         final String dealer,
  135.         final List<LatentStateLabel> latentStateLabelList)
  136.         throws Exception
  137.     {
  138.         double dealerSeniorFundingReplicatorDrift = 0.03;
  139.         double dealerSeniorFundingReplicatorVolatility = 0.002;
  140.         double dealerSeniorFundingReplicatorRepo = 0.028;

  141.         LatentStateLabel dealerSeniorFundingLabel = EntityFundingLabel.Senior (
  142.             dealer,
  143.             currency
  144.         );

  145.         latentStateLabelList.add (dealerSeniorFundingLabel);

  146.         return new PrimarySecurity (
  147.             dealer + "_" + currency + "_SENIOR_ZERO",
  148.             dealerSeniorFundingLabel,
  149.             new JumpDiffusionEvolver (
  150.                 DiffusionEvaluatorLogarithmic.Standard (
  151.                     dealerSeniorFundingReplicatorDrift,
  152.                     dealerSeniorFundingReplicatorVolatility
  153.                 ),
  154.                 HazardJumpEvaluator.Standard (
  155.                     0.3,
  156.                     0.45
  157.                 )
  158.             ),
  159.             dealerSeniorFundingReplicatorRepo
  160.         );
  161.     }

  162.     private static final PrimarySecurity DealerSubordinateFundingReplicator (
  163.         final String currency,
  164.         final String dealer,
  165.         final List<LatentStateLabel> latentStateLabelList)
  166.         throws Exception
  167.     {
  168.         double dealerSubordinateFundingReplicatorDrift = 0.045;
  169.         double dealerSubordinateFundingReplicatorVolatility = 0.002;
  170.         double dealerSubordinateFundingReplicatorRepo = 0.028;

  171.         LatentStateLabel dealerSubordinateFundingLabel = EntityFundingLabel.Subordinate (
  172.             dealer,
  173.             currency
  174.         );

  175.         latentStateLabelList.add (dealerSubordinateFundingLabel);

  176.         return new PrimarySecurity (
  177.             dealer + "_" + currency + "_SUBORDINATE_ZERO",
  178.             dealerSubordinateFundingLabel,
  179.             new JumpDiffusionEvolver (
  180.                 DiffusionEvaluatorLogarithmic.Standard (
  181.                     dealerSubordinateFundingReplicatorDrift,
  182.                     dealerSubordinateFundingReplicatorVolatility
  183.                 ),
  184.                 HazardJumpEvaluator.Standard (
  185.                     0.3,
  186.                     0.25
  187.                 )
  188.             ),
  189.             dealerSubordinateFundingReplicatorRepo
  190.         );
  191.     }

  192.     private static final PrimarySecurity ClientFundingReplicator (
  193.         final String currency,
  194.         final String client,
  195.         final List<LatentStateLabel> latentStateLabelList)
  196.         throws Exception
  197.     {
  198.         double clientFundingReplicatorDrift = 0.03;
  199.         double clientFundingReplicatorVolatility = 0.003;
  200.         double clientFundingReplicatorRepo = 0.028;

  201.         LatentStateLabel clientFundingLabel = EntityFundingLabel.Senior (
  202.             client,
  203.             currency
  204.         );

  205.         latentStateLabelList.add (clientFundingLabel);

  206.         return new PrimarySecurity (
  207.             client + "_" + currency + "_SENIOR_ZERO",
  208.             clientFundingLabel,
  209.             new JumpDiffusionEvolver (
  210.                 DiffusionEvaluatorLogarithmic.Standard (
  211.                     clientFundingReplicatorDrift,
  212.                     clientFundingReplicatorVolatility
  213.                 ),
  214.                 HazardJumpEvaluator.Standard (
  215.                     0.5,
  216.                     0.30
  217.                 )
  218.             ),
  219.             clientFundingReplicatorRepo
  220.         );
  221.     }

  222.     private static final TerminalLatentState DealerHazard (
  223.         final String currency,
  224.         final String dealer,
  225.         final List<LatentStateLabel> latentStateLabelList)
  226.         throws Exception
  227.     {
  228.         double dealerHazardDrift = 0.0002;
  229.         double dealerHazardVolatility = 0.02;

  230.         LatentStateLabel dealerHazardLabel = EntityHazardLabel.Standard (
  231.             dealer,
  232.             currency
  233.         );

  234.         latentStateLabelList.add (dealerHazardLabel);

  235.         return new TerminalLatentState (
  236.             dealerHazardLabel,
  237.             new DiffusionEvolver (
  238.                 DiffusionEvaluatorLogarithmic.Standard (
  239.                     dealerHazardDrift,
  240.                     dealerHazardVolatility
  241.                 )
  242.             )
  243.         );
  244.     }

  245.     private static final TerminalLatentState DealerRecovery (
  246.         final String currency,
  247.         final String dealer,
  248.         final List<LatentStateLabel> latentStateLabelList)
  249.         throws Exception
  250.     {
  251.         double dealerRecoveryDrift = 0.0002;
  252.         double dealerRecoveryVolatility = 0.02;

  253.         LatentStateLabel dealerRecoveryLabel = EntityRecoveryLabel.Senior (
  254.             dealer,
  255.             currency
  256.         );

  257.         latentStateLabelList.add (dealerRecoveryLabel);

  258.         return new TerminalLatentState (
  259.             dealerRecoveryLabel,
  260.             new DiffusionEvolver (
  261.                 DiffusionEvaluatorLogarithmic.Standard (
  262.                     dealerRecoveryDrift,
  263.                     dealerRecoveryVolatility
  264.                 )
  265.             )
  266.         );
  267.     }

  268.     private static final TerminalLatentState ClientHazard (
  269.         final String currency,
  270.         final String client,
  271.         final List<LatentStateLabel> latentStateLabelList)
  272.         throws Exception
  273.     {
  274.         double clientHazardDrift = 0.0002;
  275.         double clientHazardVolatility = 0.02;

  276.         LatentStateLabel clientHazardLabel = EntityHazardLabel.Standard (
  277.             client,
  278.             currency
  279.         );

  280.         latentStateLabelList.add (clientHazardLabel);

  281.         return new TerminalLatentState (
  282.             clientHazardLabel,
  283.             new DiffusionEvolver (
  284.                 DiffusionEvaluatorLogarithmic.Standard (
  285.                     clientHazardDrift,
  286.                     clientHazardVolatility
  287.                 )
  288.             )
  289.         );
  290.     }

  291.     private static final TerminalLatentState ClientRecovery (
  292.         final String currency,
  293.         final String client,
  294.         final List<LatentStateLabel> latentStateLabelList)
  295.         throws Exception
  296.     {
  297.         double clientRecoveryDrift = 0.0002;
  298.         double clientRecoveryVolatility = 0.02;

  299.         LatentStateLabel clientRecoveryLabel = EntityRecoveryLabel.Senior (
  300.             client,
  301.             currency
  302.         );

  303.         latentStateLabelList.add (clientRecoveryLabel);

  304.         return new TerminalLatentState (
  305.             clientRecoveryLabel,
  306.             new DiffusionEvolver (
  307.                 DiffusionEvaluatorLogarithmic.Standard (
  308.                     clientRecoveryDrift,
  309.                     clientRecoveryVolatility
  310.                 )
  311.             )
  312.         );
  313.     }

  314.     private static final EntityDynamicsContainer EntityEvolver (
  315.         final String currency,
  316.         final String dealer,
  317.         final String client,
  318.         final List<LatentStateLabel> latentStateLabelList)
  319.         throws Exception
  320.     {
  321.         return new EntityDynamicsContainer (
  322.             DealerHazard (
  323.                 currency,
  324.                 dealer,
  325.                 latentStateLabelList
  326.             ),
  327.             DealerRecovery (
  328.                 currency,
  329.                 dealer,
  330.                 latentStateLabelList
  331.             ),
  332.             null,
  333.             ClientHazard (
  334.                 currency,
  335.                 client,
  336.                 latentStateLabelList
  337.             ),
  338.             ClientRecovery (
  339.                 currency,
  340.                 client,
  341.                 latentStateLabelList
  342.             )
  343.         );
  344.     }

  345.     private static final PrimarySecurityDynamicsContainer PrimarySecurityEvolver (
  346.         final String currency,
  347.         final String dealer,
  348.         final String client,
  349.         final List<LatentStateLabel> latentStateLabelList)
  350.         throws Exception
  351.     {
  352.         return new PrimarySecurityDynamicsContainer (
  353.             null,
  354.             OvernightReplicator (
  355.                 currency,
  356.                 latentStateLabelList
  357.             ),
  358.             CSAReplicator (
  359.                 currency,
  360.                 latentStateLabelList
  361.             ),
  362.             DealerSeniorFundingReplicator (
  363.                 currency,
  364.                 dealer,
  365.                 latentStateLabelList
  366.             ),
  367.             DealerSubordinateFundingReplicator (
  368.                 currency,
  369.                 dealer,
  370.                 latentStateLabelList
  371.             ),
  372.             ClientFundingReplicator (
  373.                 currency,
  374.                 client,
  375.                 latentStateLabelList
  376.             )
  377.         );
  378.     }

  379.     private static final LatentStateDynamicsContainer LatentStateEvolver (
  380.         final OTCFixFloatLabel otcFixFloatLabel,
  381.         final List<LatentStateLabel> latentStateLabelList)
  382.         throws Exception
  383.     {
  384.         double otcFixFloatNumeraireDrift = 0.0;
  385.         double otcFixFloatNumeraireVolatility = 0.25;

  386.         latentStateLabelList.add (otcFixFloatLabel);

  387.         LatentStateDynamicsContainer latentStateDynamicsContainer = new LatentStateDynamicsContainer();

  388.         latentStateDynamicsContainer.addOTCFixFloat (
  389.             new TerminalLatentState (
  390.                 otcFixFloatLabel,
  391.                 new DiffusionEvolver (
  392.                     DiffusionEvaluatorLinear.Standard (
  393.                         otcFixFloatNumeraireDrift,
  394.                         otcFixFloatNumeraireVolatility
  395.                     )
  396.                 )
  397.             )
  398.         );

  399.         return latentStateDynamicsContainer;
  400.     }

  401.     private static final MarketVertexGenerator ConstructMarketVertexGenerator (
  402.         final JulianDate spotDate,
  403.         final String exposureSamplingTenor,
  404.         final int exposureSamplingNodeCount,
  405.         final String currency,
  406.         final String dealer,
  407.         final String client,
  408.         final OTCFixFloatLabel otcFixFloatLabel,
  409.         final List<LatentStateLabel> latentStateLabelList)
  410.         throws Exception
  411.     {
  412.         JulianDate terminationDate = spotDate;
  413.         int[] eventVertexArray = new int[exposureSamplingNodeCount];

  414.         for (int i = 0; i < exposureSamplingNodeCount; ++i)
  415.         {
  416.             terminationDate = terminationDate.addTenor (exposureSamplingTenor);

  417.             eventVertexArray[i] = terminationDate.julian();
  418.         }

  419.         return new MarketVertexGenerator (
  420.             spotDate.julian(),
  421.             eventVertexArray,
  422.             EntityEvolver (
  423.                 currency,
  424.                 dealer,
  425.                 client,
  426.                 latentStateLabelList
  427.             ),
  428.             PrimarySecurityEvolver (
  429.                 currency,
  430.                 dealer,
  431.                 client,
  432.                 latentStateLabelList
  433.             ),
  434.             LatentStateEvolver (
  435.                 otcFixFloatLabel,
  436.                 latentStateLabelList
  437.             )
  438.         );
  439.     }

  440.     private static final void ThinStatistics (
  441.         final String header,
  442.         final JulianDate[] vertexDateArray,
  443.         final UnivariateDiscreteThin[] thinStatisticsArray)
  444.         throws Exception
  445.     {
  446.         System.out.println ("\t|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|");

  447.         System.out.println (header);

  448.         System.out.println ("\t|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|");

  449.         String statisticsDump = "\t|       DATE      =>" ;

  450.         for (int i = 0; i < vertexDateArray.length; ++i)
  451.         {
  452.             statisticsDump = statisticsDump + " " + vertexDateArray[i] + "  |";
  453.         }

  454.         System.out.println (statisticsDump);

  455.         System.out.println ("\t|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|");

  456.         statisticsDump = "\t|     AVERAGE     =>";

  457.         for (int j = 0; j < thinStatisticsArray.length; ++j)
  458.         {
  459.             statisticsDump = statisticsDump + "   " + FormatUtil.FormatDouble (thinStatisticsArray[j].average(), 2, 4, 1.) + "   |";
  460.         }

  461.         System.out.println (statisticsDump);

  462.         statisticsDump = "\t|     MAXIMUM     =>";

  463.         for (int j = 0; j < thinStatisticsArray.length; ++j)
  464.         {
  465.             statisticsDump = statisticsDump + "   " + FormatUtil.FormatDouble (thinStatisticsArray[j].maximum(), 2, 4, 1.) + "   |";
  466.         }

  467.         System.out.println (statisticsDump);

  468.         statisticsDump = "\t|     MINIMUM     =>";

  469.         for (int j = 0; j < thinStatisticsArray.length; ++j)
  470.         {
  471.             statisticsDump = statisticsDump + "   " + FormatUtil.FormatDouble (thinStatisticsArray[j].minimum(), 2, 4, 1.) + "   |";
  472.         }

  473.         System.out.println (statisticsDump);

  474.         statisticsDump = "\t|      ERROR      =>";

  475.         for (int j = 0; j < thinStatisticsArray.length; ++j)
  476.         {
  477.             statisticsDump = statisticsDump + "   " + FormatUtil.FormatDouble (thinStatisticsArray[j].error(), 2, 4, 1.) + "   |";
  478.         }

  479.         System.out.println (statisticsDump);

  480.         System.out.println ("\t|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|");
  481.     }

  482.     private static final void ThinStatistics (
  483.         final String header,
  484.         final UnivariateDiscreteThin thinStatistics)
  485.         throws Exception
  486.     {
  487.         System.out.println (
  488.             header +
  489.             FormatUtil.FormatDouble (thinStatistics.average(), 3, 2, 100.) + "% | " +
  490.             FormatUtil.FormatDouble (thinStatistics.maximum(), 3, 2, 100.) + "% | " +
  491.             FormatUtil.FormatDouble (thinStatistics.minimum(), 3, 2, 100.) + "% | " +
  492.             FormatUtil.FormatDouble (thinStatistics.error(), 3, 2, 100.) + "% ||"
  493.         );
  494.     }

  495.     public static final void main (
  496.         final String[] argumentArray)
  497.         throws Exception
  498.     {
  499.         EnvManager.InitEnv (
  500.             "",
  501.             true
  502.         );

  503.         String dealer = "CITI";
  504.         String client = "AIG";
  505.         String currency = "USD";

  506.         double dealerVMThreshold = -0.1;
  507.         double clientVMThreshold = 0.1;

  508.         /*
  509.          * Evolution Control
  510.          */

  511.         int pathCount = 60000;
  512.         int exposureSamplingNodeCount = 10;
  513.         String exposureSamplingTenor = "6M";
  514.         double[][] correlationMatrix = new double[][] {
  515.             {1.00, 0.00, 0.20, 0.15, 0.05, 0.00, 0.00, 0.00, 0.00, 0.00}, // #0  DEALER HAZARD
  516.             {0.00, 1.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00}, // #1  DEALER SENIOR RECOVERY
  517.             {0.20, 0.00, 1.00, 0.13, 0.25, 0.00, 0.00, 0.00, 0.00, 0.00}, // #2  CLIENT HAZARD
  518.             {0.15, 0.00, 0.13, 1.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00}, // #3  CLIENT RECOVERY
  519.             {0.05, 0.00, 0.25, 0.00, 1.00, 0.00, 0.00, 0.00, 0.00, 0.00}, // #4  OVERNIGHT REPLICATOR
  520.             {0.00, 0.00, 0.00, 0.00, 0.00, 1.00, 0.00, 0.00, 0.00, 0.00}, // #5  CSA REPLICATOR
  521.             {0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 1.00, 0.00, 0.00, 0.00}, // #6  DEALER SENIOR FUNDING REPLICATOR
  522.             {0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 1.00, 0.00, 0.00}, // #7  DEALER SUBORDINATE FUNDING REPLICATOR
  523.             {0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 1.00, 0.00}, // #8  CLIENT FUNDING REPLICATOR
  524.             {0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 1.00}, // #9  OTC FIX FLOAT REPLICATOR
  525.         };

  526.         JulianDate spotDate = DateUtil.Today();

  527.         OTCFixFloatLabel otcFixFloatLabel = OTCFixFloatLabel.Standard (currency + "-3M-10Y");

  528.         JulianDate terminationDate = spotDate;
  529.         PathExposureAdjustment[] pathExposureAdjustmentArray = new PathExposureAdjustment[pathCount];

  530.         for (int i = 0; i < exposureSamplingNodeCount; ++i)
  531.         {
  532.             terminationDate = terminationDate.addTenor (exposureSamplingTenor);
  533.         }

  534.         final int maturityDate = terminationDate.julian();

  535.         List<LatentStateLabel> latentStateLabelList = new ArrayList<LatentStateLabel>();

  536.         PathSimulator fixFloatPathSimulator = new PathSimulator (
  537.             pathCount,
  538.             ConstructMarketVertexGenerator (
  539.                 spotDate,
  540.                 exposureSamplingTenor,
  541.                 exposureSamplingNodeCount,
  542.                 currency,
  543.                 dealer,
  544.                 client,
  545.                 otcFixFloatLabel,
  546.                 latentStateLabelList
  547.             ),
  548.             AdjustmentDigestScheme.ALBANESE_ANDERSEN_METRICS_POINTER,
  549.             PositionGroupContainer.Solo (
  550.                 new PositionGroup (
  551.                     new PositionSchemaSpecification (
  552.                         "POSGRPSPEC1",
  553.                         "POSGRPSPEC1",
  554.                         PositionGroupSpecification.FixedThreshold (
  555.                             "FIXEDTHRESHOLD",
  556.                             clientVMThreshold,
  557.                             dealerVMThreshold,
  558.                             PositionReplicationScheme.ALBANESE_ANDERSEN_VERTEX,
  559.                             BrokenDateScheme.SQUARE_ROOT_OF_TIME,
  560.                             0.,
  561.                             CloseOutScheme.ISDA_92
  562.                         ),
  563.                         new CollateralGroupSpecification (
  564.                             StringUtil.GUID(),
  565.                             "FIXEDTHRESHOLD",
  566.                             OvernightLabel.Create (currency),
  567.                             CSALabel.ISDA (currency)
  568.                         ),
  569.                         new CreditDebtGroupSpecification (
  570.                             "NETGRPSPEC1",
  571.                             "NETGRPSPEC1",
  572.                             EntityHazardLabel.Standard (
  573.                                 dealer,
  574.                                 currency
  575.                             ),
  576.                             EntityHazardLabel.Standard (
  577.                                 client,
  578.                                 currency
  579.                             ),
  580.                             EntityRecoveryLabel.Senior (
  581.                                 dealer,
  582.                                 currency
  583.                             ),
  584.                             EntityRecoveryLabel.Senior (
  585.                                 client,
  586.                                 currency
  587.                             ),
  588.                             null,
  589.                             true,
  590.                             true
  591.                         ),
  592.                         new FundingGroupSpecification (
  593.                             "FUNDGRPSPEC1",
  594.                             "FUNDGRPSPEC1",
  595.                             EntityFundingLabel.Senior (
  596.                                 dealer,
  597.                                 currency
  598.                             ),
  599.                             EntityFundingLabel.Senior (
  600.                                 client,
  601.                                 currency
  602.                             ),
  603.                             EntityFundingLabel.Subordinate (
  604.                                 dealer,
  605.                                 currency
  606.                             )
  607.                         )
  608.                     ),
  609.                     new FixFloatBaselPositionEstimator (
  610.                         maturityDate,
  611.                         otcFixFloatLabel
  612.                     )
  613.                 )
  614.             )
  615.         );

  616.         LatentStateVertexContainer latentStateVertexContainer = new LatentStateVertexContainer();

  617.         latentStateVertexContainer.add (
  618.             otcFixFloatLabel,
  619.             0.
  620.         );

  621.         MarketVertex initialMarketVertex = MarketVertex.Epochal (
  622.             spotDate,
  623.             1.000,              // dblOvernightNumeraireInitial
  624.             1.000,              // dblCSANumeraire
  625.             0.015,              // dblBankHazardRate
  626.             0.400,              // dblBankRecoveryRate
  627.             0.015 / (1 - 0.40), // dblBankFundingSpread
  628.             0.030,              // dblCounterPartyHazardRate
  629.             0.300,              // dblCounterPartyRecoveryRate
  630.             0.030 / (1 - 0.30), // dblCounterPartyFundingSpread
  631.             latentStateVertexContainer
  632.         );

  633.         CorrelatedPathVertexDimension correlatedPathVertexDimension = new CorrelatedPathVertexDimension (
  634.             new RandomNumberGenerator(),
  635.             correlationMatrix,
  636.             exposureSamplingNodeCount,
  637.             1,
  638.             true,
  639.             null
  640.         );

  641.         for (int i = 0; i < pathCount; ++i)
  642.         {
  643.             pathExposureAdjustmentArray[i] = fixFloatPathSimulator.singleTrajectory (
  644.                 initialMarketVertex,
  645.                 LatentStateWeiner.FromUnitRandom (
  646.                     latentStateLabelList,
  647.                     Matrix.Transpose (correlatedPathVertexDimension.straightPathVertexRd().flatform())
  648.                 )
  649.             );
  650.         }

  651.         ExposureAdjustmentAggregator exposureAdjustmentAggregator = new ExposureAdjustmentAggregator
  652.             (pathExposureAdjustmentArray);

  653.         ExposureAdjustmentDigest exposureAdjustmentDigest = exposureAdjustmentAggregator.digest();

  654.         System.out.println();

  655.         ThinStatistics (
  656.             "\t|                                                                                COLLATERALIZED EXPOSURE                                                                                |",
  657.             exposureAdjustmentAggregator.vertexDates(),
  658.             exposureAdjustmentDigest.collateralizedExposure()
  659.         );

  660.         ThinStatistics (
  661.             "\t|                                                                               UNCOLLATERALIZED EXPOSURE                                                                               |",
  662.             exposureAdjustmentAggregator.vertexDates(),
  663.             exposureAdjustmentDigest.uncollateralizedExposure()
  664.         );

  665.         ThinStatistics (
  666.             "\t|                                                                                COLLATERALIZED EXPOSURE PV                                                                             |",
  667.             exposureAdjustmentAggregator.vertexDates(),
  668.             exposureAdjustmentDigest.collateralizedExposurePV()
  669.         );

  670.         ThinStatistics (
  671.             "\t|                                                                               UNCOLLATERALIZED EXPOSURE PV                                                                            |",
  672.             exposureAdjustmentAggregator.vertexDates(),
  673.             exposureAdjustmentDigest.uncollateralizedExposurePV()
  674.         );

  675.         ThinStatistics (
  676.             "\t|                                                                            COLLATERALIZED POSITIVE EXPOSURE PV                                                                        |",
  677.             exposureAdjustmentAggregator.vertexDates(),
  678.             exposureAdjustmentDigest.collateralizedPositiveExposurePV()
  679.         );

  680.         ThinStatistics (
  681.             "\t|                                                                           UNCOLLATERALIZED POSITIVE EXPOSURE PV                                                                       |",
  682.             exposureAdjustmentAggregator.vertexDates(),
  683.             exposureAdjustmentDigest.uncollateralizedPositiveExposurePV()
  684.         );

  685.         ThinStatistics (
  686.             "\t|                                                                            COLLATERALIZED NEGATIVE EXPOSURE PV                                                                        |",
  687.             exposureAdjustmentAggregator.vertexDates(),
  688.             exposureAdjustmentDigest.collateralizedNegativeExposurePV()
  689.         );

  690.         ThinStatistics (
  691.             "\t|                                                                           UNCOLLATERALIZED NEGATIVE EXPOSURE PV                                                                       |",
  692.             exposureAdjustmentAggregator.vertexDates(),
  693.             exposureAdjustmentDigest.uncollateralizedNegativeExposurePV()
  694.         );

  695.         System.out.println();

  696.         System.out.println ("\t||-----------------------------------------------------||");

  697.         System.out.println ("\t||  UCVA CVA FTDCVA DVA FCA UNIVARIATE THIN STATISTICS ||");

  698.         System.out.println ("\t||-----------------------------------------------------||");

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

  700.         System.out.println ("\t||            - Path Average                           ||");

  701.         System.out.println ("\t||            - Path Maximum                           ||");

  702.         System.out.println ("\t||            - Path Minimum                           ||");

  703.         System.out.println ("\t||            - Monte Carlo Error                      ||");

  704.         System.out.println ("\t||-----------------------------------------------------||");

  705.         ThinStatistics (
  706.             "\t||  UCVA  => ",
  707.             exposureAdjustmentDigest.ucva()
  708.         );

  709.         ThinStatistics (
  710.             "\t|| FTDCVA => ",
  711.             exposureAdjustmentDigest.ftdcva()
  712.         );

  713.         ThinStatistics (
  714.             "\t||   CVA  => ",
  715.             exposureAdjustmentDigest.cva()
  716.         );

  717.         ThinStatistics (
  718.             "\t||  CVACL => ",
  719.             exposureAdjustmentDigest.cvacl()
  720.         );

  721.         ThinStatistics (
  722.             "\t||   DVA  => ",
  723.             exposureAdjustmentDigest.dva()
  724.         );

  725.         ThinStatistics (
  726.             "\t||   FVA  => ",
  727.             exposureAdjustmentDigest.fva()
  728.         );

  729.         ThinStatistics (
  730.             "\t||   FDA  => ",
  731.             exposureAdjustmentDigest.fda()
  732.         );

  733.         ThinStatistics (
  734.             "\t||   FCA  => ",
  735.             exposureAdjustmentDigest.fca()
  736.         );

  737.         ThinStatistics (
  738.             "\t||   FBA  => ",
  739.             exposureAdjustmentDigest.fba()
  740.         );

  741.         ThinStatistics (
  742.             "\t||  SFVA  => ",
  743.             exposureAdjustmentDigest.sfva()
  744.         );

  745.         System.out.println ("\t||-----------------------------------------------------||");

  746.         ThinStatistics (
  747.             "\t||  Total => ",
  748.             exposureAdjustmentDigest.totalVA()
  749.         );

  750.         System.out.println ("\t||-----------------------------------------------------||");

  751.         EnvManager.TerminateEnv();
  752.     }
  753. }