CounterPartyHazardLow.java

  1. package org.drip.sample.burgard2012;

  2. import org.drip.numerical.common.FormatUtil;
  3. import org.drip.service.env.EnvManager;

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

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

  78. /**
  79.  * <i>CounterPartyHazardLow</i> estimates the CVA Relative to V for a Call Option bought by the Bank for
  80.  * different Close Outs and Funding Spreads using the Burgard and Kjaer (2011) Methodology for the Case where
  81.  * the Counter Party Hazard is Low (Zero). The References are:
  82.  *  
  83.  * <br><br>
  84.  *  <ul>
  85.  *      <li>
  86.  *          Burgard, C., and M. Kjaer (2014): PDE Representations of Derivatives with Bilateral Counter-party
  87.  *              Risk and Funding Costs <i>Journal of Credit Risk</i> <b>7 (3)</b> 1-19
  88.  *      </li>
  89.  *      <li>
  90.  *          Cesari, G., J. Aquilina, N. Charpillon, X. Filipovic, G. Lee, and L. Manda (2009): <i>Modeling,
  91.  *              Pricing, and Hedging Counter-party Credit Exposure - A Technical Guide</i> <b>Springer
  92.  *              Finance</b> New York
  93.  *      </li>
  94.  *      <li>
  95.  *          Gregory, J. (2009): Being Two-faced over Counter-party Credit Risk <i>Risk</i> <b>20 (2)</b>
  96.  *              86-90
  97.  *      </li>
  98.  *      <li>
  99.  *          Li, B., and Y. Tang (2007): <i>Quantitative Analysis, Derivatives Modeling, and Trading
  100.  *              Strategies in the Presence of Counter-party Credit Risk for the Fixed Income Market</i>
  101.  *              <b>World Scientific Publishing</b> Singapore
  102.  *      </li>
  103.  *      <li>
  104.  *          Piterbarg, V. (2010): Funding Beyond Discounting: Collateral Agreements and Derivatives Pricing
  105.  *              <i>Risk</i> <b>21 (2)</b> 97-102
  106.  *      </li>
  107.  *  </ul>
  108.  *  
  109.  * <br><br>
  110.  *  <ul>
  111.  *      <li><b>Module </b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/PortfolioCore.md">Portfolio Core Module</a></li>
  112.  *      <li><b>Library</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/XVAAnalyticsLibrary.md">XVA Analytics Library</a></li>
  113.  *      <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>
  114.  *      <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>
  115.  *  </ul>
  116.  * <br><br>
  117.  *
  118.  * @author Lakshmi Krishnamurthy
  119.  */

  120. public class CounterPartyHazardLow {

  121.     private static final void CVA (
  122.         final double dblT,
  123.         final double dblRB,
  124.         final double dblRC,
  125.         final double dblLambdaB,
  126.         final double dblLambdaC)
  127.         throws Exception
  128.     {
  129.         double dblMTM_XVA___Funding_0    = -1. * (1. - Math.exp (-1. * (1. - dblRC) * dblLambdaC * dblT));

  130.         double dblMTM_XVA___Funding_Bank = -1. * (1. - Math.exp (-1. * ((1. - dblRB) * dblLambdaB + (1. - dblRC) * dblLambdaC) * dblT));

  131.         double dblMTM_Fair__Funding_0   = -1. * (1. - dblRC) * dblLambdaC *
  132.             (1. - Math.exp (-1. * (dblLambdaB + dblLambdaC) * dblT)) /
  133.             (dblLambdaB + dblLambdaC);

  134.         double dblMTM_Fair__Funding_Bank = -1. * ((1. - dblRB) * dblLambdaB + (1. - dblRC) * dblLambdaC) *
  135.             (1. - Math.exp (-1. * (dblLambdaB + dblLambdaC) * dblT)) /
  136.             (dblLambdaB + dblLambdaC);

  137.         System.out.println ("\t|| " +
  138.             FormatUtil.FormatDouble (dblLambdaB   , 1, 1, 100.) + "% => " +
  139.             FormatUtil.FormatDouble (dblMTM_XVA___Funding_0   , 2, 2, 100.) + "% | " +
  140.             FormatUtil.FormatDouble (dblMTM_XVA___Funding_Bank, 2, 2, 100.) + "% | " +
  141.             FormatUtil.FormatDouble (dblMTM_Fair__Funding_0   , 2, 2, 100.) + "% | " +
  142.             FormatUtil.FormatDouble (dblMTM_Fair__Funding_Bank, 2, 2, 100.) + "% ||"
  143.         );
  144.     }

  145.     public static final void main (
  146.         final String[] astrArgs)
  147.         throws Exception
  148.     {
  149.         EnvManager.InitEnv ("");

  150.         double dblLambdaC = 0.00;

  151.         double dblRB = 0.4;
  152.         double dblRC = 0.4;
  153.         double dblT = 5.;

  154.         double[] adblLambdaB = new double[] {
  155.             0.00001,
  156.             0.005,
  157.             0.01,
  158.             0.015,
  159.             0.02,
  160.             0.025,
  161.             0.03,
  162.             0.035,
  163.             0.04,
  164.             0.045,
  165.             0.05
  166.         };

  167.         System.out.println();

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

  169.         System.out.println ("\t||        CVA UNDER LOW COUNTER PARTY HAZARD        ||");

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

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

  172.         System.out.println ("\t||        - Close Out      => MTM XVA               ||");

  173.         System.out.println ("\t||        - Funding Spread => None                  ||");

  174.         System.out.println ("\t||        - Close Out      => MTM Fair Value        ||");

  175.         System.out.println ("\t||        - Funding Spread => Bank                  ||");

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

  177.         for (double dblLambdaB : adblLambdaB)
  178.             CVA (
  179.                 dblT,
  180.                 dblRB,
  181.                 dblRC,
  182.                 dblLambdaB,
  183.                 dblLambdaC
  184.             );

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

  186.         System.out.println();

  187.         EnvManager.TerminateEnv();
  188.     }
  189. }