ExposurePathLocalVolatility.java

  1. package org.drip.sample.pykhtin2009;

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

  5. import org.drip.analytics.date.DateUtil;
  6. import org.drip.analytics.date.JulianDate;
  7. import org.drip.exposure.csatimeline.AndersenPykhtinSokolLag;
  8. import org.drip.exposure.evolver.EntityDynamicsContainer;
  9. import org.drip.exposure.evolver.LatentStateDynamicsContainer;
  10. import org.drip.exposure.evolver.LatentStateVertexContainer;
  11. import org.drip.exposure.evolver.PrimarySecurity;
  12. import org.drip.exposure.evolver.PrimarySecurityDynamicsContainer;
  13. import org.drip.exposure.evolver.TerminalLatentState;
  14. import org.drip.exposure.generator.NumeraireMPoR;
  15. import org.drip.exposure.mpor.PathVariationMarginTrajectoryEstimator;
  16. import org.drip.exposure.regression.LocalVolatilityGenerationControl;
  17. import org.drip.exposure.regression.PykhtinPillarDynamics;
  18. import org.drip.exposure.universe.LatentStateWeiner;
  19. import org.drip.exposure.universe.MarketPath;
  20. import org.drip.exposure.universe.MarketVertex;
  21. import org.drip.exposure.universe.MarketVertexGenerator;
  22. import org.drip.function.definition.R1ToR1;
  23. import org.drip.measure.crng.RandomNumberGenerator;
  24. import org.drip.measure.discrete.CorrelatedPathVertexDimension;
  25. import org.drip.measure.dynamics.DiffusionEvaluatorLinear;
  26. import org.drip.measure.dynamics.DiffusionEvaluatorLogarithmic;
  27. import org.drip.measure.dynamics.HazardJumpEvaluator;
  28. import org.drip.measure.process.DiffusionEvolver;
  29. import org.drip.measure.process.JumpDiffusionEvolver;
  30. import org.drip.numerical.common.FormatUtil;
  31. import org.drip.numerical.linearalgebra.Matrix;
  32. import org.drip.service.env.EnvManager;
  33. import org.drip.state.identifier.CSALabel;
  34. import org.drip.state.identifier.EntityEquityLabel;
  35. import org.drip.state.identifier.EntityFundingLabel;
  36. import org.drip.state.identifier.EntityHazardLabel;
  37. import org.drip.state.identifier.EntityRecoveryLabel;
  38. import org.drip.state.identifier.LatentStateLabel;
  39. import org.drip.state.identifier.OvernightLabel;

  40. /*
  41.  * -*- mode: java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  42.  */

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

  83. /**
  84.  * ExposurePathLocalVolatility estimates the Path-wise Local Volatility Realizations using the Pykhtin (2009)
  85.  *  Scheme. The References are:
  86.  *  
  87.  *  - Andersen, L. B. G., M. Pykhtin, and A. Sokol (2017): Re-thinking Margin Period of Risk,
  88.  *      https://papers.ssrn.com/sol3/papers.cfm?abstract_id=2902737, eSSRN.
  89.  *  
  90.  *  - Andersen, L. B. G., M. Pykhtin, and A. Sokol (2017): Credit Exposure in the Presence of Initial Margin,
  91.  *      https://papers.ssrn.com/sol3/papers.cfm?abstract_id=2806156, eSSRN.
  92.  *  
  93.  *  - Albanese, C., and L. Andersen (2014): Accounting for OTC Derivatives: Funding Adjustments and the
  94.  *      Re-Hypothecation Option, eSSRN, https://papers.ssrn.com/sol3/papers.cfm?abstract_id=2482955.
  95.  *  
  96.  *  - Burgard, C., and M. Kjaer (2017): Derivatives Funding, Netting, and Accounting, eSSRN,
  97.  *      https://papers.ssrn.com/sol3/papers.cfm?abstract_id=2534011.
  98.  *
  99.  *  - Pykhtin, M. (2009): Modeling Counter-party Credit Exposure in the Presence of Margin Agreements,
  100.  *      http://www.risk-europe.com/protected/michael-pykhtin.pdf.
  101.  *
  102.  * @author Lakshmi Krishnamurthy
  103.  */

  104. public class ExposurePathLocalVolatility
  105. {

  106.     private static final PrimarySecurity OvernightReplicator (
  107.         final String currency,
  108.         final List<LatentStateLabel> latentStateLabelList)
  109.         throws Exception
  110.     {
  111.         double overnightReplicatorDrift = 0.0025;
  112.         double overnightReplicatorVolatility = 0.001;
  113.         double overnightReplicatorRepo = 0.0;

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

  115.         latentStateLabelList.add (overnightLabel);

  116.         return new PrimarySecurity (
  117.             currency + "_OVERNIGHT",
  118.             overnightLabel,
  119.             new DiffusionEvolver (
  120.                 DiffusionEvaluatorLogarithmic.Standard (
  121.                     overnightReplicatorDrift,
  122.                     overnightReplicatorVolatility
  123.                 )
  124.             ),
  125.             overnightReplicatorRepo
  126.         );
  127.     }

  128.     private static final PrimarySecurity CSAReplicator (
  129.         final String currency,
  130.         final List<LatentStateLabel> latentStateLabelList)
  131.         throws Exception
  132.     {
  133.         double csaReplicatorDrift = 0.01;
  134.         double csaReplicatorVolatility = 0.002;
  135.         double csaReplicatorRepo = 0.005;

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

  137.         latentStateLabelList.add (csaLabel);

  138.         return new PrimarySecurity (
  139.             currency + "_CSA",
  140.             csaLabel,
  141.             new DiffusionEvolver (
  142.                 DiffusionEvaluatorLogarithmic.Standard (
  143.                     csaReplicatorDrift,
  144.                     csaReplicatorVolatility
  145.                 )
  146.             ),
  147.             csaReplicatorRepo
  148.         );
  149.     }

  150.     private static final PrimarySecurity DealerSeniorFundingReplicator (
  151.         final String currency,
  152.         final String dealer,
  153.         final List<LatentStateLabel> latentStateLabelList)
  154.         throws Exception
  155.     {
  156.         double dealerSeniorFundingReplicatorDrift = 0.03;
  157.         double dealerSeniorFundingReplicatorVolatility = 0.002;
  158.         double dealerSeniorFundingReplicatorRepo = 0.028;

  159.         LatentStateLabel dealerSeniorFundingLabel = EntityFundingLabel.Senior (
  160.             dealer,
  161.             currency
  162.         );

  163.         latentStateLabelList.add (dealerSeniorFundingLabel);

  164.         return new PrimarySecurity (
  165.             dealer + "_" + currency + "_SENIOR_ZERO",
  166.             dealerSeniorFundingLabel,
  167.             new JumpDiffusionEvolver (
  168.                 DiffusionEvaluatorLogarithmic.Standard (
  169.                     dealerSeniorFundingReplicatorDrift,
  170.                     dealerSeniorFundingReplicatorVolatility
  171.                 ),
  172.                 HazardJumpEvaluator.Standard (
  173.                     0.3,
  174.                     0.45
  175.                 )
  176.             ),
  177.             dealerSeniorFundingReplicatorRepo
  178.         );
  179.     }

  180.     private static final PrimarySecurity DealerSubordinateFundingReplicator (
  181.         final String currency,
  182.         final String dealer,
  183.         final List<LatentStateLabel> latentStateLabelList)
  184.         throws Exception
  185.     {
  186.         double dealerSubordinateFundingReplicatorDrift = 0.045;
  187.         double dealerSubordinateFundingReplicatorVolatility = 0.002;
  188.         double dealerSubordinateFundingReplicatorRepo = 0.028;

  189.         LatentStateLabel dealerSubordinateFundingLabel = EntityFundingLabel.Subordinate (
  190.             dealer,
  191.             currency
  192.         );

  193.         latentStateLabelList.add (dealerSubordinateFundingLabel);

  194.         return new PrimarySecurity (
  195.             dealer + "_" + currency + "_SUBORDINATE_ZERO",
  196.             dealerSubordinateFundingLabel,
  197.             new JumpDiffusionEvolver (
  198.                 DiffusionEvaluatorLogarithmic.Standard (
  199.                     dealerSubordinateFundingReplicatorDrift,
  200.                     dealerSubordinateFundingReplicatorVolatility
  201.                 ),
  202.                 HazardJumpEvaluator.Standard (
  203.                     0.3,
  204.                     0.25
  205.                 )
  206.             ),
  207.             dealerSubordinateFundingReplicatorRepo
  208.         );
  209.     }

  210.     private static final PrimarySecurity ClientFundingReplicator (
  211.         final String currency,
  212.         final String client,
  213.         final List<LatentStateLabel> latentStateLabelList)
  214.         throws Exception
  215.     {
  216.         double clientFundingReplicatorDrift = 0.03;
  217.         double clientFundingReplicatorVolatility = 0.003;
  218.         double clientFundingReplicatorRepo = 0.028;

  219.         LatentStateLabel clientFundingLabel = EntityFundingLabel.Senior (
  220.             client,
  221.             currency
  222.         );

  223.         latentStateLabelList.add (clientFundingLabel);

  224.         return new PrimarySecurity (
  225.             client + "_" + currency + "_SENIOR_ZERO",
  226.             clientFundingLabel,
  227.             new JumpDiffusionEvolver (
  228.                 DiffusionEvaluatorLogarithmic.Standard (
  229.                     clientFundingReplicatorDrift,
  230.                     clientFundingReplicatorVolatility
  231.                 ),
  232.                 HazardJumpEvaluator.Standard (
  233.                     0.5,
  234.                     0.30
  235.                 )
  236.             ),
  237.             clientFundingReplicatorRepo
  238.         );
  239.     }

  240.     private static final TerminalLatentState DealerHazard (
  241.         final String currency,
  242.         final String dealer,
  243.         final List<LatentStateLabel> latentStateLabelList)
  244.         throws Exception
  245.     {
  246.         double dealerHazardDrift = 0.0002;
  247.         double dealerHazardVolatility = 0.02;

  248.         LatentStateLabel dealerHazardLabel = EntityHazardLabel.Standard (
  249.             dealer,
  250.             currency
  251.         );

  252.         latentStateLabelList.add (dealerHazardLabel);

  253.         return new TerminalLatentState (
  254.             dealerHazardLabel,
  255.             new DiffusionEvolver (
  256.                 DiffusionEvaluatorLogarithmic.Standard (
  257.                     dealerHazardDrift,
  258.                     dealerHazardVolatility
  259.                 )
  260.             )
  261.         );
  262.     }

  263.     private static final TerminalLatentState DealerRecovery (
  264.         final String currency,
  265.         final String dealer,
  266.         final List<LatentStateLabel> latentStateLabelList)
  267.         throws Exception
  268.     {
  269.         double dealerRecoveryDrift = 0.0002;
  270.         double dealerRecoveryVolatility = 0.02;

  271.         LatentStateLabel dealerRecoveryLabel = EntityRecoveryLabel.Senior (
  272.             dealer,
  273.             currency
  274.         );

  275.         latentStateLabelList.add (dealerRecoveryLabel);

  276.         return new TerminalLatentState (
  277.             dealerRecoveryLabel,
  278.             new DiffusionEvolver (
  279.                 DiffusionEvaluatorLogarithmic.Standard (
  280.                     dealerRecoveryDrift,
  281.                     dealerRecoveryVolatility
  282.                 )
  283.             )
  284.         );
  285.     }

  286.     private static final TerminalLatentState ClientHazard (
  287.         final String currency,
  288.         final String client,
  289.         final List<LatentStateLabel> latentStateLabelList)
  290.         throws Exception
  291.     {
  292.         double clientHazardDrift = 0.0002;
  293.         double clientHazardVolatility = 0.02;

  294.         LatentStateLabel clientHazardLabel = EntityHazardLabel.Standard (
  295.             client,
  296.             currency
  297.         );

  298.         latentStateLabelList.add (clientHazardLabel);

  299.         return new TerminalLatentState (
  300.             clientHazardLabel,
  301.             new DiffusionEvolver (
  302.                 DiffusionEvaluatorLogarithmic.Standard (
  303.                     clientHazardDrift,
  304.                     clientHazardVolatility
  305.                 )
  306.             )
  307.         );
  308.     }

  309.     private static final TerminalLatentState ClientRecovery (
  310.         final String currency,
  311.         final String client,
  312.         final List<LatentStateLabel> latentStateLabelList)
  313.         throws Exception
  314.     {
  315.         double clientRecoveryDrift = 0.0002;
  316.         double clientRecoveryVolatility = 0.02;

  317.         LatentStateLabel clientRecoveryLabel = EntityRecoveryLabel.Senior (
  318.             client,
  319.             currency
  320.         );

  321.         latentStateLabelList.add (clientRecoveryLabel);

  322.         return new TerminalLatentState (
  323.             clientRecoveryLabel,
  324.             new DiffusionEvolver (
  325.                 DiffusionEvaluatorLogarithmic.Standard (
  326.                     clientRecoveryDrift,
  327.                     clientRecoveryVolatility
  328.                 )
  329.             )
  330.         );
  331.     }

  332.     private static final EntityDynamicsContainer EntityEvolver (
  333.         final String currency,
  334.         final String dealer,
  335.         final String client,
  336.         final List<LatentStateLabel> latentStateLabelList)
  337.         throws Exception
  338.     {
  339.         return new EntityDynamicsContainer (
  340.             DealerHazard (
  341.                 currency,
  342.                 dealer,
  343.                 latentStateLabelList
  344.             ),
  345.             DealerRecovery (
  346.                 currency,
  347.                 dealer,
  348.                 latentStateLabelList
  349.             ),
  350.             null,
  351.             ClientHazard (
  352.                 currency,
  353.                 client,
  354.                 latentStateLabelList
  355.             ),
  356.             ClientRecovery (
  357.                 currency,
  358.                 client,
  359.                 latentStateLabelList
  360.             )
  361.         );
  362.     }

  363.     private static final PrimarySecurityDynamicsContainer PrimarySecurityEvolver (
  364.         final String currency,
  365.         final String dealer,
  366.         final String client,
  367.         final List<LatentStateLabel> latentStateLabelList)
  368.         throws Exception
  369.     {
  370.         return new PrimarySecurityDynamicsContainer (
  371.             null,
  372.             OvernightReplicator (
  373.                 currency,
  374.                 latentStateLabelList
  375.             ),
  376.             CSAReplicator (
  377.                 currency,
  378.                 latentStateLabelList
  379.             ),
  380.             DealerSeniorFundingReplicator (
  381.                 currency,
  382.                 dealer,
  383.                 latentStateLabelList
  384.             ),
  385.             DealerSubordinateFundingReplicator (
  386.                 currency,
  387.                 dealer,
  388.                 latentStateLabelList
  389.             ),
  390.             ClientFundingReplicator (
  391.                 currency,
  392.                 client,
  393.                 latentStateLabelList
  394.             )
  395.         );
  396.     }

  397.     private static final LatentStateDynamicsContainer LatentStateEvolver (
  398.         final EntityEquityLabel equityLabel,
  399.         final List<LatentStateLabel> latentStateLabelList)
  400.         throws Exception
  401.     {
  402.         double equityNumeraireDrift = 0.05;
  403.         double equityNumeraireVolatility = 0.10;

  404.         latentStateLabelList.add (equityLabel);

  405.         LatentStateDynamicsContainer latentStateDynamicsContainer = new LatentStateDynamicsContainer();

  406.         latentStateDynamicsContainer.addEntityEquity (
  407.             new TerminalLatentState (
  408.                 equityLabel,
  409.                 new DiffusionEvolver (
  410.                     DiffusionEvaluatorLinear.Standard (
  411.                         equityNumeraireDrift,
  412.                         equityNumeraireVolatility
  413.                     )
  414.                 )
  415.             )
  416.         );

  417.         return latentStateDynamicsContainer;
  418.     }

  419.     private static final MarketVertexGenerator ConstructMarketVertexGenerator (
  420.         final JulianDate spotDate,
  421.         final String exposureSamplingTenor,
  422.         final int exposureSamplingNodeCount,
  423.         final String currency,
  424.         final String dealer,
  425.         final String client,
  426.         final EntityEquityLabel equityLabel,
  427.         final List<LatentStateLabel> latentStateLabelList)
  428.         throws Exception
  429.     {
  430.         JulianDate terminationDate = spotDate;
  431.         int[] eventVertexArray = new int[exposureSamplingNodeCount];

  432.         for (int i = 0; i < exposureSamplingNodeCount; ++i)
  433.         {
  434.             terminationDate = terminationDate.addTenor (exposureSamplingTenor);

  435.             eventVertexArray[i] = terminationDate.julian();
  436.         }

  437.         return new MarketVertexGenerator (
  438.             spotDate.julian(),
  439.             eventVertexArray,
  440.             EntityEvolver (
  441.                 currency,
  442.                 dealer,
  443.                 client,
  444.                 latentStateLabelList
  445.             ),
  446.             PrimarySecurityEvolver (
  447.                 currency,
  448.                 dealer,
  449.                 client,
  450.                 latentStateLabelList
  451.             ),
  452.             LatentStateEvolver (
  453.                 equityLabel,
  454.                 latentStateLabelList
  455.             )
  456.         );
  457.     }

  458.     public static final void main (
  459.         final String[] args)
  460.         throws Exception
  461.     {
  462.         EnvManager.InitEnv ("");

  463.         JulianDate spotDate = DateUtil.CreateFromYMD (
  464.             2018,
  465.             DateUtil.APRIL,
  466.             19
  467.         );

  468.         int pathCount = 10000;
  469.         String exposurePeriodTenor = "6M";
  470.         int exposurePeriodCount = 15;
  471.         String currency = "USD";
  472.         String dealer = "NOM";
  473.         String client = "SSGA";
  474.         double[][] correlationMatrix = new double[][] {
  475.             {1.00, 0.00, 0.20, 0.15, 0.05, 0.00, 0.00, 0.00, 0.00, 0.00}, // #0  DEALER HAZARD
  476.             {0.00, 1.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00}, // #1  DEALER SENIOR RECOVERY
  477.             {0.20, 0.00, 1.00, 0.13, 0.25, 0.00, 0.00, 0.00, 0.00, 0.00}, // #2  CLIENT HAZARD
  478.             {0.15, 0.00, 0.13, 1.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00}, // #3  CLIENT RECOVERY
  479.             {0.05, 0.00, 0.25, 0.00, 1.00, 0.00, 0.00, 0.00, 0.00, 0.00}, // #4  OVERNIGHT REPLICATOR
  480.             {0.00, 0.00, 0.00, 0.00, 0.00, 1.00, 0.00, 0.00, 0.00, 0.00}, // #5  CSA REPLICATOR
  481.             {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
  482.             {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
  483.             {0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 1.00, 0.00}, // #8  CLIENT FUNDING REPLICATOR
  484.             {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
  485.         };
  486.         String referenceEntity = "HYG";
  487.         double equityNotional = 10.;

  488.         LocalVolatilityGenerationControl localVolatilityGenerationControl =
  489.             LocalVolatilityGenerationControl.Standard (pathCount);

  490.         EntityEquityLabel equityLabel = EntityEquityLabel.Standard (
  491.             referenceEntity,
  492.             currency
  493.         );

  494.         NumeraireMPoR numeraireMPoR = new NumeraireMPoR (
  495.             equityLabel,
  496.             equityNotional
  497.         );

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

  499.         MarketVertexGenerator marketVertexGenerator = ConstructMarketVertexGenerator (
  500.             spotDate,
  501.             exposurePeriodTenor,
  502.             exposurePeriodCount,
  503.             currency,
  504.             dealer,
  505.             client,
  506.             equityLabel,
  507.             latentStateLabelList
  508.         );

  509.         LatentStateVertexContainer latentStateVertexContainer = new LatentStateVertexContainer();

  510.         latentStateVertexContainer.add (
  511.             equityLabel,
  512.             10.
  513.         );

  514.         MarketVertex initialMarketVertex = MarketVertex.Epochal (
  515.             spotDate,
  516.             1.000,              // dblOvernightNumeraireInitial
  517.             1.000,              // dblCSANumeraire
  518.             0.015,              // dblBankHazardRate
  519.             0.400,              // dblBankRecoveryRate
  520.             0.015 / (1 - 0.40), // dblBankFundingSpread
  521.             0.030,              // dblCounterPartyHazardRate
  522.             0.300,              // dblCounterPartyRecoveryRate
  523.             0.030 / (1 - 0.30), // dblCounterPartyFundingSpread
  524.             latentStateVertexContainer
  525.         );

  526.         AndersenPykhtinSokolLag andersenPykhtinSokolLag = AndersenPykhtinSokolLag.ClassicalMinus();

  527.         CorrelatedPathVertexDimension correlatedPathVertexDimension = new CorrelatedPathVertexDimension (
  528.             new RandomNumberGenerator(),
  529.             correlationMatrix,
  530.             exposurePeriodCount,
  531.             1,
  532.             true,
  533.             null
  534.         );

  535.         JulianDate exposureDate = spotDate;
  536.         int[] exposureDateArray = new int[exposurePeriodCount + 1];
  537.         R1ToR1[] localVolatilityR1ToR1Array = new R1ToR1[exposurePeriodCount + 1];
  538.         double[][] pathExposureArray = new double[exposurePeriodCount + 1][pathCount];

  539.         for (int i = 0; i <= exposurePeriodCount; ++i)
  540.         {
  541.             exposureDateArray[i] = exposureDate.julian();

  542.             exposureDate = exposureDate.addTenor (exposurePeriodTenor);
  543.         }

  544.         for (int pathIndex = 0; pathIndex < pathCount; ++pathIndex)
  545.         {
  546.             MarketPath marketPath = new MarketPath (
  547.                 marketVertexGenerator.marketVertex (
  548.                     initialMarketVertex,
  549.                     LatentStateWeiner.FromUnitRandom (
  550.                         latentStateLabelList,
  551.                         Matrix.Transpose (correlatedPathVertexDimension.straightPathVertexRd().flatform())
  552.                     )
  553.                 )
  554.             );

  555.             PathVariationMarginTrajectoryEstimator variationMarginTradeTrajectoryEstimator =
  556.                 PathVariationMarginTrajectoryEstimator.Standard (
  557.                     exposureDateArray,
  558.                     currency,
  559.                     numeraireMPoR,
  560.                     marketPath,
  561.                     andersenPykhtinSokolLag
  562.                 );

  563.             Map<Integer, Double> variationMarginEstimateTrajectory =
  564.                 variationMarginTradeTrajectoryEstimator.variationMarginEstimateTrajectory();

  565.             int exposureDateIndex = 0;

  566.             for (Map.Entry<Integer, Double> variationMarginEstimateTrajectoryEntry :
  567.                 variationMarginEstimateTrajectory.entrySet())
  568.             {
  569.                 pathExposureArray[exposureDateIndex++][pathIndex] =
  570.                     variationMarginEstimateTrajectoryEntry.getValue();
  571.             }
  572.         }

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

  574.         System.out.println ("\t||      Sorted Exposure Node Realizations");

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

  576.         System.out.println ("\t||                                                      ");

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

  578.         System.out.println ("\t||            - Exposure Date                 ");

  579.         System.out.println ("\t||            - The Spot/Forward Exposures                  ");

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

  581.         for (int exposureDateIndex = 0; exposureDateIndex < exposurePeriodCount; ++exposureDateIndex)
  582.         {
  583.             String strDump = "\t|| " + new JulianDate (exposureDateArray[exposureDateIndex]) + " => ";

  584.             for (int pathIndex = 0; pathIndex < pathCount; ++pathIndex)
  585.             {
  586.                 strDump += FormatUtil.FormatDouble (pathExposureArray[exposureDateIndex][pathIndex], 3, 1, 1.) + " | ";
  587.             }

  588.             System.out.println (strDump);
  589.         }

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

  591.         System.out.println();

  592.         for (int exposureDateIndex = 0; exposureDateIndex < exposurePeriodCount; ++exposureDateIndex)
  593.         {
  594.             PykhtinPillarDynamics vertexRealization = PykhtinPillarDynamics.Standard
  595.                 (pathExposureArray [exposureDateIndex]);

  596.             localVolatilityR1ToR1Array[exposureDateIndex] = null == vertexRealization ? null :
  597.                 vertexRealization.localVolatilityR1ToR1 (localVolatilityGenerationControl);
  598.         }

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

  600.         System.out.println ("\t||           EXPOSURE DATE LOCAL VOLATILITY             ");

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

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

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

  604.         System.out.println ("\t||            - Simulation Path Number                  ");

  605.         System.out.println ("\t||            - The Spot/Forward Dates                  ");

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

  607.         for (int pathIndex = 0; pathIndex < pathCount; ++pathIndex)
  608.         {
  609.             String strDump = "\t|| " + FormatUtil.FormatDouble (pathIndex, 5, 0, 1.) + " => ";

  610.             for (int exposureDateIndex = 0; exposureDateIndex < exposurePeriodCount; ++exposureDateIndex)
  611.             {
  612.                 strDump += FormatUtil.FormatDouble (
  613.                     null == localVolatilityR1ToR1Array[exposureDateIndex] ? 0. :
  614.                     localVolatilityR1ToR1Array[exposureDateIndex].evaluate (
  615.                         pathExposureArray [exposureDateIndex][pathIndex]
  616.                     ), 1, 6, 1.
  617.                 ) + " | ";
  618.             }

  619.             System.out.println (strDump);
  620.         }

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

  622.         EnvManager.TerminateEnv();
  623.     }
  624. }