BurgardKjaerBuilder.java

  1. package org.drip.xva.vertex;

  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>BurgardKjaerBuilder</i> contains the Builders that construct the Burgard Kjaer Vertex using a Variant
  78.  * of the Generalized Burgard Kjaer (2013) Scheme. The References are:
  79.  *
  80.  *  <br><br>
  81.  *  <ul>
  82.  *      <li>
  83.  *          Burgard, C., and M. Kjaer (2014): PDE Representations of Derivatives with Bilateral Counter-party
  84.  *              Risk and Funding Costs <i>Journal of Credit Risk</i> <b>7 (3)</b> 1-19
  85.  *      </li>
  86.  *      <li>
  87.  *          Burgard, C., and M. Kjaer (2014): In the Balance <i>Risk</i> <b>24 (11)</b> 72-75
  88.  *      </li>
  89.  *      <li>
  90.  *          Gregory, J. (2009): Being Two-faced over Counter-party Credit Risk <i>Risk</i> <b>20 (2)</b>
  91.  *              86-90
  92.  *      </li>
  93.  *      <li>
  94.  *          Li, B., and Y. Tang (2007): <i>Quantitative Analysis, Derivatives Modeling, and Trading
  95.  *              Strategies in the Presence of Counter-party Credit Risk for the Fixed Income Market</i>
  96.  *              <b>World Scientific Publishing</b> Singapore
  97.  *      </li>
  98.  *      <li>
  99.  *          Piterbarg, V. (2010): Funding Beyond Discounting: Collateral Agreements and Derivatives Pricing
  100.  *              <i>Risk</i> <b>21 (2)</b> 97-102
  101.  *      </li>
  102.  *  </ul>
  103.  *
  104.  *  <br><br>
  105.  *  <ul>
  106.  *      <li><b>Module </b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/PortfolioCore.md">Portfolio Core Module</a></li>
  107.  *      <li><b>Library</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/XVAAnalyticsLibrary.md">XVA Analytics Library</a></li>
  108.  *      <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>
  109.  *      <li><b>Package</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/xva/vertex/README.md">XVA Hypothecation Group Vertex Generators</a></li>
  110.  *  </ul>
  111.  * <br><br>
  112.  *
  113.  * @author Lakshmi Krishnamurthy
  114.  */

  115. public class BurgardKjaerBuilder
  116. {

  117.     /**
  118.      * Construct the Initial Dynamic Dealer Portfolio
  119.      *
  120.      * @param anchorDate The Anchor Date
  121.      * @param forward The Unrealized Forward Exposure
  122.      * @param marketVertex The Market Vertex
  123.      * @param closeOutScheme The Generic Close Out Instance
  124.      *
  125.      * @return The Burgard Kjaer Dealer Portfolio Vertex
  126.      */

  127.     public static final org.drip.xva.vertex.BurgardKjaer Initial (
  128.         final org.drip.analytics.date.JulianDate anchorDate,
  129.         final double forward,
  130.         final org.drip.exposure.universe.MarketVertex marketVertex,
  131.         final org.drip.xva.definition.CloseOut closeOutScheme)
  132.     {
  133.         if (null == marketVertex)
  134.         {
  135.             return null;
  136.         }

  137.         org.drip.xva.hypothecation.CollateralGroupVertexCloseOut collateralGroupVertexCloseOut =
  138.             org.drip.xva.hypothecation.CollateralGroupVertexCloseOut.Standard (
  139.                 closeOutScheme,
  140.                 forward,
  141.                 0.
  142.             );

  143.         org.drip.xva.vertex.BurgardKjaerExposure burgardKjaerVertexExposure =
  144.             org.drip.xva.vertex.BurgardKjaerExposure.Initial (
  145.                 forward,
  146.                 collateralGroupVertexCloseOut
  147.             );

  148.         if (null == burgardKjaerVertexExposure)
  149.         {
  150.             return null;
  151.         }

  152.         double fundingExposure = burgardKjaerVertexExposure.funding();

  153.         double dealerDefaultCloseOut = collateralGroupVertexCloseOut.dealer();

  154.         org.drip.exposure.universe.MarketVertexEntity dealerMarketVertex = marketVertex.dealer();

  155.         double dealerSubordinateFundingMarketVertex = dealerMarketVertex.subordinateFundingReplicator();

  156.         double dealerSurvival = dealerMarketVertex.survivalProbability();

  157.         double dealerSeniorRecoveryRate = dealerMarketVertex.seniorRecoveryRate();

  158.         double dealerSubordinateRecoveryRate = dealerMarketVertex.subordinateRecoveryRate();

  159.         double clientSurvival = marketVertex.client().survivalProbability();

  160.         double incrementalDealerSurvival = dealerSurvival - 1.;

  161.         double adjustedExposure =
  162.             forward + dealerSurvival * (clientSurvival - 1.) * burgardKjaerVertexExposure.credit() +
  163.             clientSurvival * incrementalDealerSurvival * burgardKjaerVertexExposure.debt() +
  164.             clientSurvival * incrementalDealerSurvival * fundingExposure -
  165.             dealerSurvival * clientSurvival * marketVertex.csaSpread() *
  166.                 burgardKjaerVertexExposure.variationMarginPosting();

  167.         try
  168.         {
  169.             return new org.drip.xva.vertex.BurgardKjaer (
  170.                 anchorDate,
  171.                 forward,
  172.                 0.,
  173.                 burgardKjaerVertexExposure,
  174.                 collateralGroupVertexCloseOut,
  175.                 new org.drip.xva.derivative.ReplicationPortfolioVertexDealer (
  176.                     (fundingExposure + dealerSubordinateRecoveryRate * adjustedExposure - dealerDefaultCloseOut) /
  177.                         (dealerSeniorRecoveryRate - dealerSubordinateRecoveryRate) / dealerMarketVertex.seniorFundingReplicator(),
  178.                     (fundingExposure + dealerSeniorRecoveryRate * adjustedExposure - dealerDefaultCloseOut) /
  179.                         (dealerSubordinateRecoveryRate - dealerSeniorRecoveryRate) / dealerSubordinateFundingMarketVertex
  180.                 )
  181.             );
  182.         }
  183.         catch (java.lang.Exception e)
  184.         {
  185.             e.printStackTrace();
  186.         }

  187.         return null;
  188.     }

  189.     /**
  190.      * Construct a Path-wise Dynamic Dealer Portfolio
  191.      *
  192.      * @param anchorDate The Anchor Date
  193.      * @param collateralGroupVertexExposure The Raw Collateral Group Vertex Exposure
  194.      * @param marketEdge The Market Edge
  195.      * @param collateralGroupVertexCloseOut The Collateral Group Vertex Close Out
  196.      * @param burgardKjaerVertexExposure The Collateral Group Vertex Exposure Decomposition
  197.      *
  198.      * @return The Burgard Kjaer Dealer Portfolio Vertex
  199.      */

  200.     public static final org.drip.xva.vertex.BurgardKjaer DealerPortfolioBuilder (
  201.         final org.drip.analytics.date.JulianDate anchorDate,
  202.         final org.drip.xva.hypothecation.CollateralGroupVertexExposure collateralGroupVertexExposure,
  203.         final org.drip.exposure.universe.MarketEdge marketEdge,
  204.         final org.drip.xva.hypothecation.CollateralGroupVertexCloseOut collateralGroupVertexCloseOut,
  205.         final org.drip.xva.vertex.BurgardKjaerExposure burgardKjaerVertexExposure)
  206.     {
  207.         if (null == collateralGroupVertexExposure ||
  208.             null == marketEdge ||
  209.             null == collateralGroupVertexCloseOut ||
  210.             null == burgardKjaerVertexExposure)
  211.         {
  212.             return null;
  213.         }

  214.         double fundingExposure = burgardKjaerVertexExposure.funding();

  215.         double dealerDefaultCloseOut = collateralGroupVertexCloseOut.dealer();

  216.         org.drip.exposure.universe.MarketVertex marketVertexStart = marketEdge.start();

  217.         org.drip.exposure.universe.MarketVertex marketVertexFinish = marketEdge.finish();

  218.         org.drip.exposure.universe.MarketVertexEntity dealerMarketVertexFinish = marketVertexFinish.dealer();

  219.         double dealerSubordinateFundingMarketVertexFinish = dealerMarketVertexFinish.subordinateFundingReplicator();

  220.         double dealerSurvivalFinish = dealerMarketVertexFinish.survivalProbability();

  221.         double dealerSeniorRecoveryRateFinish = dealerMarketVertexFinish.seniorRecoveryRate();

  222.         double dealerSubordinateRecoveryRateFinish = dealerMarketVertexFinish.subordinateRecoveryRate();

  223.         double clientSurvivalFinish = marketVertexFinish.client().survivalProbability();

  224.         double incrementalDealerSurvival = dealerSurvivalFinish -
  225.             (null == marketVertexStart ? 1. : marketVertexStart.dealer().survivalProbability());

  226.         double adjustedExposure =
  227.             collateralGroupVertexExposure.uncollateralized() +
  228.             dealerSurvivalFinish *
  229.                 (clientSurvivalFinish -
  230.                     (null == marketVertexStart ? 1. : marketVertexStart.client().survivalProbability())) *
  231.                 burgardKjaerVertexExposure.credit() +
  232.             clientSurvivalFinish * incrementalDealerSurvival * burgardKjaerVertexExposure.debt() +
  233.             clientSurvivalFinish * incrementalDealerSurvival * fundingExposure -
  234.             dealerSurvivalFinish * clientSurvivalFinish * marketVertexFinish.csaSpread() *
  235.                 burgardKjaerVertexExposure.variationMarginPosting();

  236.         try
  237.         {
  238.             return new org.drip.xva.vertex.BurgardKjaer (
  239.                 anchorDate,
  240.                 collateralGroupVertexExposure.variationMarginEstimate(),
  241.                 collateralGroupVertexExposure.tradePayment(),
  242.                 burgardKjaerVertexExposure,
  243.                 collateralGroupVertexCloseOut,
  244.                 new org.drip.xva.derivative.ReplicationPortfolioVertexDealer (
  245.                     (fundingExposure + dealerSubordinateRecoveryRateFinish * adjustedExposure -
  246.                         dealerDefaultCloseOut) / (dealerSeniorRecoveryRateFinish -
  247.                         dealerSubordinateRecoveryRateFinish) /
  248.                         dealerMarketVertexFinish.seniorFundingReplicator(),
  249.                     (fundingExposure + dealerSeniorRecoveryRateFinish * adjustedExposure - dealerDefaultCloseOut)
  250.                         / (dealerSubordinateRecoveryRateFinish - dealerSeniorRecoveryRateFinish) /
  251.                         dealerSubordinateFundingMarketVertexFinish
  252.                 )
  253.             );
  254.         }
  255.         catch (java.lang.Exception e)
  256.         {
  257.             e.printStackTrace();
  258.         }

  259.         return null;
  260.     }

  261.     /**
  262.      * Construct a Standard Instance of BurgardKjaerVertex using the specified Hedge Error with Two Dealer
  263.      *  Bonds
  264.      *
  265.      * @param anchorDate The Vertex Date Anchor
  266.      * @param exposure The Exposure at the Path Vertex Time Node
  267.      * @param realizedCashFlow The Default Window Realized Cash-flow at the Path Vertex Time Node
  268.      * @param collateralBalance The Collateral Balance at the Path Vertex Time Node
  269.      * @param hedgeError The Hedge Error
  270.      * @param marketEdge The Market Edge
  271.      * @param closeOutScheme The Generic Close-Out Evaluator Instance
  272.      *
  273.      * @return The Standard Instance of BurgardKjaerVertex using the specified Hedge Error with Two Dealer
  274.      *  Bonds
  275.      */

  276.     public static final org.drip.xva.vertex.BurgardKjaer HedgeErrorDualBond (
  277.         final org.drip.analytics.date.JulianDate anchorDate,
  278.         final double exposure,
  279.         final double realizedCashFlow,
  280.         final double collateralBalance,
  281.         final double hedgeError,
  282.         final org.drip.exposure.universe.MarketEdge marketEdge,
  283.         final org.drip.xva.definition.CloseOut closeOutScheme)
  284.     {
  285.         if (!org.drip.numerical.common.NumberUtil.IsValid (exposure) ||
  286.             !org.drip.numerical.common.NumberUtil.IsValid (realizedCashFlow) ||
  287.             !org.drip.numerical.common.NumberUtil.IsValid (collateralBalance) ||
  288.             !org.drip.numerical.common.NumberUtil.IsValid (hedgeError))
  289.         {
  290.             return null;
  291.         }

  292.         double uncollateralizedExposure = exposure + realizedCashFlow;
  293.         double collateralizedExposure = uncollateralizedExposure - collateralBalance;

  294.         org.drip.xva.hypothecation.CollateralGroupVertexCloseOut collateralGroupVertexCloseOut =
  295.             org.drip.xva.hypothecation.CollateralGroupVertexCloseOut.Standard (
  296.                 closeOutScheme,
  297.                 uncollateralizedExposure,
  298.                 collateralBalance
  299.             );

  300.         if (null == collateralGroupVertexCloseOut)
  301.         {
  302.             return null;
  303.         }

  304.         try
  305.         {
  306.             return DealerPortfolioBuilder (
  307.                 anchorDate,
  308.                 new org.drip.xva.hypothecation.CollateralGroupVertexExposure (
  309.                     exposure,
  310.                     realizedCashFlow
  311.                 ),
  312.                 marketEdge,
  313.                 collateralGroupVertexCloseOut,
  314.                 new org.drip.xva.vertex.BurgardKjaerExposure (
  315.                     collateralizedExposure - collateralGroupVertexCloseOut.client(),
  316.                     collateralizedExposure - collateralGroupVertexCloseOut.dealer(),
  317.                     hedgeError,
  318.                     collateralBalance
  319.                 )
  320.             );
  321.         }
  322.         catch (java.lang.Exception e)
  323.         {
  324.             e.printStackTrace();
  325.         }

  326.         return null;
  327.     }

  328.     /**
  329.      * Construct a Standard Instance of BurgardKjaerVertex using semi-replication with no Short-fall at own
  330.      *  Default using Two Bonds
  331.      *
  332.      * @param anchorDate The Vertex Date Anchor
  333.      * @param exposure The Exposure at the Path Vertex Time Node
  334.      * @param realizedCashFlow The Default Window Realized Cash-flow at the Path Vertex Time Node
  335.      * @param collateralBalance The Collateral Balance at the Path Vertex Time Node
  336.      * @param marketEdge The Market Edge
  337.      * @param closeOutScheme The Generic Close-Out Evaluator Instance
  338.      *
  339.      * @return The Standard Instance of BurgardKjaerVertex using semi-replication with no Short-fall at own
  340.      *  Default using Two Bonds
  341.      */

  342.     public static final org.drip.xva.vertex.BurgardKjaer SemiReplicationDualBond (
  343.         final org.drip.analytics.date.JulianDate anchorDate,
  344.         final double exposure,
  345.         final double realizedCashFlow,
  346.         final double collateralBalance,
  347.         final org.drip.exposure.universe.MarketEdge marketEdge,
  348.         final org.drip.xva.definition.CloseOut closeOutScheme)
  349.     {
  350.         if (!org.drip.numerical.common.NumberUtil.IsValid (exposure) ||
  351.             !org.drip.numerical.common.NumberUtil.IsValid (realizedCashFlow) ||
  352.             !org.drip.numerical.common.NumberUtil.IsValid (collateralBalance))
  353.         {
  354.             return null;
  355.         }

  356.         double uncollateralizedExposure = exposure + realizedCashFlow;
  357.         double collateralizedExposure = uncollateralizedExposure - collateralBalance;

  358.         try
  359.         {
  360.             return DealerPortfolioBuilder (
  361.                 anchorDate,
  362.                 new org.drip.xva.hypothecation.CollateralGroupVertexExposure (
  363.                     exposure,
  364.                     realizedCashFlow
  365.                 ),
  366.                 marketEdge,
  367.                 org.drip.xva.hypothecation.CollateralGroupVertexCloseOut.Standard (
  368.                     closeOutScheme,
  369.                     uncollateralizedExposure,
  370.                     collateralBalance
  371.                 ),
  372.                 new org.drip.xva.vertex.BurgardKjaerExposure (
  373.                     0. < collateralizedExposure ? collateralizedExposure : 0.,
  374.                     0. > collateralizedExposure ? collateralizedExposure : 0.,
  375.                     0. < collateralizedExposure ? collateralizedExposure : 0.,
  376.                     collateralBalance
  377.                 )
  378.             );
  379.         }
  380.         catch (java.lang.Exception e)
  381.         {
  382.             e.printStackTrace();
  383.         }

  384.         return null;
  385.     }

  386.     /**
  387.      * Construct a Standard Instance of BurgardKjaerVertex using a Fully Collateralized Strategy, i.e., also
  388.      *  referred to as the 2 Way Gold Plated CSA
  389.      *
  390.      * @param anchorDate The Vertex Date Anchor
  391.      * @param exposure The Exposure at the Path Vertex Time Node
  392.      * @param realizedCashFlow The Default Window Realized Cash-flow at the Path Vertex Time Node
  393.      * @param marketEdge The Market Edge
  394.      * @param closeOutScheme The Generic Close-Out Evaluator Instance
  395.      *
  396.      * @return The Standard Instance of BurgardKjaerVertex using using a Fully Collateralized Strategy
  397.      */

  398.     public static final org.drip.xva.vertex.BurgardKjaer GoldPlatedTwoWayCSA (
  399.         final org.drip.analytics.date.JulianDate anchorDate,
  400.         final double exposure,
  401.         final double realizedCashFlow,
  402.         final org.drip.exposure.universe.MarketEdge marketEdge,
  403.         final org.drip.xva.definition.CloseOut closeOutScheme)
  404.     {
  405.         if (!org.drip.numerical.common.NumberUtil.IsValid (exposure) ||
  406.             !org.drip.numerical.common.NumberUtil.IsValid (realizedCashFlow))
  407.         {
  408.             return null;
  409.         }

  410.         double uncollateralizedExposure = exposure + realizedCashFlow;

  411.         try
  412.         {
  413.             return DealerPortfolioBuilder (
  414.                 anchorDate,
  415.                 new org.drip.xva.hypothecation.CollateralGroupVertexExposure (
  416.                     exposure,
  417.                     realizedCashFlow
  418.                 ),
  419.                 marketEdge,
  420.                 org.drip.xva.hypothecation.CollateralGroupVertexCloseOut.Standard (
  421.                     closeOutScheme,
  422.                     uncollateralizedExposure,
  423.                     uncollateralizedExposure
  424.                 ),
  425.                 new org.drip.xva.vertex.BurgardKjaerExposure (
  426.                     0.,
  427.                     0.,
  428.                     0.,
  429.                     uncollateralizedExposure
  430.                 )
  431.             );
  432.         }
  433.         catch (java.lang.Exception e)
  434.         {
  435.             e.printStackTrace();
  436.         }

  437.         return null;
  438.     }

  439.     /**
  440.      * Construct a Standard Instance of BurgardKjaerVertex using One Way CSA
  441.      *
  442.      * @param anchorDate The Vertex Date Anchor
  443.      * @param exposure The Exposure at the Path Vertex Time Node
  444.      * @param realizedCashFlow The Default Window Realized Cash-flow at the Path Vertex Time Node
  445.      * @param marketEdge The Market Edge
  446.      * @param closeOutScheme The Generic Close-Out Evaluator Instance
  447.      *
  448.      * @return The Standard Instance of BurgardKjaerVertex using One Way CSA
  449.      */

  450.     public static final org.drip.xva.vertex.BurgardKjaer OneWayCSA (
  451.         final org.drip.analytics.date.JulianDate anchorDate,
  452.         final double exposure,
  453.         final double realizedCashFlow,
  454.         final org.drip.exposure.universe.MarketEdge marketEdge,
  455.         final org.drip.xva.definition.CloseOut closeOutScheme)
  456.     {
  457.         if (!org.drip.numerical.common.NumberUtil.IsValid (exposure) ||
  458.             !org.drip.numerical.common.NumberUtil.IsValid (realizedCashFlow))
  459.         {
  460.             return null;
  461.         }

  462.         double uncollateralizedExposure = exposure + realizedCashFlow;
  463.         double collateralBalance = 0. > uncollateralizedExposure ? uncollateralizedExposure : 0.;

  464.         try
  465.         {
  466.             return DealerPortfolioBuilder (
  467.                 anchorDate,
  468.                 new org.drip.xva.hypothecation.CollateralGroupVertexExposure (
  469.                     exposure,
  470.                     realizedCashFlow
  471.                 ),
  472.                 marketEdge,
  473.                 org.drip.xva.hypothecation.CollateralGroupVertexCloseOut.Standard (
  474.                     closeOutScheme,
  475.                     uncollateralizedExposure,
  476.                     collateralBalance
  477.                 ),
  478.                 new org.drip.xva.vertex.BurgardKjaerExposure (
  479.                     0. < uncollateralizedExposure ? uncollateralizedExposure : 0.,
  480.                     0.,
  481.                     0. < uncollateralizedExposure ? uncollateralizedExposure : 0.,
  482.                     collateralBalance
  483.                 )
  484.             );
  485.         }
  486.         catch (java.lang.Exception e)
  487.         {
  488.             e.printStackTrace();
  489.         }

  490.         return null;
  491.     }

  492.     /**
  493.      * Construct a Standard Instance of BurgardKjaerVertex using the "Set Off" Legal Agreement Scheme
  494.      *
  495.      * @param anchorDate The Vertex Date Anchor
  496.      * @param exposure The Exposure at the Path Vertex Time Node
  497.      * @param realizedCashFlow The Default Window Realized Cash-flow at the Path Vertex Time Node
  498.      * @param collateralBalance The Collateral Balance at the Path Vertex Time Node
  499.      * @param marketEdge The Market Edge
  500.      *
  501.      * @return The Standard Instance of BurgardKjaerVertex using the "Set Off" Legal Agreement Scheme
  502.      */

  503.     public static final org.drip.xva.vertex.BurgardKjaer SetOff (
  504.         final org.drip.analytics.date.JulianDate anchorDate,
  505.         final double exposure,
  506.         final double realizedCashFlow,
  507.         final double collateralBalance,
  508.         final org.drip.exposure.universe.MarketEdge marketEdge)
  509.     {
  510.         if (!org.drip.numerical.common.NumberUtil.IsValid (exposure) ||
  511.             !org.drip.numerical.common.NumberUtil.IsValid (realizedCashFlow) ||
  512.             !org.drip.numerical.common.NumberUtil.IsValid (collateralBalance))
  513.         {
  514.             return null;
  515.         }

  516.         org.drip.exposure.universe.MarketVertex marketVertexFinish = marketEdge.finish();

  517.         double dealerSeniorRecoveryRateFinish = marketVertexFinish.dealer().seniorRecoveryRate();

  518.         double clientRecoveryFinish = marketVertexFinish.client().seniorRecoveryRate();

  519.         double collateralizedExposure = exposure + realizedCashFlow - collateralBalance;

  520.         try
  521.         {
  522.             return DealerPortfolioBuilder (
  523.                 anchorDate,
  524.                 new org.drip.xva.hypothecation.CollateralGroupVertexExposure (
  525.                     exposure,
  526.                     realizedCashFlow
  527.                 ),
  528.                 marketEdge,
  529.                 new org.drip.xva.hypothecation.CollateralGroupVertexCloseOut (
  530.                     collateralizedExposure * dealerSeniorRecoveryRateFinish,
  531.                     collateralizedExposure * clientRecoveryFinish
  532.                 ),
  533.                 new org.drip.xva.vertex.BurgardKjaerExposure (
  534.                     collateralizedExposure * (1. - clientRecoveryFinish),
  535.                     collateralizedExposure * (1. - dealerSeniorRecoveryRateFinish),
  536.                     0.,
  537.                     collateralBalance
  538.                 )
  539.             );
  540.         }
  541.         catch (java.lang.Exception e)
  542.         {
  543.             e.printStackTrace();
  544.         }

  545.         return null;
  546.     }
  547. }