HedgeErrorBaselProxy.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.  * HedgeErrorBaselProxy simulates for various Latent States and Exposures for an Fix Float Swap and computes
  67.  *  the XVA Metrics using the Basel Proxy-Style Exposure Generator using Burgard Kjaer Dual Bond Hedge Error
  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.  *  - Albanese, C., L. Andersen, and, S. Iabichino (2015): The FVA Puzzle: Accounting, Risk Management, and
  79.  *      Collateral Trading <b>https://papers.ssrn.com/sol3/paper.cfm?abstract_id_2517301</b><br><br>
  80.  *  
  81.  *  - Burgard, C., and M. Kjaer (2017): Derivatives Funding, Netting, and Accounting, eSSRN,
  82.  *      https://papers.ssrn.com/sol3/papers.cfm?abstract_id=2534011.
  83.  *
  84.  * @author Lakshmi Krishnamurthy
  85.  */

  86. public class HedgeErrorBaselProxy
  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 DealerSeniorRecovery (
  246.         final String currency,
  247.         final String dealer,
  248.         final List<LatentStateLabel> latentStateLabelList)
  249.         throws Exception
  250.     {
  251.         double dealerSeniorRecoveryDrift = 0.0002;
  252.         double dealerSeniorRecoveryVolatility = 0.02;

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

  257.         latentStateLabelList.add (dealerSeniorRecoveryLabel);

  258.         return new TerminalLatentState (
  259.             dealerSeniorRecoveryLabel,
  260.             new DiffusionEvolver (
  261.                 DiffusionEvaluatorLogarithmic.Standard (
  262.                     dealerSeniorRecoveryDrift,
  263.                     dealerSeniorRecoveryVolatility
  264.                 )
  265.             )
  266.         );
  267.     }

  268.     private static final TerminalLatentState DealerSubordinateRecovery (
  269.         final String currency,
  270.         final String dealer,
  271.         final List<LatentStateLabel> latentStateLabelList)
  272.         throws Exception
  273.     {
  274.         double dealerSubordinateRecoveryDrift = 0.0002;
  275.         double dealerSubordinateRecoveryVolatility = 0.02;

  276.         LatentStateLabel dealerSubordinateRecoveryLabel = EntityRecoveryLabel.Subordinate (
  277.             dealer,
  278.             currency
  279.         );

  280.         latentStateLabelList.add (dealerSubordinateRecoveryLabel);

  281.         return new TerminalLatentState (
  282.             dealerSubordinateRecoveryLabel,
  283.             new DiffusionEvolver (
  284.                 DiffusionEvaluatorLogarithmic.Standard (
  285.                     dealerSubordinateRecoveryDrift,
  286.                     dealerSubordinateRecoveryVolatility
  287.                 )
  288.             )
  289.         );
  290.     }

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

  299.         LatentStateLabel clientHazardLabel = EntityHazardLabel.Standard (
  300.             client,
  301.             currency
  302.         );

  303.         latentStateLabelList.add (clientHazardLabel);

  304.         return new TerminalLatentState (
  305.             clientHazardLabel,
  306.             new DiffusionEvolver (
  307.                 DiffusionEvaluatorLogarithmic.Standard (
  308.                     clientHazardDrift,
  309.                     clientHazardVolatility
  310.                 )
  311.             )
  312.         );
  313.     }

  314.     private static final TerminalLatentState ClientRecovery (
  315.         final String currency,
  316.         final String client,
  317.         final List<LatentStateLabel> latentStateLabelList)
  318.         throws Exception
  319.     {
  320.         double clientRecoveryDrift = 0.0002;
  321.         double clientRecoveryVolatility = 0.02;

  322.         LatentStateLabel clientRecoveryLabel = EntityRecoveryLabel.Senior (
  323.             client,
  324.             currency
  325.         );

  326.         latentStateLabelList.add (clientRecoveryLabel);

  327.         return new TerminalLatentState (
  328.             clientRecoveryLabel,
  329.             new DiffusionEvolver (
  330.                 DiffusionEvaluatorLogarithmic.Standard (
  331.                     clientRecoveryDrift,
  332.                     clientRecoveryVolatility
  333.                 )
  334.             )
  335.         );
  336.     }

  337.     private static final EntityDynamicsContainer EntityEvolver (
  338.         final String currency,
  339.         final String dealer,
  340.         final String client,
  341.         final List<LatentStateLabel> latentStateLabelList)
  342.         throws Exception
  343.     {
  344.         return new EntityDynamicsContainer (
  345.             DealerHazard (
  346.                 currency,
  347.                 dealer,
  348.                 latentStateLabelList
  349.             ),
  350.             DealerSeniorRecovery (
  351.                 currency,
  352.                 dealer,
  353.                 latentStateLabelList
  354.             ),
  355.             DealerSubordinateRecovery (
  356.                 currency,
  357.                 dealer,
  358.                 latentStateLabelList
  359.             ),
  360.             ClientHazard (
  361.                 currency,
  362.                 client,
  363.                 latentStateLabelList
  364.             ),
  365.             ClientRecovery (
  366.                 currency,
  367.                 client,
  368.                 latentStateLabelList
  369.             )
  370.         );
  371.     }

  372.     private static final PrimarySecurityDynamicsContainer PrimarySecurityEvolver (
  373.         final String currency,
  374.         final String dealer,
  375.         final String client,
  376.         final List<LatentStateLabel> latentStateLabelList)
  377.         throws Exception
  378.     {
  379.         return new PrimarySecurityDynamicsContainer (
  380.             null,
  381.             OvernightReplicator (
  382.                 currency,
  383.                 latentStateLabelList
  384.             ),
  385.             CSAReplicator (
  386.                 currency,
  387.                 latentStateLabelList
  388.             ),
  389.             DealerSeniorFundingReplicator (
  390.                 currency,
  391.                 dealer,
  392.                 latentStateLabelList
  393.             ),
  394.             DealerSubordinateFundingReplicator (
  395.                 currency,
  396.                 dealer,
  397.                 latentStateLabelList
  398.             ),
  399.             ClientFundingReplicator (
  400.                 currency,
  401.                 client,
  402.                 latentStateLabelList
  403.             )
  404.         );
  405.     }

  406.     private static final LatentStateDynamicsContainer LatentStateEvolver (
  407.         final OTCFixFloatLabel otcFixFloatLabel,
  408.         final List<LatentStateLabel> latentStateLabelList)
  409.         throws Exception
  410.     {
  411.         double otcFixFloatNumeraireDrift = 0.0;
  412.         double otcFixFloatNumeraireVolatility = 0.25;

  413.         latentStateLabelList.add (otcFixFloatLabel);

  414.         LatentStateDynamicsContainer latentStateDynamicsContainer = new LatentStateDynamicsContainer();

  415.         latentStateDynamicsContainer.addOTCFixFloat (
  416.             new TerminalLatentState (
  417.                 otcFixFloatLabel,
  418.                 new DiffusionEvolver (
  419.                     DiffusionEvaluatorLinear.Standard (
  420.                         otcFixFloatNumeraireDrift,
  421.                         otcFixFloatNumeraireVolatility
  422.                     )
  423.                 )
  424.             )
  425.         );

  426.         return latentStateDynamicsContainer;
  427.     }

  428.     private static final MarketVertexGenerator ConstructMarketVertexGenerator (
  429.         final JulianDate spotDate,
  430.         final String exposureSamplingTenor,
  431.         final int exposureSamplingNodeCount,
  432.         final String currency,
  433.         final String dealer,
  434.         final String client,
  435.         final OTCFixFloatLabel otcFixFloatLabel,
  436.         final List<LatentStateLabel> latentStateLabelList)
  437.         throws Exception
  438.     {
  439.         JulianDate terminationDate = spotDate;
  440.         int[] eventVertexArray = new int[exposureSamplingNodeCount];

  441.         for (int i = 0; i < exposureSamplingNodeCount; ++i)
  442.         {
  443.             terminationDate = terminationDate.addTenor (exposureSamplingTenor);

  444.             eventVertexArray[i] = terminationDate.julian();
  445.         }

  446.         return new MarketVertexGenerator (
  447.             spotDate.julian(),
  448.             eventVertexArray,
  449.             EntityEvolver (
  450.                 currency,
  451.                 dealer,
  452.                 client,
  453.                 latentStateLabelList
  454.             ),
  455.             PrimarySecurityEvolver (
  456.                 currency,
  457.                 dealer,
  458.                 client,
  459.                 latentStateLabelList
  460.             ),
  461.             LatentStateEvolver (
  462.                 otcFixFloatLabel,
  463.                 latentStateLabelList
  464.             )
  465.         );
  466.     }

  467.     private static final void ThinStatistics (
  468.         final String header,
  469.         final JulianDate[] vertexDateArray,
  470.         final UnivariateDiscreteThin[] thinStatisticsArray)
  471.         throws Exception
  472.     {
  473.         System.out.println ("\t|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|");

  474.         System.out.println (header);

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

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

  477.         for (int i = 0; i < vertexDateArray.length; ++i)
  478.         {
  479.             statisticsDump = statisticsDump + " " + vertexDateArray[i] + "  |";
  480.         }

  481.         System.out.println (statisticsDump);

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

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

  484.         for (int j = 0; j < thinStatisticsArray.length; ++j)
  485.         {
  486.             statisticsDump = statisticsDump + "   " + FormatUtil.FormatDouble (thinStatisticsArray[j].average(), 2, 4, 1.) + "   |";
  487.         }

  488.         System.out.println (statisticsDump);

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

  490.         for (int j = 0; j < thinStatisticsArray.length; ++j)
  491.         {
  492.             statisticsDump = statisticsDump + "   " + FormatUtil.FormatDouble (thinStatisticsArray[j].maximum(), 2, 4, 1.) + "   |";
  493.         }

  494.         System.out.println (statisticsDump);

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

  496.         for (int j = 0; j < thinStatisticsArray.length; ++j)
  497.         {
  498.             statisticsDump = statisticsDump + "   " + FormatUtil.FormatDouble (thinStatisticsArray[j].minimum(), 2, 4, 1.) + "   |";
  499.         }

  500.         System.out.println (statisticsDump);

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

  502.         for (int j = 0; j < thinStatisticsArray.length; ++j)
  503.         {
  504.             statisticsDump = statisticsDump + "   " + FormatUtil.FormatDouble (thinStatisticsArray[j].error(), 2, 4, 1.) + "   |";
  505.         }

  506.         System.out.println (statisticsDump);

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

  509.     private static final void ThinStatistics (
  510.         final String header,
  511.         final UnivariateDiscreteThin thinStatistics)
  512.         throws Exception
  513.     {
  514.         System.out.println (
  515.             header +
  516.             FormatUtil.FormatDouble (thinStatistics.average(), 3, 2, 100.) + "% | " +
  517.             FormatUtil.FormatDouble (thinStatistics.maximum(), 3, 2, 100.) + "% | " +
  518.             FormatUtil.FormatDouble (thinStatistics.minimum(), 3, 2, 100.) + "% | " +
  519.             FormatUtil.FormatDouble (thinStatistics.error(), 3, 2, 100.) + "% ||"
  520.         );
  521.     }

  522.     public static final void main (
  523.         final String[] argumentArray)
  524.         throws Exception
  525.     {
  526.         EnvManager.InitEnv (
  527.             "",
  528.             true
  529.         );

  530.         String dealer = "CITI";
  531.         String client = "AIG";
  532.         String currency = "USD";

  533.         double dealerVMThreshold = -0.1;
  534.         double clientVMThreshold = 0.1;

  535.         /*
  536.          * Evolution Control
  537.          */

  538.         int pathCount = 60000;
  539.         int exposureSamplingNodeCount = 10;
  540.         String exposureSamplingTenor = "6M";
  541.         double[][] correlationMatrix = new double[][] {
  542.             {1.00, 0.00, 0.00, 0.20, 0.15, 0.05, 0.00, 0.00, 0.00, 0.00, 0.00}, // #0  DEALER HAZARD
  543.             {0.00, 1.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00}, // #1  DEALER SENIOR RECOVERY
  544.             {0.00, 0.00, 1.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00}, // #2  DEALER SUBORDINATE RECOVERY
  545.             {0.20, 0.00, 0.00, 1.00, 0.13, 0.25, 0.00, 0.00, 0.00, 0.00, 0.00}, // #3  CLIENT HAZARD
  546.             {0.15, 0.00, 0.00, 0.13, 1.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00}, // #4  CLIENT RECOVERY
  547.             {0.05, 0.00, 0.25, 0.00, 0.00, 1.00, 0.00, 0.00, 0.00, 0.00, 0.00}, // #5  OVERNIGHT REPLICATOR
  548.             {0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 1.00, 0.00, 0.00, 0.00, 0.00}, // #6  CSA REPLICATOR
  549.             {0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 1.00, 0.00, 0.00, 0.00}, // #7  DEALER SENIOR FUNDING REPLICATOR
  550.             {0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 1.00, 0.00, 0.00}, // #8  DEALER SUBORDINATE FUNDING REPLICATOR
  551.             {0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 1.00, 0.00}, // #9  CLIENT FUNDING REPLICATOR
  552.             {0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 1.00}, // #10 OTC FIX FLOAT REPLICATOR
  553.         };

  554.         JulianDate spotDate = DateUtil.Today();

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

  556.         JulianDate terminationDate = spotDate;
  557.         PathExposureAdjustment[] pathExposureAdjustmentArray = new PathExposureAdjustment[pathCount];

  558.         for (int i = 0; i < exposureSamplingNodeCount; ++i)
  559.         {
  560.             terminationDate = terminationDate.addTenor (exposureSamplingTenor);
  561.         }

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

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

  564.         PathSimulator fixFloatPathSimulator = new PathSimulator (
  565.             pathCount,
  566.             ConstructMarketVertexGenerator (
  567.                 spotDate,
  568.                 exposureSamplingTenor,
  569.                 exposureSamplingNodeCount,
  570.                 currency,
  571.                 dealer,
  572.                 client,
  573.                 otcFixFloatLabel,
  574.                 latentStateLabelList
  575.             ),
  576.             AdjustmentDigestScheme.ALBANESE_ANDERSEN_METRICS_POINTER,
  577.             PositionGroupContainer.Solo (
  578.                 new PositionGroup (
  579.                     new PositionSchemaSpecification (
  580.                         "POSGRPSPEC1",
  581.                         "POSGRPSPEC1",
  582.                         PositionGroupSpecification.FixedThreshold (
  583.                             "FIXEDTHRESHOLD",
  584.                             clientVMThreshold,
  585.                             dealerVMThreshold,
  586.                             PositionReplicationScheme.BURGARD_KJAER_HEDGE_ERROR_DUAL_BOND_VERTEX,
  587.                             BrokenDateScheme.SQUARE_ROOT_OF_TIME,
  588.                             0.,
  589.                             CloseOutScheme.BILATERAL
  590.                         ),
  591.                         new CollateralGroupSpecification (
  592.                             StringUtil.GUID(),
  593.                             "FIXEDTHRESHOLD",
  594.                             OvernightLabel.Create (currency),
  595.                             CSALabel.ISDA (currency)
  596.                         ),
  597.                         new CreditDebtGroupSpecification (
  598.                             "NETGRPSPEC1",
  599.                             "NETGRPSPEC1",
  600.                             EntityHazardLabel.Standard (
  601.                                 dealer,
  602.                                 currency
  603.                             ),
  604.                             EntityHazardLabel.Standard (
  605.                                 client,
  606.                                 currency
  607.                             ),
  608.                             EntityRecoveryLabel.Senior (
  609.                                 dealer,
  610.                                 currency
  611.                             ),
  612.                             EntityRecoveryLabel.Senior (
  613.                                 client,
  614.                                 currency
  615.                             ),
  616.                             EntityRecoveryLabel.Subordinate (
  617.                                 dealer,
  618.                                 currency
  619.                             ),
  620.                             true,
  621.                             true
  622.                         ),
  623.                         new FundingGroupSpecification (
  624.                             "FUNDGRPSPEC1",
  625.                             "FUNDGRPSPEC1",
  626.                             EntityFundingLabel.Senior (
  627.                                 dealer,
  628.                                 currency
  629.                             ),
  630.                             EntityFundingLabel.Senior (
  631.                                 client,
  632.                                 currency
  633.                             ),
  634.                             EntityFundingLabel.Subordinate (
  635.                                 dealer,
  636.                                 currency
  637.                             )
  638.                         )
  639.                     ),
  640.                     new FixFloatBaselPositionEstimator (
  641.                         maturityDate,
  642.                         otcFixFloatLabel
  643.                     )
  644.                 )
  645.             )
  646.         );

  647.         LatentStateVertexContainer latentStateVertexContainer = new LatentStateVertexContainer();

  648.         latentStateVertexContainer.add (
  649.             otcFixFloatLabel,
  650.             0.
  651.         );

  652.         MarketVertex initialMarketVertex = MarketVertex.Epochal (
  653.             spotDate,
  654.             1.000,              // dblOvernightNumeraireInitial
  655.             1.000,              // dblCSANumeraire
  656.             0.015,              // dblBankHazardRate
  657.             0.400,              // dblBankRecoveryRate
  658.             0.015 / (1 - 0.40), // dblBankFundingSpread
  659.             0.250,              // dblBankRecoveryRate
  660.             0.015 / (1 - 0.25), // dblBankFundingSpread
  661.             0.030,              // dblCounterPartyHazardRate
  662.             0.300,              // dblCounterPartyRecoveryRate
  663.             0.030 / (1 - 0.30), // dblCounterPartyFundingSpread
  664.             latentStateVertexContainer
  665.         );

  666.         CorrelatedPathVertexDimension correlatedPathVertexDimension = new CorrelatedPathVertexDimension (
  667.             new RandomNumberGenerator(),
  668.             correlationMatrix,
  669.             exposureSamplingNodeCount,
  670.             1,
  671.             true,
  672.             null
  673.         );

  674.         for (int i = 0; i < pathCount; ++i)
  675.         {
  676.             pathExposureAdjustmentArray[i] = fixFloatPathSimulator.singleTrajectory (
  677.                 initialMarketVertex,
  678.                 LatentStateWeiner.FromUnitRandom (
  679.                     latentStateLabelList,
  680.                     Matrix.Transpose (correlatedPathVertexDimension.straightPathVertexRd().flatform())
  681.                 )
  682.             );
  683.         }

  684.         ExposureAdjustmentAggregator exposureAdjustmentAggregator = new ExposureAdjustmentAggregator
  685.             (pathExposureAdjustmentArray);

  686.         ExposureAdjustmentDigest exposureAdjustmentDigest = exposureAdjustmentAggregator.digest();

  687.         System.out.println();

  688.         ThinStatistics (
  689.             "\t|                                                                                COLLATERALIZED EXPOSURE                                                                                |",
  690.             exposureAdjustmentAggregator.vertexDates(),
  691.             exposureAdjustmentDigest.collateralizedExposure()
  692.         );

  693.         ThinStatistics (
  694.             "\t|                                                                               UNCOLLATERALIZED EXPOSURE                                                                               |",
  695.             exposureAdjustmentAggregator.vertexDates(),
  696.             exposureAdjustmentDigest.uncollateralizedExposure()
  697.         );

  698.         ThinStatistics (
  699.             "\t|                                                                                COLLATERALIZED EXPOSURE PV                                                                             |",
  700.             exposureAdjustmentAggregator.vertexDates(),
  701.             exposureAdjustmentDigest.collateralizedExposurePV()
  702.         );

  703.         ThinStatistics (
  704.             "\t|                                                                               UNCOLLATERALIZED EXPOSURE PV                                                                            |",
  705.             exposureAdjustmentAggregator.vertexDates(),
  706.             exposureAdjustmentDigest.uncollateralizedExposurePV()
  707.         );

  708.         ThinStatistics (
  709.             "\t|                                                                            COLLATERALIZED POSITIVE EXPOSURE PV                                                                        |",
  710.             exposureAdjustmentAggregator.vertexDates(),
  711.             exposureAdjustmentDigest.collateralizedPositiveExposurePV()
  712.         );

  713.         ThinStatistics (
  714.             "\t|                                                                           UNCOLLATERALIZED POSITIVE EXPOSURE PV                                                                       |",
  715.             exposureAdjustmentAggregator.vertexDates(),
  716.             exposureAdjustmentDigest.uncollateralizedPositiveExposurePV()
  717.         );

  718.         ThinStatistics (
  719.             "\t|                                                                            COLLATERALIZED NEGATIVE EXPOSURE PV                                                                        |",
  720.             exposureAdjustmentAggregator.vertexDates(),
  721.             exposureAdjustmentDigest.collateralizedNegativeExposurePV()
  722.         );

  723.         ThinStatistics (
  724.             "\t|                                                                           UNCOLLATERALIZED NEGATIVE EXPOSURE PV                                                                       |",
  725.             exposureAdjustmentAggregator.vertexDates(),
  726.             exposureAdjustmentDigest.uncollateralizedNegativeExposurePV()
  727.         );

  728.         System.out.println();

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

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

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

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

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

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

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

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

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

  738.         ThinStatistics (
  739.             "\t||  UCVA  => ",
  740.             exposureAdjustmentDigest.ucva()
  741.         );

  742.         ThinStatistics (
  743.             "\t|| FTDCVA => ",
  744.             exposureAdjustmentDigest.ftdcva()
  745.         );

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

  750.         ThinStatistics (
  751.             "\t||  CVACL => ",
  752.             exposureAdjustmentDigest.cvacl()
  753.         );

  754.         ThinStatistics (
  755.             "\t||   DVA  => ",
  756.             exposureAdjustmentDigest.dva()
  757.         );

  758.         ThinStatistics (
  759.             "\t||   FVA  => ",
  760.             exposureAdjustmentDigest.fva()
  761.         );

  762.         ThinStatistics (
  763.             "\t||   FDA  => ",
  764.             exposureAdjustmentDigest.fda()
  765.         );

  766.         ThinStatistics (
  767.             "\t||   FCA  => ",
  768.             exposureAdjustmentDigest.fca()
  769.         );

  770.         ThinStatistics (
  771.             "\t||   FBA  => ",
  772.             exposureAdjustmentDigest.fba()
  773.         );

  774.         ThinStatistics (
  775.             "\t||  SFVA  => ",
  776.             exposureAdjustmentDigest.sfva()
  777.         );

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

  779.         ThinStatistics (
  780.             "\t||  Total => ",
  781.             exposureAdjustmentDigest.totalVA()
  782.         );

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

  784.         EnvManager.TerminateEnv();
  785.     }
  786. }