ExposurePathFixFloat.java

  1. package org.drip.sample.pykhtin2009;

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

  6. import org.drip.analytics.date.DateUtil;
  7. import org.drip.analytics.date.JulianDate;
  8. import org.drip.exposure.csatimeline.AndersenPykhtinSokolLag;
  9. import org.drip.exposure.evolver.EntityDynamicsContainer;
  10. import org.drip.exposure.evolver.LatentStateDynamicsContainer;
  11. import org.drip.exposure.evolver.LatentStateVertexContainer;
  12. import org.drip.exposure.evolver.PrimarySecurity;
  13. import org.drip.exposure.evolver.PrimarySecurityDynamicsContainer;
  14. import org.drip.exposure.evolver.TerminalLatentState;
  15. import org.drip.exposure.generator.FixFloatMPoR;
  16. import org.drip.exposure.mpor.PathVariationMarginTrajectoryEstimator;
  17. import org.drip.exposure.regression.LocalVolatilityGenerationControl;
  18. import org.drip.exposure.regression.PykhtinBrownianBridgeStretch;
  19. import org.drip.exposure.regression.PykhtinPillarDynamics;
  20. import org.drip.exposure.universe.LatentStateWeiner;
  21. import org.drip.exposure.universe.MarketPath;
  22. import org.drip.exposure.universe.MarketVertex;
  23. import org.drip.exposure.universe.MarketVertexGenerator;
  24. import org.drip.function.definition.R1ToR1;
  25. import org.drip.market.otc.FixedFloatSwapConvention;
  26. import org.drip.market.otc.IBORFixedFloatContainer;
  27. import org.drip.measure.crng.RandomNumberGenerator;
  28. import org.drip.measure.discrete.CorrelatedPathVertexDimension;
  29. import org.drip.measure.dynamics.DiffusionEvaluatorLinear;
  30. import org.drip.measure.dynamics.DiffusionEvaluatorLogarithmic;
  31. import org.drip.measure.dynamics.HazardJumpEvaluator;
  32. import org.drip.measure.gaussian.NormalQuadrature;
  33. import org.drip.measure.process.DiffusionEvolver;
  34. import org.drip.measure.process.JumpDiffusionEvolver;
  35. import org.drip.measure.statistics.UnivariateDiscreteThin;
  36. import org.drip.numerical.common.FormatUtil;
  37. import org.drip.numerical.linearalgebra.Matrix;
  38. import org.drip.product.rates.FixFloatComponent;
  39. import org.drip.service.env.EnvManager;
  40. import org.drip.state.identifier.CSALabel;
  41. import org.drip.state.identifier.EntityFundingLabel;
  42. import org.drip.state.identifier.EntityHazardLabel;
  43. import org.drip.state.identifier.EntityRecoveryLabel;
  44. import org.drip.state.identifier.ForwardLabel;
  45. import org.drip.state.identifier.LatentStateLabel;
  46. import org.drip.state.identifier.OvernightLabel;

  47. /*
  48.  * -*- mode: java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  49.  */

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

  90. /**
  91.  * ExposurePathFixFloat sets up a Brownian Bridge Based Dense Exposure Generation from Sparse Nodes for a
  92.  *  Fix-Float Swap. The References are:
  93.  *  
  94.  *  - Andersen, L. B. G., M. Pykhtin, and A. Sokol (2017): Re-thinking Margin Period of Risk,
  95.  *      https://papers.ssrn.com/sol3/papers.cfm?abstract_id=2902737, eSSRN.
  96.  *  
  97.  *  - Andersen, L. B. G., M. Pykhtin, and A. Sokol (2017): Credit Exposure in the Presence of Initial Margin,
  98.  *      https://papers.ssrn.com/sol3/papers.cfm?abstract_id=2806156, eSSRN.
  99.  *  
  100.  *  - Albanese, C., and L. Andersen (2014): Accounting for OTC Derivatives: Funding Adjustments and the
  101.  *      Re-Hypothecation Option, eSSRN, https://papers.ssrn.com/sol3/papers.cfm?abstract_id=2482955.
  102.  *  
  103.  *  - Burgard, C., and M. Kjaer (2017): Derivatives Funding, Netting, and Accounting, eSSRN,
  104.  *      https://papers.ssrn.com/sol3/papers.cfm?abstract_id=2534011.
  105.  *
  106.  *  - Pykhtin, M. (2009): Modeling Counter-party Credit Exposure in the Presence of Margin Agreements,
  107.  *      http://www.risk-europe.com/protected/michael-pykhtin.pdf.
  108.  *
  109.  * @author Lakshmi Krishnamurthy
  110.  */

  111. public class ExposurePathFixFloat
  112. {

  113.     private static final FixFloatComponent OTCIRS (
  114.         final JulianDate spotDate,
  115.         final String currency,
  116.         final String maturityTenor,
  117.         final double coupon)
  118.     {
  119.         FixedFloatSwapConvention ffConv = IBORFixedFloatContainer.ConventionFromJurisdiction (
  120.             currency,
  121.             "ALL",
  122.             maturityTenor,
  123.             "MAIN"
  124.         );

  125.         return ffConv.createFixFloatComponent (
  126.             spotDate,
  127.             maturityTenor,
  128.             coupon,
  129.             0.,
  130.             1.
  131.         );
  132.     }

  133.     private static final PrimarySecurity OvernightReplicator (
  134.         final String currency,
  135.         final List<LatentStateLabel> latentStateLabelList)
  136.         throws Exception
  137.     {
  138.         double overnightReplicatorDrift = 0.0025;
  139.         double overnightReplicatorVolatility = 0.001;
  140.         double overnightReplicatorRepo = 0.0;

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

  142.         latentStateLabelList.add (overnightLabel);

  143.         return new PrimarySecurity (
  144.             currency + "_OVERNIGHT",
  145.             overnightLabel,
  146.             new DiffusionEvolver (
  147.                 DiffusionEvaluatorLogarithmic.Standard (
  148.                     overnightReplicatorDrift,
  149.                     overnightReplicatorVolatility
  150.                 )
  151.             ),
  152.             overnightReplicatorRepo
  153.         );
  154.     }

  155.     private static final PrimarySecurity CSAReplicator (
  156.         final String currency,
  157.         final List<LatentStateLabel> latentStateLabelList)
  158.         throws Exception
  159.     {
  160.         double csaReplicatorDrift = 0.01;
  161.         double csaReplicatorVolatility = 0.002;
  162.         double csaReplicatorRepo = 0.005;

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

  164.         latentStateLabelList.add (csaLabel);

  165.         return new PrimarySecurity (
  166.             currency + "_CSA",
  167.             csaLabel,
  168.             new DiffusionEvolver (
  169.                 DiffusionEvaluatorLogarithmic.Standard (
  170.                     csaReplicatorDrift,
  171.                     csaReplicatorVolatility
  172.                 )
  173.             ),
  174.             csaReplicatorRepo
  175.         );
  176.     }

  177.     private static final PrimarySecurity DealerSeniorFundingReplicator (
  178.         final String currency,
  179.         final String dealer,
  180.         final List<LatentStateLabel> latentStateLabelList)
  181.         throws Exception
  182.     {
  183.         double dealerSeniorFundingReplicatorDrift = 0.03;
  184.         double dealerSeniorFundingReplicatorVolatility = 0.002;
  185.         double dealerSeniorFundingReplicatorRepo = 0.028;

  186.         LatentStateLabel dealerSeniorFundingLabel = EntityFundingLabel.Senior (
  187.             dealer,
  188.             currency
  189.         );

  190.         latentStateLabelList.add (dealerSeniorFundingLabel);

  191.         return new PrimarySecurity (
  192.             dealer + "_" + currency + "_SENIOR_ZERO",
  193.             dealerSeniorFundingLabel,
  194.             new JumpDiffusionEvolver (
  195.                 DiffusionEvaluatorLogarithmic.Standard (
  196.                     dealerSeniorFundingReplicatorDrift,
  197.                     dealerSeniorFundingReplicatorVolatility
  198.                 ),
  199.                 HazardJumpEvaluator.Standard (
  200.                     0.3,
  201.                     0.45
  202.                 )
  203.             ),
  204.             dealerSeniorFundingReplicatorRepo
  205.         );
  206.     }

  207.     private static final PrimarySecurity DealerSubordinateFundingReplicator (
  208.         final String currency,
  209.         final String dealer,
  210.         final List<LatentStateLabel> latentStateLabelList)
  211.         throws Exception
  212.     {
  213.         double dealerSubordinateFundingReplicatorDrift = 0.045;
  214.         double dealerSubordinateFundingReplicatorVolatility = 0.002;
  215.         double dealerSubordinateFundingReplicatorRepo = 0.028;

  216.         LatentStateLabel dealerSubordinateFundingLabel = EntityFundingLabel.Subordinate (
  217.             dealer,
  218.             currency
  219.         );

  220.         latentStateLabelList.add (dealerSubordinateFundingLabel);

  221.         return new PrimarySecurity (
  222.             dealer + "_" + currency + "_SUBORDINATE_ZERO",
  223.             dealerSubordinateFundingLabel,
  224.             new JumpDiffusionEvolver (
  225.                 DiffusionEvaluatorLogarithmic.Standard (
  226.                     dealerSubordinateFundingReplicatorDrift,
  227.                     dealerSubordinateFundingReplicatorVolatility
  228.                 ),
  229.                 HazardJumpEvaluator.Standard (
  230.                     0.3,
  231.                     0.25
  232.                 )
  233.             ),
  234.             dealerSubordinateFundingReplicatorRepo
  235.         );
  236.     }

  237.     private static final PrimarySecurity ClientFundingReplicator (
  238.         final String currency,
  239.         final String client,
  240.         final List<LatentStateLabel> latentStateLabelList)
  241.         throws Exception
  242.     {
  243.         double clientFundingReplicatorDrift = 0.03;
  244.         double clientFundingReplicatorVolatility = 0.003;
  245.         double clientFundingReplicatorRepo = 0.028;

  246.         LatentStateLabel clientFundingLabel = EntityFundingLabel.Senior (
  247.             client,
  248.             currency
  249.         );

  250.         latentStateLabelList.add (clientFundingLabel);

  251.         return new PrimarySecurity (
  252.             client + "_" + currency + "_SENIOR_ZERO",
  253.             clientFundingLabel,
  254.             new JumpDiffusionEvolver (
  255.                 DiffusionEvaluatorLogarithmic.Standard (
  256.                     clientFundingReplicatorDrift,
  257.                     clientFundingReplicatorVolatility
  258.                 ),
  259.                 HazardJumpEvaluator.Standard (
  260.                     0.5,
  261.                     0.30
  262.                 )
  263.             ),
  264.             clientFundingReplicatorRepo
  265.         );
  266.     }

  267.     private static final TerminalLatentState DealerHazard (
  268.         final String currency,
  269.         final String dealer,
  270.         final List<LatentStateLabel> latentStateLabelList)
  271.         throws Exception
  272.     {
  273.         double dealerHazardDrift = 0.0002;
  274.         double dealerHazardVolatility = 0.02;

  275.         LatentStateLabel dealerHazardLabel = EntityHazardLabel.Standard (
  276.             dealer,
  277.             currency
  278.         );

  279.         latentStateLabelList.add (dealerHazardLabel);

  280.         return new TerminalLatentState (
  281.             dealerHazardLabel,
  282.             new DiffusionEvolver (
  283.                 DiffusionEvaluatorLogarithmic.Standard (
  284.                     dealerHazardDrift,
  285.                     dealerHazardVolatility
  286.                 )
  287.             )
  288.         );
  289.     }

  290.     private static final TerminalLatentState DealerRecovery (
  291.         final String currency,
  292.         final String dealer,
  293.         final List<LatentStateLabel> latentStateLabelList)
  294.         throws Exception
  295.     {
  296.         double dealerRecoveryDrift = 0.0002;
  297.         double dealerRecoveryVolatility = 0.02;

  298.         LatentStateLabel dealerRecoveryLabel = EntityRecoveryLabel.Senior (
  299.             dealer,
  300.             currency
  301.         );

  302.         latentStateLabelList.add (dealerRecoveryLabel);

  303.         return new TerminalLatentState (
  304.             dealerRecoveryLabel,
  305.             new DiffusionEvolver (
  306.                 DiffusionEvaluatorLogarithmic.Standard (
  307.                     dealerRecoveryDrift,
  308.                     dealerRecoveryVolatility
  309.                 )
  310.             )
  311.         );
  312.     }

  313.     private static final TerminalLatentState ClientHazard (
  314.         final String currency,
  315.         final String client,
  316.         final List<LatentStateLabel> latentStateLabelList)
  317.         throws Exception
  318.     {
  319.         double clientHazardDrift = 0.0002;
  320.         double clientHazardVolatility = 0.02;

  321.         LatentStateLabel clientHazardLabel = EntityHazardLabel.Standard (
  322.             client,
  323.             currency
  324.         );

  325.         latentStateLabelList.add (clientHazardLabel);

  326.         return new TerminalLatentState (
  327.             clientHazardLabel,
  328.             new DiffusionEvolver (
  329.                 DiffusionEvaluatorLogarithmic.Standard (
  330.                     clientHazardDrift,
  331.                     clientHazardVolatility
  332.                 )
  333.             )
  334.         );
  335.     }

  336.     private static final TerminalLatentState ClientRecovery (
  337.         final String currency,
  338.         final String client,
  339.         final List<LatentStateLabel> latentStateLabelList)
  340.         throws Exception
  341.     {
  342.         double clientRecoveryDrift = 0.0002;
  343.         double clientRecoveryVolatility = 0.02;

  344.         LatentStateLabel clientRecoveryLabel = EntityRecoveryLabel.Senior (
  345.             client,
  346.             currency
  347.         );

  348.         latentStateLabelList.add (clientRecoveryLabel);

  349.         return new TerminalLatentState (
  350.             clientRecoveryLabel,
  351.             new DiffusionEvolver (
  352.                 DiffusionEvaluatorLogarithmic.Standard (
  353.                     clientRecoveryDrift,
  354.                     clientRecoveryVolatility
  355.                 )
  356.             )
  357.         );
  358.     }

  359.     private static final EntityDynamicsContainer EntityEvolver (
  360.         final String currency,
  361.         final String dealer,
  362.         final String client,
  363.         final List<LatentStateLabel> latentStateLabelList)
  364.         throws Exception
  365.     {
  366.         return new EntityDynamicsContainer (
  367.             DealerHazard (
  368.                 currency,
  369.                 dealer,
  370.                 latentStateLabelList
  371.             ),
  372.             DealerRecovery (
  373.                 currency,
  374.                 dealer,
  375.                 latentStateLabelList
  376.             ),
  377.             null,
  378.             ClientHazard (
  379.                 currency,
  380.                 client,
  381.                 latentStateLabelList
  382.             ),
  383.             ClientRecovery (
  384.                 currency,
  385.                 client,
  386.                 latentStateLabelList
  387.             )
  388.         );
  389.     }

  390.     private static final PrimarySecurityDynamicsContainer PrimarySecurityEvolver (
  391.         final String currency,
  392.         final String dealer,
  393.         final String client,
  394.         final List<LatentStateLabel> latentStateLabelList)
  395.         throws Exception
  396.     {
  397.         return new PrimarySecurityDynamicsContainer (
  398.             null,
  399.             OvernightReplicator (
  400.                 currency,
  401.                 latentStateLabelList
  402.             ),
  403.             CSAReplicator (
  404.                 currency,
  405.                 latentStateLabelList
  406.             ),
  407.             DealerSeniorFundingReplicator (
  408.                 currency,
  409.                 dealer,
  410.                 latentStateLabelList
  411.             ),
  412.             DealerSubordinateFundingReplicator (
  413.                 currency,
  414.                 dealer,
  415.                 latentStateLabelList
  416.             ),
  417.             ClientFundingReplicator (
  418.                 currency,
  419.                 client,
  420.                 latentStateLabelList
  421.             )
  422.         );
  423.     }

  424.     private static final LatentStateDynamicsContainer LatentStateEvolver (
  425.         final ForwardLabel forwardLabel,
  426.         final List<LatentStateLabel> latentStateLabelList)
  427.         throws Exception
  428.     {
  429.         double otcFixFloatNumeraireDrift = 0.0;
  430.         double otcFixFloatNumeraireVolatility = 0.10;

  431.         latentStateLabelList.add (forwardLabel);

  432.         LatentStateDynamicsContainer latentStateDynamicsContainer = new LatentStateDynamicsContainer();

  433.         latentStateDynamicsContainer.addForward (
  434.             new TerminalLatentState (
  435.                 forwardLabel,
  436.                 new DiffusionEvolver (
  437.                     DiffusionEvaluatorLinear.Standard (
  438.                         otcFixFloatNumeraireDrift,
  439.                         otcFixFloatNumeraireVolatility
  440.                     )
  441.                 )
  442.             )
  443.         );

  444.         return latentStateDynamicsContainer;
  445.     }

  446.     private static final MarketVertexGenerator ConstructMarketVertexGenerator (
  447.         final JulianDate spotDate,
  448.         final String exposureSamplingTenor,
  449.         final int exposureSamplingNodeCount,
  450.         final String currency,
  451.         final String dealer,
  452.         final String client,
  453.         final ForwardLabel forwardLabel,
  454.         final List<LatentStateLabel> latentStateLabelList)
  455.         throws Exception
  456.     {
  457.         JulianDate terminationDate = spotDate;
  458.         int[] eventVertexArray = new int[exposureSamplingNodeCount];

  459.         for (int i = 0; i < exposureSamplingNodeCount; ++i)
  460.         {
  461.             terminationDate = terminationDate.addTenor (exposureSamplingTenor);

  462.             eventVertexArray[i] = terminationDate.julian();
  463.         }

  464.         return new MarketVertexGenerator (
  465.             spotDate.julian(),
  466.             eventVertexArray,
  467.             EntityEvolver (
  468.                 currency,
  469.                 dealer,
  470.                 client,
  471.                 latentStateLabelList
  472.             ),
  473.             PrimarySecurityEvolver (
  474.                 currency,
  475.                 dealer,
  476.                 client,
  477.                 latentStateLabelList
  478.             ),
  479.             LatentStateEvolver (
  480.                 forwardLabel,
  481.                 latentStateLabelList
  482.             )
  483.         );
  484.     }

  485.     public static final void main (
  486.         final String[] args)
  487.         throws Exception
  488.     {
  489.         EnvManager.InitEnv ("");

  490.         JulianDate spotDate = DateUtil.CreateFromYMD (
  491.             2018,
  492.             DateUtil.APRIL,
  493.             19
  494.         );

  495.         int pathCount = 5000;
  496.         String latentStateGenerationTenor = "1D";
  497.         int latentStateGenerationCount = 490;
  498.         int latentStateVertexCount = latentStateGenerationCount + 10;
  499.         String currency = "USD";
  500.         String dealer = "NOM";
  501.         String client = "SSGA";
  502.         double[][] correlationMatrix = new double[][]
  503.         {
  504.             {1.00, 0.00, 0.20, 0.15, 0.05, 0.00, 0.00, 0.00, 0.00, 0.00}, // #0  DEALER HAZARD
  505.             {0.00, 1.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00}, // #1  DEALER SENIOR RECOVERY
  506.             {0.20, 0.00, 1.00, 0.13, 0.25, 0.00, 0.00, 0.00, 0.00, 0.00}, // #2  CLIENT HAZARD
  507.             {0.15, 0.00, 0.13, 1.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00}, // #3  CLIENT RECOVERY
  508.             {0.05, 0.00, 0.25, 0.00, 1.00, 0.00, 0.00, 0.00, 0.00, 0.00}, // #4  OVERNIGHT REPLICATOR
  509.             {0.00, 0.00, 0.00, 0.00, 0.00, 1.00, 0.00, 0.00, 0.00, 0.00}, // #5  CSA REPLICATOR
  510.             {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
  511.             {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
  512.             {0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 1.00, 0.00}, // #8  CLIENT FUNDING REPLICATOR
  513.             {0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 1.00}, // #9  FORWARD NUMERAIRE
  514.         };
  515.         String sparseFixFloatExposureTenor = "3M";
  516.         int sparseFixFloatExposureCount = 4;
  517.         String fixFloatMaturityTenor = "1Y";
  518.         double fixFloatCoupon = 0.02;
  519.         double fixFloatNotional = -1.e+06;

  520.         ForwardLabel forwardLabel = ForwardLabel.Create (
  521.             currency,
  522.             "3M"
  523.         );

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

  525.         MarketVertexGenerator marketVertexGenerator = ConstructMarketVertexGenerator (
  526.             spotDate,
  527.             latentStateGenerationTenor,
  528.             latentStateVertexCount,
  529.             currency,
  530.             dealer,
  531.             client,
  532.             forwardLabel,
  533.             latentStateLabelList
  534.         );

  535.         LatentStateVertexContainer latentStateVertexContainer = new LatentStateVertexContainer();

  536.         latentStateVertexContainer.add (
  537.             ForwardLabel.Create (
  538.                 currency,
  539.                 "3M"
  540.             ),
  541.             0.02
  542.         );

  543.         MarketVertex initialMarketVertex = MarketVertex.Epochal (
  544.             spotDate,
  545.             1.000,              // dblOvernightNumeraireInitial
  546.             1.000,              // dblCSANumeraire
  547.             0.015,              // dblBankHazardRate
  548.             0.400,              // dblBankRecoveryRate
  549.             0.015 / (1 - 0.40), // dblBankFundingSpread
  550.             0.030,              // dblCounterPartyHazardRate
  551.             0.300,              // dblCounterPartyRecoveryRate
  552.             0.030 / (1 - 0.30), // dblCounterPartyFundingSpread
  553.             latentStateVertexContainer
  554.         );

  555.         AndersenPykhtinSokolLag andersenPykhtinSokolLag = AndersenPykhtinSokolLag.Aggressive();

  556.         FixFloatComponent fixFloatComponent = OTCIRS (
  557.             spotDate,
  558.             currency,
  559.             fixFloatMaturityTenor,
  560.             fixFloatCoupon
  561.         );

  562.         FixFloatMPoR fixFloatMPoR = new FixFloatMPoR (
  563.             fixFloatComponent,
  564.             fixFloatNotional
  565.         );

  566.         CorrelatedPathVertexDimension correlatedPathVertexDimension = new CorrelatedPathVertexDimension (
  567.             new RandomNumberGenerator(),
  568.             correlationMatrix,
  569.             latentStateVertexCount,
  570.             1,
  571.             true,
  572.             null
  573.         );

  574.         JulianDate sparseFixFloatExposureDate = spotDate;
  575.         int[] sparseFixFloatExposureDateArray = new int[sparseFixFloatExposureCount + 1];
  576.         double[][] pathSparseExposureArray = new double[sparseFixFloatExposureCount + 1][pathCount];

  577.         for (int i = 0; i <= sparseFixFloatExposureCount; ++i)
  578.         {
  579.             sparseFixFloatExposureDateArray[i] = sparseFixFloatExposureDate.julian();

  580.             sparseFixFloatExposureDate = sparseFixFloatExposureDate.addTenor (sparseFixFloatExposureTenor);
  581.         }

  582.         List<Map<Integer, Double>> wanderTrajectoryList = new ArrayList<Map<Integer, Double>>();

  583.         for (int pathIndex = 0; pathIndex < pathCount; ++pathIndex)
  584.         {
  585.             Map<Integer, Double> wanderTrajectory = new TreeMap<Integer, Double>();

  586.             for (int denseExposureDate = spotDate.julian();
  587.                 denseExposureDate <= sparseFixFloatExposureDateArray[sparseFixFloatExposureCount];
  588.                 ++denseExposureDate)
  589.             {
  590.                 wanderTrajectory.put (
  591.                     denseExposureDate,
  592.                     NormalQuadrature.Random()
  593.                 );
  594.             }

  595.             wanderTrajectoryList.add (wanderTrajectory);
  596.         }

  597.         for (int pathIndex = 0; pathIndex < pathCount; ++pathIndex)
  598.         {
  599.             MarketPath marketPath = new MarketPath (
  600.                 marketVertexGenerator.marketVertex (
  601.                     initialMarketVertex,
  602.                     LatentStateWeiner.FromUnitRandom (
  603.                         latentStateLabelList,
  604.                         Matrix.Transpose (correlatedPathVertexDimension.straightPathVertexRd().flatform())
  605.                     )
  606.                 )
  607.             );

  608.             Map<Integer, Double> variationMarginEstimateTrajectory =
  609.                 PathVariationMarginTrajectoryEstimator.Standard (
  610.                     sparseFixFloatExposureDateArray,
  611.                     currency,
  612.                     fixFloatMPoR,
  613.                     marketPath,
  614.                     andersenPykhtinSokolLag
  615.                 ).variationMarginEstimateTrajectory();

  616.             int sparseFixFloatExposureDateIndex = 0;

  617.             for (Map.Entry<Integer, Double> variationMarginEstimateTrajectoryEntry :
  618.                 variationMarginEstimateTrajectory.entrySet())
  619.             {
  620.                 pathSparseExposureArray[sparseFixFloatExposureDateIndex++][pathIndex] =
  621.                     variationMarginEstimateTrajectoryEntry.getValue();
  622.             }
  623.         }

  624.         Map<Integer, R1ToR1> localVolatilityTrajectory = new TreeMap<Integer, R1ToR1>();

  625.         LocalVolatilityGenerationControl localVolatilityGenerationControl =
  626.             LocalVolatilityGenerationControl.Standard (pathCount);

  627.         int denseExposureDateCount = sparseFixFloatExposureDateArray[sparseFixFloatExposureCount] - spotDate.julian() + 1;

  628.         double[][] pathDenseExposureDistribution = new double[denseExposureDateCount][pathCount];

  629.         for (int exposureDateIndex = 0;
  630.             exposureDateIndex <= sparseFixFloatExposureCount;
  631.             ++exposureDateIndex)
  632.         {
  633.             PykhtinPillarDynamics vertexRealization = PykhtinPillarDynamics.Standard
  634.                 (pathSparseExposureArray [exposureDateIndex]);

  635.             localVolatilityTrajectory.put (
  636.                 sparseFixFloatExposureDateArray[exposureDateIndex],
  637.                 null == vertexRealization ? null :
  638.                     vertexRealization.localVolatilityR1ToR1 (localVolatilityGenerationControl)
  639.             );
  640.         }

  641.         for (int pathIndex = 0; pathIndex < pathCount; ++pathIndex)
  642.         {
  643.             Map<Integer, Double> sparseExposureTrajectory = new TreeMap<Integer, Double>();

  644.             for (int sparseExposureDateIndex = 0;
  645.                 sparseExposureDateIndex <= sparseFixFloatExposureCount;
  646.                 ++sparseExposureDateIndex)
  647.             {
  648.                 sparseExposureTrajectory.put (
  649.                     sparseFixFloatExposureDateArray[sparseExposureDateIndex],
  650.                     pathSparseExposureArray[sparseExposureDateIndex][pathIndex]
  651.                 );
  652.             }

  653.             Map<Integer, Double> pathDenseExposureTrajectory = new PykhtinBrownianBridgeStretch (
  654.                 sparseExposureTrajectory,
  655.                 localVolatilityTrajectory
  656.             ).denseExposure (wanderTrajectoryList.get (pathIndex));

  657.             if (null != pathDenseExposureTrajectory)
  658.             {
  659.                 for (int denseExposureDate = spotDate.julian();
  660.                     denseExposureDate <= sparseFixFloatExposureDateArray[sparseFixFloatExposureCount];
  661.                     ++denseExposureDate)
  662.                 {
  663.                     pathDenseExposureDistribution[denseExposureDate - spotDate.julian()][pathIndex] =
  664.                         pathDenseExposureTrajectory.get (denseExposureDate);
  665.                 }
  666.             }
  667.         }

  668.         UnivariateDiscreteThin[] univariateDiscreteThinArray = new
  669.             UnivariateDiscreteThin[denseExposureDateCount];

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

  671.         System.out.println ("\t||  Pykhtin (2009) Fix-Float Sparse -> Dense Exposures ||");

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

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

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

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

  676.         System.out.println ("\t||            - Dense Exposure Average                 ||");

  677.         System.out.println ("\t||            - Dense Exposure Minimum                 ||");

  678.         System.out.println ("\t||            - Dense Exposure Maximum                 ||");

  679.         System.out.println ("\t||            - Dense Exposure Estimation Error        ||");

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

  681.         for (int denseExposureDate = spotDate.julian();
  682.             denseExposureDate <= sparseFixFloatExposureDateArray[sparseFixFloatExposureCount];
  683.             ++denseExposureDate)
  684.         {
  685.             int dateIndex = denseExposureDate - spotDate.julian();

  686.             univariateDiscreteThinArray[dateIndex] = new UnivariateDiscreteThin
  687.                 (pathDenseExposureDistribution[dateIndex]);

  688.             System.out.println (
  689.                 "\t|| " +
  690.                 new JulianDate (denseExposureDate) + " => " +
  691.                 FormatUtil.FormatDouble (univariateDiscreteThinArray[dateIndex].average(), 5, 0, 1.) + " | " +
  692.                 FormatUtil.FormatDouble (univariateDiscreteThinArray[dateIndex].minimum(), 6, 0, 1.) + " | " +
  693.                 FormatUtil.FormatDouble (univariateDiscreteThinArray[dateIndex].maximum(), 6, 0, 1.) + " | " +
  694.                 FormatUtil.FormatDouble (univariateDiscreteThinArray[dateIndex].error(), 6, 0, 1.) + " ||"
  695.             );
  696.         }

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

  698.         EnvManager.TerminateEnv();
  699.     }
  700. }