BurgardKjaerOperator.java

  1. package org.drip.xva.pde;

  2. /*
  3.  * -*- mode: java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  4.  */

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

  76. /**
  77.  * <i>BurgardKjaerOperator</i> sets up the Parabolic Differential Equation PDE based on the Ito Evolution
  78.  * Differential for the Reference Underlier Asset, as laid out in Burgard and Kjaer (2014). The References
  79.  * are:
  80.  *
  81.  *  <br><br>
  82.  *  <ul>
  83.  *      <li>
  84.  *          Burgard, C., and M. Kjaer (2014): PDE Representations of Derivatives with Bilateral Counter-party
  85.  *              Risk and Funding Costs <i>Journal of Credit Risk</i> <b>7 (3)</b> 1-19
  86.  *      </li>
  87.  *      <li>
  88.  *          Cesari, G., J. Aquilina, N. Charpillon, X. Filipovic, G. Lee, and L. Manda (2009): <i>Modeling,
  89.  *              Pricing, and Hedging Counter-party Credit Exposure - A Technical Guide</i> <b>Springer
  90.  *              Finance</b> New York
  91.  *      </li>
  92.  *      <li>
  93.  *          Gregory, J. (2009): Being Two-faced over Counter-party Credit Risk <i>Risk</i> <b>20 (2)</b>
  94.  *              86-90
  95.  *      </li>
  96.  *      <li>
  97.  *          Li, B., and Y. Tang (2007): <i>Quantitative Analysis, Derivatives Modeling, and Trading
  98.  *              Strategies in the Presence of Counter-party Credit Risk for the Fixed Income Market</i>
  99.  *              <b>World Scientific Publishing</b> Singapore
  100.  *      </li>
  101.  *      <li>
  102.  *          Piterbarg, V. (2010): Funding Beyond Discounting: Collateral Agreements and Derivatives Pricing
  103.  *              <i>Risk</i> <b>21 (2)</b> 97-102
  104.  *      </li>
  105.  *  </ul>
  106.  *
  107.  *  <br><br>
  108.  *  <ul>
  109.  *      <li><b>Module </b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/PortfolioCore.md">Portfolio Core Module</a></li>
  110.  *      <li><b>Library</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/XVAAnalyticsLibrary.md">XVA Analytics Library</a></li>
  111.  *      <li><b>Project</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/xva/README.md">Valuation Adjustments that account for Collateral, CC Credit/Debt and Funding Overhead</a></li>
  112.  *      <li><b>Package</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/xva/pde/README.md">Burgard Kjaer PDE Evolution Scheme</a></li>
  113.  *  </ul>
  114.  * <br><br>
  115.  *
  116.  * @author Lakshmi Krishnamurthy
  117.  */

  118. public class BurgardKjaerOperator
  119. {
  120.     private org.drip.xva.definition.PDEEvolutionControl _pdeEvolutionControl = null;
  121.     private org.drip.exposure.evolver.PrimarySecurityDynamicsContainer _tradeablesContainer = null;

  122.     /**
  123.      * BurgardKjaerOperator Constructor
  124.      *
  125.      * @param tradeablesContainer The Universe of Tradeable Assets
  126.      * @param pdeEvolutionControl The XVA Control Settings
  127.      *
  128.      * @throws java.lang.Exception Thrown if the Inputs are Invalid
  129.      */

  130.     public BurgardKjaerOperator (
  131.         final org.drip.exposure.evolver.PrimarySecurityDynamicsContainer tradeablesContainer,
  132.         final org.drip.xva.definition.PDEEvolutionControl pdeEvolutionControl)
  133.         throws java.lang.Exception
  134.     {
  135.         if (null == (_tradeablesContainer = tradeablesContainer) ||
  136.             null == (_pdeEvolutionControl = pdeEvolutionControl))
  137.         {
  138.             throw new java.lang.Exception ("BurgardKjaerOperator Constructor => Invalid Inputs");
  139.         }
  140.     }

  141.     /**
  142.      * Retrieve the Universe of Trade-able Assets
  143.      *
  144.      * @return The Universe of Trade-able Assets
  145.      */

  146.     public org.drip.exposure.evolver.PrimarySecurityDynamicsContainer tradeablesContainer()
  147.     {
  148.         return _tradeablesContainer;
  149.     }

  150.     /**
  151.      * Retrieve the XVA Control Settings
  152.      *
  153.      * @return The XVA Control Settings
  154.      */

  155.     public org.drip.xva.definition.PDEEvolutionControl pdeEvolutionControl()
  156.     {
  157.         return _pdeEvolutionControl;
  158.     }

  159.     /**
  160.      * Generate the Derivative Value Time Increment using the Burgard Kjaer Scheme
  161.      *
  162.      * @param marketEdge The Market Edge
  163.      * @param initialTrajectoryVertex The Evolution Trajectory Vertex
  164.      * @param collateral The Off-setting Collateral
  165.      *
  166.      * @return The Time Increment using the Burgard Kjaer Scheme
  167.      */

  168.     public org.drip.xva.pde.BurgardKjaerEdgeRun edgeRun (
  169.         final org.drip.exposure.universe.MarketEdge marketEdge,
  170.         final org.drip.xva.derivative.EvolutionTrajectoryVertex initialTrajectoryVertex,
  171.         final double collateral)
  172.     {
  173.         if (null == marketEdge ||
  174.             null == initialTrajectoryVertex ||
  175.             !org.drip.numerical.common.NumberUtil.IsValid (collateral))
  176.         {
  177.             return null;
  178.         }

  179.         org.drip.exposure.universe.MarketVertex finalMarketVertex = marketEdge.finish();

  180.         org.drip.exposure.universe.MarketVertexEntity finalDealerMarketVertex = finalMarketVertex.dealer();

  181.         org.drip.exposure.universe.MarketVertexEntity finalClientMarketVertex = finalMarketVertex.client();

  182.         org.drip.xva.derivative.PositionGreekVertex initialPositionGreekVertex =
  183.             initialTrajectoryVertex.positionGreekVertex();

  184.         double initialDerivativeXVAValue = initialPositionGreekVertex.derivativeXVAValue();

  185.         double gainOnDealerDefault = initialTrajectoryVertex.gainOnDealerDefault();

  186.         double dealerSeniorDefaultIntensity = finalDealerMarketVertex.hazardRate();

  187.         double clientDefaultIntensity = finalClientMarketVertex.hazardRate();

  188.         double dealerGainOnClientDefault = initialTrajectoryVertex.gainOnClientDefault();

  189.         double gainOnClientDefault = clientDefaultIntensity * dealerGainOnClientDefault;

  190.         try
  191.         {
  192.             double initialPortfolioValue = finalMarketVertex.latentStateValue
  193.                 (_tradeablesContainer.assetList().get (0).label());

  194.             double portfolioValueBump = _pdeEvolutionControl.sensitivityShiftFactor() *
  195.                 initialPortfolioValue;

  196.             double[] bumpedThetaArray = new org.drip.xva.pde.ParabolicDifferentialOperator
  197.                 (_tradeablesContainer.assetList().get (0)).thetaUpDown (
  198.                     initialTrajectoryVertex,
  199.                     initialPortfolioValue,
  200.                     portfolioValueBump
  201.                 );

  202.             if (null == bumpedThetaArray || 3 != bumpedThetaArray.length)
  203.             {
  204.                 return null;
  205.             }

  206.             return new org.drip.xva.pde.BurgardKjaerEdgeRun (
  207.                 portfolioValueBump,
  208.                 -1. * bumpedThetaArray[0],
  209.                 -1. * bumpedThetaArray[1],
  210.                 -1. * bumpedThetaArray[2],
  211.                 finalMarketVertex.csaReplicator() * collateral,
  212.                 (dealerSeniorDefaultIntensity + clientDefaultIntensity) * initialDerivativeXVAValue,
  213.                 -1. * dealerSeniorDefaultIntensity * gainOnDealerDefault,
  214.                 -1. * gainOnClientDefault,
  215.                 0.
  216.             );
  217.         }
  218.         catch (java.lang.Exception e)
  219.         {
  220.             e.printStackTrace();
  221.         }

  222.         return null;
  223.     }

  224.     /**
  225.      * Generate the Time Increment Run Attribution using the Burgard Kjaer Scheme
  226.      *
  227.      * @param marketEdge The Market Edge
  228.      * @param initialTrajectoryVertex The Starting Evolution Trajectory Vertex
  229.      * @param collateral The Off-setting Collateral
  230.      *
  231.      * @return The Time Increment Run Attribution using the Burgard Kjaer Scheme
  232.      */

  233.     public org.drip.xva.pde.BurgardKjaerEdgeAttribution edgeRunAttribution (
  234.         final org.drip.exposure.universe.MarketEdge marketEdge,
  235.         final org.drip.xva.derivative.EvolutionTrajectoryVertex initialTrajectoryVertex,
  236.         final double collateral)
  237.     {
  238.         if (null == marketEdge ||
  239.             null == initialTrajectoryVertex)
  240.         {
  241.             return null;
  242.         }

  243.         org.drip.exposure.universe.MarketVertex finalMarketVertex = marketEdge.finish();

  244.         double derivativeXVAValue = initialTrajectoryVertex.positionGreekVertex().derivativeXVAValue();

  245.         org.drip.exposure.universe.MarketVertexEntity finalDealerMarketVertex = finalMarketVertex.dealer();

  246.         org.drip.exposure.universe.MarketVertexEntity finalClientMarketVertex = finalMarketVertex.client();

  247.         double clientRecoveryRate = finalClientMarketVertex.seniorRecoveryRate();

  248.         double dealerDefaultIntensity = finalDealerMarketVertex.hazardRate();

  249.         double clientDefaultIntensity = finalClientMarketVertex.hazardRate();

  250.         double closeOutMTM = org.drip.xva.definition.PDEEvolutionControl.CLOSEOUT_GREGORY_LI_TANG ==
  251.             _pdeEvolutionControl.closeOutScheme() ? derivativeXVAValue : derivativeXVAValue;

  252.         double dealerExposure = closeOutMTM > 0. ? closeOutMTM : finalDealerMarketVertex.seniorRecoveryRate()
  253.             * closeOutMTM;

  254.         double derivativeXVAClientDefaultGrowth = -1. * clientDefaultIntensity *
  255.             (closeOutMTM < 0. ? closeOutMTM : clientRecoveryRate * closeOutMTM);

  256.         double dealerSeniorFundingSpread = finalDealerMarketVertex.seniorFundingSpread() /
  257.             marketEdge.vertexIncrement();

  258.         try
  259.         {
  260.             double initialPortfolioValue = finalMarketVertex.latentStateValue
  261.                 (_tradeablesContainer.assetList().get (0).label());

  262.             double portfolioValueBump = _pdeEvolutionControl.sensitivityShiftFactor() *
  263.                 initialPortfolioValue;

  264.             double[] bumpedThetaArray = new org.drip.xva.pde.ParabolicDifferentialOperator
  265.                 (_tradeablesContainer.assetList().get (0)).thetaUpDown (
  266.                     initialTrajectoryVertex,
  267.                     initialPortfolioValue,
  268.                     portfolioValueBump
  269.                 );

  270.             if (null == bumpedThetaArray || 3 != bumpedThetaArray.length)
  271.             {
  272.                 return null;
  273.             }

  274.             return new org.drip.xva.pde.BurgardKjaerEdgeAttribution (
  275.                 portfolioValueBump,
  276.                 -1. * bumpedThetaArray[0],
  277.                 -1. * bumpedThetaArray[1],
  278.                 -1. * bumpedThetaArray[2],
  279.                 finalMarketVertex.csaReplicator() * collateral,
  280.                 (dealerDefaultIntensity + clientDefaultIntensity) * derivativeXVAValue,
  281.                 dealerSeniorFundingSpread * dealerExposure,
  282.                 -1. * dealerDefaultIntensity * dealerExposure,
  283.                 derivativeXVAClientDefaultGrowth
  284.             );
  285.         }
  286.         catch (java.lang.Exception e)
  287.         {
  288.             e.printStackTrace();
  289.         }

  290.         return null;
  291.     }
  292. }