EulerTrajectoryEvolutionScheme.java

  1. package org.drip.sample.burgard2012;

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

  5. import org.drip.analytics.date.*;
  6. import org.drip.analytics.support.VertexDateBuilder;
  7. import org.drip.exposure.evolver.*;
  8. import org.drip.exposure.universe.*;
  9. import org.drip.measure.crng.RandomNumberGenerator;
  10. import org.drip.measure.discrete.CorrelatedPathVertexDimension;
  11. import org.drip.measure.dynamics.*;
  12. import org.drip.measure.process.*;
  13. import org.drip.numerical.common.FormatUtil;
  14. import org.drip.numerical.linearalgebra.Matrix;
  15. import org.drip.service.env.EnvManager;
  16. import org.drip.state.identifier.*;
  17. import org.drip.xva.definition.*;
  18. import org.drip.xva.derivative.*;
  19. import org.drip.xva.pde.*;

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

  23. /*!
  24.  * Copyright (C) 2020 Lakshmi Krishnamurthy
  25.  * Copyright (C) 2019 Lakshmi Krishnamurthy
  26.  * Copyright (C) 2018 Lakshmi Krishnamurthy
  27.  * Copyright (C) 2017 Lakshmi Krishnamurthy
  28.  *
  29.  *  This file is part of DROP, an open-source library targeting analytics/risk, transaction cost analytics,
  30.  *      asset liability management analytics, capital, exposure, and margin analytics, valuation adjustment
  31.  *      analytics, and portfolio construction analytics within and across fixed income, credit, commodity,
  32.  *      equity, FX, and structured products. It also includes auxiliary libraries for algorithm support,
  33.  *      numerical analysis, numerical optimization, spline builder, model validation, statistical learning,
  34.  *      and computational support.
  35.  *  
  36.  *      https://lakshmidrip.github.io/DROP/
  37.  *  
  38.  *  DROP is composed of three modules:
  39.  *  
  40.  *  - DROP Product Core - https://lakshmidrip.github.io/DROP-Product-Core/
  41.  *  - DROP Portfolio Core - https://lakshmidrip.github.io/DROP-Portfolio-Core/
  42.  *  - DROP Computational Core - https://lakshmidrip.github.io/DROP-Computational-Core/
  43.  *
  44.  *  DROP Product Core implements libraries for the following:
  45.  *  - Fixed Income Analytics
  46.  *  - Loan Analytics
  47.  *  - Transaction Cost Analytics
  48.  *
  49.  *  DROP Portfolio Core implements libraries for the following:
  50.  *  - Asset Allocation Analytics
  51.  *  - Asset Liability Management Analytics
  52.  *  - Capital Estimation Analytics
  53.  *  - Exposure Analytics
  54.  *  - Margin Analytics
  55.  *  - XVA Analytics
  56.  *
  57.  *  DROP Computational Core implements libraries for the following:
  58.  *  - Algorithm Support
  59.  *  - Computation Support
  60.  *  - Function Analysis
  61.  *  - Model Validation
  62.  *  - Numerical Analysis
  63.  *  - Numerical Optimizer
  64.  *  - Spline Builder
  65.  *  - Statistical Learning
  66.  *
  67.  *  Documentation for DROP is Spread Over:
  68.  *
  69.  *  - Main                     => https://lakshmidrip.github.io/DROP/
  70.  *  - Wiki                     => https://github.com/lakshmiDRIP/DROP/wiki
  71.  *  - GitHub                   => https://github.com/lakshmiDRIP/DROP
  72.  *  - Repo Layout Taxonomy     => https://github.com/lakshmiDRIP/DROP/blob/master/Taxonomy.md
  73.  *  - Javadoc                  => https://lakshmidrip.github.io/DROP/Javadoc/index.html
  74.  *  - Technical Specifications => https://github.com/lakshmiDRIP/DROP/tree/master/Docs/Internal
  75.  *  - Release Versions         => https://lakshmidrip.github.io/DROP/version.html
  76.  *  - Community Credits        => https://lakshmidrip.github.io/DROP/credits.html
  77.  *  - Issues Catalog           => https://github.com/lakshmiDRIP/DROP/issues
  78.  *  - JUnit                    => https://lakshmidrip.github.io/DROP/junit/index.html
  79.  *  - Jacoco                   => https://lakshmidrip.github.io/DROP/jacoco/index.html
  80.  *
  81.  *  Licensed under the Apache License, Version 2.0 (the "License");
  82.  *      you may not use this file except in compliance with the License.
  83.  *  
  84.  *  You may obtain a copy of the License at
  85.  *      http://www.apache.org/licenses/LICENSE-2.0
  86.  *  
  87.  *  Unless required by applicable law or agreed to in writing, software
  88.  *      distributed under the License is distributed on an "AS IS" BASIS,
  89.  *      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  90.  *  
  91.  *  See the License for the specific language governing permissions and
  92.  *      limitations under the License.
  93.  */

  94. /**
  95.  * <i>EulerTrajectoryEvolutionScheme</i> computes the Sequence of XVA Paths arising out of the Joint
  96.  * Evolution of Numeraires - the Continuous Asset, the Collateral, the Bank, and the Counter-Party Numeraires
  97.  * involved in the Dynamic XVA Replication Portfolio of the Burgard and Kjaer (2011) Methodology. The
  98.  * References are:
  99.  *  
  100.  * <br><br>
  101.  *  <ul>
  102.  *      <li>
  103.  *          Burgard, C., and M. Kjaer (2014): PDE Representations of Derivatives with Bilateral Counter-party
  104.  *              Risk and Funding Costs <i>Journal of Credit Risk</i> <b>7 (3)</b> 1-19
  105.  *      </li>
  106.  *      <li>
  107.  *          Cesari, G., J. Aquilina, N. Charpillon, X. Filipovic, G. Lee, and L. Manda (2009): <i>Modeling,
  108.  *              Pricing, and Hedging Counter-party Credit Exposure - A Technical Guide</i> <b>Springer
  109.  *              Finance</b> New York
  110.  *      </li>
  111.  *      <li>
  112.  *          Gregory, J. (2009): Being Two-faced over Counter-party Credit Risk <i>Risk</i> <b>20 (2)</b>
  113.  *              86-90
  114.  *      </li>
  115.  *      <li>
  116.  *          Li, B., and Y. Tang (2007): <i>Quantitative Analysis, Derivatives Modeling, and Trading
  117.  *              Strategies in the Presence of Counter-party Credit Risk for the Fixed Income Market</i>
  118.  *              <b>World Scientific Publishing</b> Singapore
  119.  *      </li>
  120.  *      <li>
  121.  *          Piterbarg, V. (2010): Funding Beyond Discounting: Collateral Agreements and Derivatives Pricing
  122.  *              <i>Risk</i> <b>21 (2)</b> 97-102
  123.  *      </li>
  124.  *  </ul>
  125.  *  
  126.  * <br><br>
  127.  *  <ul>
  128.  *      <li><b>Module </b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/PortfolioCore.md">Portfolio Core Module</a></li>
  129.  *      <li><b>Library</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/XVAAnalyticsLibrary.md">XVA Analytics Library</a></li>
  130.  *      <li><b>Project</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/sample/README.md">DROP API Construction and Usage</a></li>
  131.  *      <li><b>Package</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/sample/burgard2012/README.md">Burgard Kjaer (2012) Valuation Adjustments</a></li>
  132.  *  </ul>
  133.  * <br><br>
  134.  *
  135.  * @author Lakshmi Krishnamurthy
  136.  */

  137. public class EulerTrajectoryEvolutionScheme {

  138.     private static final PrimarySecurity AssetValueReplicator (
  139.         final String currency)
  140.         throws Exception
  141.     {
  142.         double assetValueReplicatorDrift = 0.0025;
  143.         double assetValueReplicatorVolatility = 0.10;
  144.         double assetValueReplicatorRepo = 0.03;
  145.         double assetValueReplicatorDividend = 0.02;

  146.         EntityEquityLabel equityLabel = EntityEquityLabel.Standard (
  147.             "AAPL",
  148.             currency
  149.         );

  150.         return new PrimarySecurity (
  151.             "AAPL",
  152.             equityLabel,
  153.             new DiffusionEvolver (
  154.                 DiffusionEvaluatorLogarithmic.Standard (
  155.                     assetValueReplicatorDrift - assetValueReplicatorDividend,
  156.                     assetValueReplicatorVolatility
  157.                 )
  158.             ),
  159.             assetValueReplicatorRepo
  160.         );
  161.     }

  162.     private static final PrimarySecurity OvernightReplicator (
  163.         final String currency,
  164.         final List<LatentStateLabel> latentStateLabelList)
  165.         throws Exception
  166.     {
  167.         double overnightReplicatorDrift = 0.0025;
  168.         double overnightReplicatorVolatility = 0.001;
  169.         double overnightReplicatorRepo = 0.0;

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

  171.         latentStateLabelList.add (overnightLabel);

  172.         return new PrimarySecurity (
  173.             currency + "_OVERNIGHT",
  174.             overnightLabel,
  175.             new DiffusionEvolver (
  176.                 DiffusionEvaluatorLogarithmic.Standard (
  177.                     overnightReplicatorDrift,
  178.                     overnightReplicatorVolatility
  179.                 )
  180.             ),
  181.             overnightReplicatorRepo
  182.         );
  183.     }

  184.     private static final PrimarySecurity CSAReplicator (
  185.         final String currency,
  186.         final List<LatentStateLabel> latentStateLabelList)
  187.         throws Exception
  188.     {
  189.         double csaReplicatorDrift = 0.01;
  190.         double csaReplicatorVolatility = 0.002;
  191.         double csaReplicatorRepo = 0.005;

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

  193.         latentStateLabelList.add (csaLabel);

  194.         return new PrimarySecurity (
  195.             currency + "_CSA",
  196.             csaLabel,
  197.             new DiffusionEvolver (
  198.                 DiffusionEvaluatorLogarithmic.Standard (
  199.                     csaReplicatorDrift,
  200.                     csaReplicatorVolatility
  201.                 )
  202.             ),
  203.             csaReplicatorRepo
  204.         );
  205.     }

  206.     private static final PrimarySecurity DealerSeniorFundingReplicator (
  207.         final String currency,
  208.         final String dealer,
  209.         final List<LatentStateLabel> latentStateLabelList)
  210.         throws Exception
  211.     {
  212.         double dealerSeniorFundingReplicatorDrift = 0.03;
  213.         double dealerSeniorFundingReplicatorVolatility = 0.002;
  214.         double dealerSeniorFundingReplicatorRepo = 0.028;

  215.         LatentStateLabel dealerSeniorFundingLabel = EntityFundingLabel.Senior (
  216.             dealer,
  217.             currency
  218.         );

  219.         latentStateLabelList.add (dealerSeniorFundingLabel);

  220.         return new PrimarySecurity (
  221.             dealer + "_" + currency + "_SENIOR_ZERO",
  222.             dealerSeniorFundingLabel,
  223.             new JumpDiffusionEvolver (
  224.                 DiffusionEvaluatorLogarithmic.Standard (
  225.                     dealerSeniorFundingReplicatorDrift,
  226.                     dealerSeniorFundingReplicatorVolatility
  227.                 ),
  228.                 HazardJumpEvaluator.Standard (
  229.                     0.3,
  230.                     0.45
  231.                 )
  232.             ),
  233.             dealerSeniorFundingReplicatorRepo
  234.         );
  235.     }

  236.     private static final PrimarySecurity DealerSubordinateFundingReplicator (
  237.         final String currency,
  238.         final String dealer,
  239.         final List<LatentStateLabel> latentStateLabelList)
  240.         throws Exception
  241.     {
  242.         double dealerSubordinateFundingReplicatorDrift = 0.045;
  243.         double dealerSubordinateFundingReplicatorVolatility = 0.002;
  244.         double dealerSubordinateFundingReplicatorRepo = 0.028;

  245.         LatentStateLabel dealerSubordinateFundingLabel = EntityFundingLabel.Subordinate (
  246.             dealer,
  247.             currency
  248.         );

  249.         latentStateLabelList.add (dealerSubordinateFundingLabel);

  250.         return new PrimarySecurity (
  251.             dealer + "_" + currency + "_SUBORDINATE_ZERO",
  252.             dealerSubordinateFundingLabel,
  253.             new JumpDiffusionEvolver (
  254.                 DiffusionEvaluatorLogarithmic.Standard (
  255.                     dealerSubordinateFundingReplicatorDrift,
  256.                     dealerSubordinateFundingReplicatorVolatility
  257.                 ),
  258.                 HazardJumpEvaluator.Standard (
  259.                     0.3,
  260.                     0.25
  261.                 )
  262.             ),
  263.             dealerSubordinateFundingReplicatorRepo
  264.         );
  265.     }

  266.     private static final PrimarySecurity ClientFundingReplicator (
  267.         final String currency,
  268.         final String client,
  269.         final List<LatentStateLabel> latentStateLabelList)
  270.         throws Exception
  271.     {
  272.         double clientFundingReplicatorDrift = 0.03;
  273.         double clientFundingReplicatorVolatility = 0.003;
  274.         double clientFundingReplicatorRepo = 0.028;

  275.         LatentStateLabel clientFundingLabel = EntityFundingLabel.Senior (
  276.             client,
  277.             currency
  278.         );

  279.         latentStateLabelList.add (clientFundingLabel);

  280.         return new PrimarySecurity (
  281.             client + "_" + currency + "_SENIOR_ZERO",
  282.             clientFundingLabel,
  283.             new JumpDiffusionEvolver (
  284.                 DiffusionEvaluatorLogarithmic.Standard (
  285.                     clientFundingReplicatorDrift,
  286.                     clientFundingReplicatorVolatility
  287.                 ),
  288.                 HazardJumpEvaluator.Standard (
  289.                     0.5,
  290.                     0.30
  291.                 )
  292.             ),
  293.             clientFundingReplicatorRepo
  294.         );
  295.     }

  296.     private static final PrimarySecurityDynamicsContainer PrimarySecurityEvolver (
  297.         final String currency,
  298.         final String dealer,
  299.         final String client,
  300.         final List<LatentStateLabel> latentStateLabelList)
  301.         throws Exception
  302.     {
  303.         List<PrimarySecurity> assetList = new ArrayList<PrimarySecurity>();

  304.         assetList.add (AssetValueReplicator (currency));

  305.         return new PrimarySecurityDynamicsContainer (
  306.             assetList,
  307.             OvernightReplicator (
  308.                 currency,
  309.                 latentStateLabelList
  310.             ),
  311.             CSAReplicator (
  312.                 currency,
  313.                 latentStateLabelList
  314.             ),
  315.             DealerSeniorFundingReplicator (
  316.                 currency,
  317.                 dealer,
  318.                 latentStateLabelList
  319.             ),
  320.             DealerSubordinateFundingReplicator (
  321.                 currency,
  322.                 dealer,
  323.                 latentStateLabelList
  324.             ),
  325.             ClientFundingReplicator (
  326.                 currency,
  327.                 client,
  328.                 latentStateLabelList
  329.             )
  330.         );
  331.     }

  332.     private static final TerminalLatentState DealerHazard (
  333.         final String currency,
  334.         final String dealer,
  335.         final List<LatentStateLabel> latentStateLabelList)
  336.         throws Exception
  337.     {
  338.         double dealerHazardDrift = 0.0002;
  339.         double dealerHazardVolatility = 0.02;

  340.         LatentStateLabel dealerHazardLabel = EntityHazardLabel.Standard (
  341.             dealer,
  342.             currency
  343.         );

  344.         latentStateLabelList.add (dealerHazardLabel);

  345.         return new TerminalLatentState (
  346.             dealerHazardLabel,
  347.             new DiffusionEvolver (
  348.                 DiffusionEvaluatorLogarithmic.Standard (
  349.                     dealerHazardDrift,
  350.                     dealerHazardVolatility
  351.                 )
  352.             )
  353.         );
  354.     }

  355.     private static final TerminalLatentState DealerRecovery (
  356.         final String currency,
  357.         final String dealer,
  358.         final List<LatentStateLabel> latentStateLabelList)
  359.         throws Exception
  360.     {
  361.         double dealerRecoveryDrift = 0.0002;
  362.         double dealerRecoveryVolatility = 0.02;

  363.         LatentStateLabel dealerRecoveryLabel = EntityRecoveryLabel.Senior (
  364.             dealer,
  365.             currency
  366.         );

  367.         latentStateLabelList.add (dealerRecoveryLabel);

  368.         return new TerminalLatentState (
  369.             dealerRecoveryLabel,
  370.             new DiffusionEvolver (
  371.                 DiffusionEvaluatorLogarithmic.Standard (
  372.                     dealerRecoveryDrift,
  373.                     dealerRecoveryVolatility
  374.                 )
  375.             )
  376.         );
  377.     }

  378.     private static final TerminalLatentState ClientHazard (
  379.         final String currency,
  380.         final String client,
  381.         final List<LatentStateLabel> latentStateLabelList)
  382.         throws Exception
  383.     {
  384.         double clientHazardDrift = 0.0002;
  385.         double clientHazardVolatility = 0.02;

  386.         LatentStateLabel clientHazardLabel = EntityHazardLabel.Standard (
  387.             client,
  388.             currency
  389.         );

  390.         latentStateLabelList.add (clientHazardLabel);

  391.         return new TerminalLatentState (
  392.             clientHazardLabel,
  393.             new DiffusionEvolver (
  394.                 DiffusionEvaluatorLogarithmic.Standard (
  395.                     clientHazardDrift,
  396.                     clientHazardVolatility
  397.                 )
  398.             )
  399.         );
  400.     }

  401.     private static final TerminalLatentState ClientRecovery (
  402.         final String currency,
  403.         final String client,
  404.         final List<LatentStateLabel> latentStateLabelList)
  405.         throws Exception
  406.     {
  407.         double clientRecoveryDrift = 0.0002;
  408.         double clientRecoveryVolatility = 0.02;

  409.         LatentStateLabel clientRecoveryLabel = EntityRecoveryLabel.Senior (
  410.             client,
  411.             currency
  412.         );

  413.         latentStateLabelList.add (clientRecoveryLabel);

  414.         return new TerminalLatentState (
  415.             clientRecoveryLabel,
  416.             new DiffusionEvolver (
  417.                 DiffusionEvaluatorLogarithmic.Standard (
  418.                     clientRecoveryDrift,
  419.                     clientRecoveryVolatility
  420.                 )
  421.             )
  422.         );
  423.     }

  424.     private static final EntityDynamicsContainer EntityEvolver (
  425.         final String currency,
  426.         final String dealer,
  427.         final String client,
  428.         final List<LatentStateLabel> latentStateLabelList)
  429.         throws Exception
  430.     {
  431.         return new EntityDynamicsContainer (
  432.             DealerHazard (
  433.                 currency,
  434.                 dealer,
  435.                 latentStateLabelList
  436.             ),
  437.             DealerRecovery (
  438.                 currency,
  439.                 dealer,
  440.                 latentStateLabelList
  441.             ),
  442.             null,
  443.             ClientHazard (
  444.                 currency,
  445.                 client,
  446.                 latentStateLabelList
  447.             ),
  448.             ClientRecovery (
  449.                 currency,
  450.                 client,
  451.                 latentStateLabelList
  452.             )
  453.         );
  454.     }

  455.     private static final LatentStateDynamicsContainer LatentStateEvolver (
  456.         final EntityEquityLabel equityLabel,
  457.         final List<LatentStateLabel> latentStateLabelList)
  458.         throws Exception
  459.     {
  460.         double assetValueReplicatorDrift = 0.0025;
  461.         double assetValueReplicatorVolatility = 0.10;

  462.         latentStateLabelList.add (equityLabel);

  463.         LatentStateDynamicsContainer latentStateDynamicsContainer = new LatentStateDynamicsContainer();

  464.         latentStateDynamicsContainer.addEntityEquity (
  465.             new TerminalLatentState (
  466.                 equityLabel,
  467.                 new DiffusionEvolver (
  468.                     DiffusionEvaluatorLinear.Standard (
  469.                         assetValueReplicatorDrift,
  470.                         assetValueReplicatorVolatility
  471.                     )
  472.                 )
  473.             )
  474.         );

  475.         return latentStateDynamicsContainer;
  476.     }

  477.     private static final MarketVertexGenerator ConstructMarketVertexGenerator (
  478.         final JulianDate spotDate,
  479.         final int[] eventVertexArray,
  480.         final String currency,
  481.         final String dealer,
  482.         final String client,
  483.         final EntityEquityLabel equityLabel,
  484.         final List<LatentStateLabel> latentStateLabelList)
  485.         throws Exception
  486.     {
  487.         return new MarketVertexGenerator (
  488.             spotDate.julian(),
  489.             eventVertexArray,
  490.             EntityEvolver (
  491.                 currency,
  492.                 dealer,
  493.                 client,
  494.                 latentStateLabelList
  495.             ),
  496.             PrimarySecurityEvolver (
  497.                 currency,
  498.                 dealer,
  499.                 client,
  500.                 latentStateLabelList
  501.             ),
  502.             LatentStateEvolver (
  503.                 equityLabel,
  504.                 latentStateLabelList
  505.             )
  506.         );
  507.     }

  508.     private static final MarketVertex[] MarketVertexArray (
  509.         final Map<Integer, MarketVertex> marketVertexMap)
  510.         throws Exception
  511.     {
  512.         int marketVertexCount = marketVertexMap.size();

  513.         int marketVertexIndex = 0;
  514.         MarketVertex[] marketVertexArray = new MarketVertex[marketVertexCount];

  515.         for (Map.Entry<Integer, MarketVertex> marketVertexMapEntry : marketVertexMap.entrySet())
  516.         {
  517.             marketVertexArray[marketVertexIndex++] = marketVertexMapEntry.getValue();
  518.         }

  519.         return marketVertexArray;
  520.     }

  521.     public static final void main (
  522.         final String[] astrArgs)
  523.         throws Exception
  524.     {
  525.         EnvManager.InitEnv ("");

  526.         String dealer = "WFC";
  527.         String client = "BAC";
  528.         int vertexCount = 24;
  529.         String currency = "USD";
  530.         int simulationDuration = 365;

  531.         double dealerHazardRateInitial = 0.03;
  532.         double clientHazardRateInitial = 0.05;
  533.         double dealerSeniorRecoveryRateInitial = 0.40;
  534.         double clientRecoveryRateInitial = 0.40;

  535.         double[][] latentStateCorrelationMatrix = new double[][]
  536.         {
  537.             {1.00, 0.00, 0.20, 0.15, 0.05, 0.00, 0.00, 0.00, 0.00, 0.00}, // #0  DEALER HAZARD
  538.             {0.00, 1.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00}, // #1  DEALER SENIOR RECOVERY
  539.             {0.20, 0.00, 1.00, 0.13, 0.25, 0.00, 0.00, 0.00, 0.00, 0.00}, // #2  CLIENT HAZARD
  540.             {0.15, 0.00, 0.13, 1.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00}, // #3  CLIENT RECOVERY
  541.             {0.05, 0.00, 0.25, 0.00, 1.00, 0.00, 0.00, 0.00, 0.00, 0.00}, // #4  OVERNIGHT REPLICATOR
  542.             {0.00, 0.00, 0.00, 0.00, 0.00, 1.00, 0.00, 0.00, 0.00, 0.00}, // #5  CSA REPLICATOR
  543.             {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
  544.             {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
  545.             {0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 1.00, 0.00}, // #8  CLIENT FUNDING REPLICATOR
  546.             {0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 1.00}, // #9  EQUITY REPLICATOR
  547.         };

  548.         double dblTerminalXVADerivativeValue = 1.;

  549.         double dblSensitivityShiftFactor = 0.001;

  550.         JulianDate spotDateJulian = DateUtil.Today();

  551.         int spotDate = spotDateJulian.julian();

  552.         int[] eventVertexArray = VertexDateBuilder.EqualWidth (
  553.             spotDate,
  554.             spotDate + simulationDuration,
  555.             vertexCount
  556.         );

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

  558.         EntityEquityLabel equityLabel = EntityEquityLabel.Standard (
  559.             "AAPL",
  560.             currency
  561.         );

  562.         MarketVertexGenerator marketVertexGenerator = ConstructMarketVertexGenerator (
  563.             spotDateJulian,
  564.             eventVertexArray,
  565.             currency,
  566.             dealer,
  567.             client,
  568.             equityLabel,
  569.             latentStateLabelList
  570.         );

  571.         System.out.println ("marketVertexGenerator = " + marketVertexGenerator);

  572.         LatentStateVertexContainer latentStateVertexContainer = new LatentStateVertexContainer();

  573.         latentStateVertexContainer.add (
  574.             equityLabel,
  575.             1.
  576.         );

  577.         MarketVertex initialMarketVertex = MarketVertex.Epochal (
  578.             spotDateJulian,
  579.             1.000,
  580.             1.000,
  581.             dealerHazardRateInitial,
  582.             dealerSeniorRecoveryRateInitial,
  583.             dealerHazardRateInitial / (1 - dealerSeniorRecoveryRateInitial),
  584.             clientHazardRateInitial,
  585.             clientRecoveryRateInitial,
  586.             clientHazardRateInitial / (1 - clientRecoveryRateInitial),
  587.             latentStateVertexContainer
  588.         );

  589.         CorrelatedPathVertexDimension correlatedPathVertexDimension = new CorrelatedPathVertexDimension (
  590.             new RandomNumberGenerator(),
  591.             latentStateCorrelationMatrix,
  592.             vertexCount,
  593.             1,
  594.             true,
  595.             null
  596.         );

  597.         MarketVertex[] aMVBase = MarketVertexArray (
  598.             marketVertexGenerator.marketVertex (
  599.                 initialMarketVertex,
  600.                 LatentStateWeiner.FromUnitRandom (
  601.                     latentStateLabelList,
  602.                     Matrix.Transpose (correlatedPathVertexDimension.straightPathVertexRd().flatform())
  603.                 )
  604.             )
  605.         );

  606.         MarketVertex[] aMV = new MarketVertex[aMVBase.length];
  607.         double dblDerivativeValue = dblTerminalXVADerivativeValue;
  608.         double dblDerivativeXVAValue = dblTerminalXVADerivativeValue;

  609.         for (int i = 0; i < aMV.length; ++i)
  610.             aMV[i] = aMVBase[aMV.length - 1 - i];

  611.         PDEEvolutionControl pdeec = new PDEEvolutionControl (
  612.             PDEEvolutionControl.CLOSEOUT_GREGORY_LI_TANG,
  613.             dblSensitivityShiftFactor
  614.         );

  615.         CloseOutBilateral cob = new CloseOutBilateral (
  616.             dealerSeniorRecoveryRateInitial,
  617.             clientRecoveryRateInitial
  618.         );

  619.         TrajectoryEvolutionScheme tes = new TrajectoryEvolutionScheme (
  620.             marketVertexGenerator.primarySecurityDynamicsContainer(),
  621.             pdeec
  622.         );

  623.         BurgardKjaerOperator bko = new BurgardKjaerOperator (
  624.             marketVertexGenerator.primarySecurityDynamicsContainer(),
  625.             pdeec
  626.         );

  627.         PositionGreekVertex agvInitial = new PositionGreekVertex (
  628.             dblDerivativeXVAValue,
  629.             -1.,
  630.             0.,
  631.             dblDerivativeValue
  632.         );

  633.         double dblGainOnBankDefaultInitial = -1. * (dblDerivativeXVAValue - cob.dealerDefault
  634.             (dblDerivativeXVAValue));

  635.         double dblGainOnCounterPartyDefaultInitial = -1. * (dblDerivativeXVAValue - cob.clientDefault
  636.             (dblDerivativeXVAValue));

  637.         ReplicationPortfolioVertex rpvInitial = ReplicationPortfolioVertex.Standard (
  638.             1.,
  639.             dblGainOnBankDefaultInitial,
  640.             dblGainOnCounterPartyDefaultInitial,
  641.             0.
  642.         );

  643.         System.out.println();

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

  645.         System.out.println ("\t||                                            BILATERAL XVA EVOLVER - BURGARD & KJAER (2011) REPLICATION PORTFOLIO EVOLUTION                                             ||");

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

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

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

  649.         System.out.println ("\t||            - Derivative XVA Value                                                                                                                                     ||");

  650.         System.out.println ("\t||            - Asset Price Realization                                                                                                                                  ||");

  651.         System.out.println ("\t||            - Realization of the Zero Coupon Bank Bond Price                                                                                                           ||");

  652.         System.out.println ("\t||            - Realization of the Zero Coupon Counter Party Bond Price                                                                                                  ||");

  653.         System.out.println ("\t||            - Realization of the Zero Coupon Collateral Bond Price                                                                                                     ||");

  654.         System.out.println ("\t||            - Derivative XVA Asset Replication Units                                                                                                                   ||");

  655.         System.out.println ("\t||            - Derivative XVA Value Bank Bond Replication Units                                                                                                         ||");

  656.         System.out.println ("\t||            - Derivative XVA Value Counter Party Bond Replication Units                                                                                                ||");

  657.         System.out.println ("\t||            - Derivative XVA Value Cash Account Replication Units                                                                                                      ||");

  658.         System.out.println ("\t||            - Derivative Cash Account Accumulation Component                                                                                                           ||");

  659.         System.out.println ("\t||            - Asset Cash Account Accumulation Component                                                                                                                ||");

  660.         System.out.println ("\t||            - Bank Cash Account Accumulation Component                                                                                                                 ||");

  661.         System.out.println ("\t||            - Counter Party Cash Account Accumulation Component                                                                                                        ||");

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

  663.         System.out.println ("\t||" +
  664.             FormatUtil.FormatDouble (1., 1, 6, 1.) + " | " +
  665.             FormatUtil.FormatDouble (agvInitial.derivativeXVAValue(), 1, 6, 1.) + " | " +
  666.             FormatUtil.FormatDouble (aMVBase[aMV.length - 1].latentStateValue (equityLabel), 1, 6, 1.) + " | " +
  667.             FormatUtil.FormatDouble (aMVBase[aMV.length - 1].dealer().seniorFundingReplicator(), 1, 6, 1.) + " | " +
  668.             FormatUtil.FormatDouble (aMVBase[aMV.length - 1].client().seniorFundingReplicator(), 1, 6, 1.) + " | " +
  669.             FormatUtil.FormatDouble (aMVBase[aMV.length - 1].csaReplicator(), 1, 6, 1.) + " | " +
  670.             FormatUtil.FormatDouble (rpvInitial.positionHoldings(), 1, 6, 1.) + " | " +
  671.             FormatUtil.FormatDouble (rpvInitial.dealerSeniorNumeraireHoldings(), 1, 6, 1.) + " | " +
  672.             FormatUtil.FormatDouble (rpvInitial.clientNumeraireHoldings(), 1, 6, 1.) + " | " +
  673.             FormatUtil.FormatDouble (rpvInitial.cashAccount(), 1, 6, 1.) + " | " +
  674.             FormatUtil.FormatDouble (0., 1, 6, 1.) + " | " +
  675.             FormatUtil.FormatDouble (0., 1, 6, 1.) + " | " +
  676.             FormatUtil.FormatDouble (0., 1, 6, 1.) + " | " +
  677.             FormatUtil.FormatDouble (0., 1, 6, 1.) + " ||"
  678.         );

  679.         EvolutionTrajectoryVertex etv = new EvolutionTrajectoryVertex (
  680.             1.,
  681.             rpvInitial,
  682.             agvInitial,
  683.             dblGainOnBankDefaultInitial,
  684.             dblGainOnCounterPartyDefaultInitial,
  685.             0.,
  686.             0.
  687.         );

  688.         EvolutionTrajectoryEdge[] aETE = tes.eulerWalk (
  689.             aMV,
  690.             bko,
  691.             etv,
  692.             0.
  693.         );

  694.         for (int i = vertexCount - 1; i >= 0; --i) {
  695.             etv = aETE[i].vertexFinish();

  696.             CashAccountEdge lca = aETE[i].cashAccountEdge();

  697.             System.out.println ("\t||" +
  698.                 FormatUtil.FormatDouble (etv.time(), 1, 6, 1.) + " | " +
  699.                 FormatUtil.FormatDouble (etv.positionGreekVertex().derivativeXVAValue(), 1, 6, 1.) + " | " +
  700.                 FormatUtil.FormatDouble (aMVBase[i].latentStateValue (equityLabel), 1, 6, 1.) + " | " +
  701.                 FormatUtil.FormatDouble (aMVBase[i].dealer().seniorFundingReplicator(), 1, 6, 1.) + " | " +
  702.                 FormatUtil.FormatDouble (aMVBase[i].client().seniorFundingReplicator(), 1, 6, 1.) + " | " +
  703.                 FormatUtil.FormatDouble (aMVBase[i].csaReplicator(), 1, 6, 1.) + " | " +
  704.                 FormatUtil.FormatDouble (etv.replicationPortfolioVertex().positionHoldings(), 1, 6, 1.) + " | " +
  705.                 FormatUtil.FormatDouble (etv.replicationPortfolioVertex().dealerSeniorNumeraireHoldings(), 1, 6, 1.) + " | " +
  706.                 FormatUtil.FormatDouble (etv.replicationPortfolioVertex().clientNumeraireHoldings(), 1, 6, 1.) + " | " +
  707.                 FormatUtil.FormatDouble (etv.replicationPortfolioVertex().cashAccount(), 1, 6, 1.) + " | " +
  708.                 FormatUtil.FormatDouble (lca.accumulation(), 1, 6, 1.) + " | " +
  709.                 FormatUtil.FormatDouble (lca.assetAccumulation(), 1, 6, 1.) + " | " +
  710.                 FormatUtil.FormatDouble (lca.dealerAccumulation(), 1, 6, 1.) + " | " +
  711.                 FormatUtil.FormatDouble (lca.clientAccumulation(), 1, 6, 1.) + " ||"
  712.             );
  713.         }

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

  715.         System.out.println();

  716.         EnvManager.TerminateEnv();
  717.     }
  718. }