BondWorkoutMeasures.java

  1. package org.drip.analytics.output;

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

  81. /**
  82.  * <i>BondWorkoutMeasures</i> encapsulates the parsimonius yet complete set of measures generated out of a
  83.  * full bond analytics run to a given work-out. It contains the following:
  84.  *
  85.  *  <br><br>
  86.  *  <ul>
  87.  *      <li>
  88.  *          Credit Risky/Credit Riskless Clean/Dirty Coupon Measures
  89.  *      </li>
  90.  *      <li>
  91.  *          Credit Risky/Credit Riskless Par/Principal PV
  92.  *      </li>
  93.  *      <li>
  94.  *          Loss Measures such as expected Recovery, Loss on instantaneous default, and default exposure
  95.  *              with/without recovery
  96.  *      </li>
  97.  *      <li>
  98.  *          Unit Coupon measures such as Accrued 01, first coupon/index rate
  99.  *      </li>
  100.  *  </ul>
  101.  *
  102.  *  <br><br>
  103.  *  <ul>
  104.  *      <li><b>Module </b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/ProductCore.md">Product Core Module</a></li>
  105.  *      <li><b>Library</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/FixedIncomeAnalyticsLibrary.md">Fixed Income Analytics</a></li>
  106.  *      <li><b>Project</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/analytics/README.md">Date, Cash Flow, and Cash Flow Period Measure Generation Utilities</a></li>
  107.  *      <li><b>Package</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/analytics/output/README.md">Period Product Targeted Valuation Measures</a></li>
  108.  *  </ul>
  109.  *
  110.  * @author Lakshmi Krishnamurthy
  111.  */

  112. public class BondWorkoutMeasures {
  113.     private double _dblAccrued01 = java.lang.Double.NaN;
  114.     private double _dblRecoveryPV = java.lang.Double.NaN;
  115.     private BondCouponMeasures _bcmCreditRiskyClean = null;
  116.     private BondCouponMeasures _bcmCreditRiskyDirty = null;
  117.     private double _dblFirstIndexRate = java.lang.Double.NaN;
  118.     private double _dblFirstCouponRate = java.lang.Double.NaN;
  119.     private BondCouponMeasures _bcmCreditRisklessClean = null;
  120.     private BondCouponMeasures _bcmCreditRisklessDirty = null;
  121.     private double _dblDefaultExposure = java.lang.Double.NaN;
  122.     private double _dblExpectedRecovery = java.lang.Double.NaN;
  123.     private double _dblCreditRiskyParPV = java.lang.Double.NaN;
  124.     private double _dblCreditRisklessParPV = java.lang.Double.NaN;
  125.     private double _dblDefaultExposureNoRec = java.lang.Double.NaN;
  126.     private double _dblCreditRiskyPrincipalPV = java.lang.Double.NaN;
  127.     private double _dblCreditRisklessPrincipalPV = java.lang.Double.NaN;
  128.     private double _dblLossOnInstantaneousDefault = java.lang.Double.NaN;

  129.     /**
  130.      *
  131.      * BondWorkoutMeasures constructor
  132.      *
  133.      * @param bcmCreditRiskyDirty Dirty credit risky BondMeasuresCoupon
  134.      * @param bcmCreditRisklessDirty Dirty credit risk-less BondMeasuresCoupon
  135.      * @param dblCreditRiskyParPV Credit risky Par PV
  136.      * @param dblCreditRisklessParPV Credit risk-less par PV
  137.      * @param dblCreditRiskyPrincipalPV Credit Risky Principal PV
  138.      * @param dblCreditRisklessPrincipalPV Credit Risk-less Principal PV
  139.      * @param dblRecoveryPV Recovery PV
  140.      * @param dblExpectedRecovery Expected Recovery
  141.      * @param dblDefaultExposure PV on instantaneous default
  142.      * @param dblDefaultExposureNoRec PV on instantaneous default with zero recovery
  143.      * @param dblLossOnInstantaneousDefault Loss On Instantaneous Default
  144.      * @param dblAccrued01 Accrued01
  145.      * @param dblFirstCouponRate First Coupon Rate
  146.      * @param dblFirstIndexRate First Index Rate
  147.      * @param dblCashPayDF Cash Pay Discount Factor
  148.      *
  149.      * @throws java.lang.Exception Thrown if inputs are invalid
  150.      */

  151.     public BondWorkoutMeasures (
  152.         final BondCouponMeasures bcmCreditRiskyDirty,
  153.         final BondCouponMeasures bcmCreditRisklessDirty,
  154.         final double dblCreditRiskyParPV,
  155.         final double dblCreditRisklessParPV,
  156.         final double dblCreditRiskyPrincipalPV,
  157.         final double dblCreditRisklessPrincipalPV,
  158.         final double dblRecoveryPV,
  159.         final double dblExpectedRecovery,
  160.         final double dblDefaultExposure,
  161.         final double dblDefaultExposureNoRec,
  162.         final double dblLossOnInstantaneousDefault,
  163.         final double dblAccrued01,
  164.         final double dblFirstCouponRate,
  165.         final double dblFirstIndexRate,
  166.         final double dblCashPayDF)
  167.         throws java.lang.Exception
  168.     {
  169.         if (null == (_bcmCreditRisklessDirty = bcmCreditRisklessDirty) ||
  170.             !org.drip.numerical.common.NumberUtil.IsValid (_dblCreditRisklessParPV = dblCreditRisklessParPV) ||
  171.                 !org.drip.numerical.common.NumberUtil.IsValid (_dblCreditRisklessPrincipalPV =
  172.                     dblCreditRisklessPrincipalPV) || !org.drip.numerical.common.NumberUtil.IsValid (_dblAccrued01
  173.                         = dblAccrued01) || !org.drip.numerical.common.NumberUtil.IsValid (_dblFirstCouponRate =
  174.                             dblFirstCouponRate))
  175.             throw new java.lang.Exception ("BondWorkoutMeasures ctr: Invalid Inputs!");

  176.         _dblRecoveryPV = dblRecoveryPV;
  177.         _dblFirstIndexRate = dblFirstIndexRate;
  178.         _dblDefaultExposure = dblDefaultExposure;
  179.         _dblExpectedRecovery = dblExpectedRecovery;
  180.         _bcmCreditRiskyDirty = bcmCreditRiskyDirty;
  181.         _dblCreditRiskyParPV = dblCreditRiskyParPV;
  182.         _dblDefaultExposureNoRec = dblDefaultExposureNoRec;
  183.         _dblCreditRiskyPrincipalPV = dblCreditRiskyPrincipalPV;
  184.         _dblLossOnInstantaneousDefault = dblLossOnInstantaneousDefault;

  185.         if (!(_bcmCreditRisklessClean = new org.drip.analytics.output.BondCouponMeasures
  186.             (_bcmCreditRisklessDirty.dv01(), _bcmCreditRisklessDirty.indexCouponPV(),
  187.                 _bcmCreditRisklessDirty.couponPV(), _bcmCreditRisklessDirty.pv())).adjustForSettlement
  188.                     (dblCashPayDF))
  189.             throw new java.lang.Exception
  190.                 ("BondWorkoutMeasures ctr: Cannot successfully set up BCM CreditRisklessClean");

  191.         if (!_bcmCreditRisklessClean.adjustForAccrual (_dblAccrued01, _dblFirstCouponRate, dblFirstIndexRate,
  192.             false))
  193.             throw new java.lang.Exception
  194.                 ("BondWorkoutMeasures ctr: Cannot successfully set up BCM CreditRisklessClean");

  195.         if (null != _bcmCreditRiskyDirty && ((!(_bcmCreditRiskyClean = new BondCouponMeasures
  196.             (_bcmCreditRiskyDirty.dv01(), _bcmCreditRiskyDirty.indexCouponPV(),
  197.                 _bcmCreditRiskyDirty.couponPV(), _bcmCreditRiskyDirty.pv())).adjustForSettlement
  198.                     (dblCashPayDF)) || !_bcmCreditRiskyClean.adjustForAccrual (_dblAccrued01,
  199.                         _dblFirstCouponRate, _dblFirstCouponRate, false)))
  200.             throw new java.lang.Exception
  201.                 ("BondWorkoutMeasures ctr: Cannot successfully set up BCM CreditRiskyClean");
  202.     }

  203.     /**
  204.      * Retrieve the Credit Risky Clean Bond Coupon Measures
  205.      *
  206.      * @return Credit Risky Clean Bond Coupon Measures
  207.      */

  208.     public org.drip.analytics.output.BondCouponMeasures creditRiskyCleanbcm()
  209.     {
  210.         return _bcmCreditRiskyClean;
  211.     }

  212.     /**
  213.      * Retrieve the Credit Risk-less Clean Bond Coupon Measures
  214.      *
  215.      * @return Credit Risk-less Clean Bond Coupon Measures
  216.      */

  217.     public org.drip.analytics.output.BondCouponMeasures creditRisklessCleanbcm()
  218.     {
  219.         return _bcmCreditRisklessClean;
  220.     }

  221.     /**
  222.      * Retrieve the Credit Risky Dirty Bond Coupon Measures
  223.      *
  224.      * @return Credit Risky Dirty Bond Coupon Measures
  225.      */

  226.     public org.drip.analytics.output.BondCouponMeasures creditRiskyDirtybcm()
  227.     {
  228.         return _bcmCreditRiskyDirty;
  229.     }

  230.     /**
  231.      * Retrieve the Credit Risk-less Dirty Bond Coupon Measures
  232.      *
  233.      * @return Credit Risk-less Dirty Bond Coupon Measures
  234.      */

  235.     public org.drip.analytics.output.BondCouponMeasures creditRisklessDirtybcm()
  236.     {
  237.         return _bcmCreditRisklessDirty;
  238.     }

  239.     /**
  240.      * Retrieve the Accrued01
  241.      *
  242.      * @return Accrued01
  243.      */

  244.     public double accrued01()
  245.     {
  246.         return _dblAccrued01;
  247.     }

  248.     /**
  249.      * Retrieve the First Coupon Rate
  250.      *
  251.      * @return First Coupon Rate
  252.      */

  253.     public double firstCouponRate()
  254.     {
  255.         return _dblFirstCouponRate;
  256.     }

  257.     /**
  258.      * Retrieve the First Index Rate
  259.      *
  260.      * @return First Index Rate
  261.      */

  262.     public double firstIndexRate()
  263.     {
  264.         return _dblFirstIndexRate;
  265.     }

  266.     /**
  267.      * Retrieve the Credit Risky Par PV
  268.      *
  269.      * @return The Credit Risky Par PV
  270.      */

  271.     public double creditRiskyParPV()
  272.     {
  273.         return _dblCreditRiskyParPV;
  274.     }

  275.     /**
  276.      * Retrieve the Credit Risk-less Par PV
  277.      *
  278.      * @return The Credit Risk-less Par PV
  279.      */

  280.     public double creditRisklessParPV()
  281.     {
  282.         return _dblCreditRisklessParPV;
  283.     }

  284.     /**
  285.      * Retrieve the Credit Risky Principal PV
  286.      *
  287.      * @return The Credit Risky Principal PV
  288.      */

  289.     public double creditRiskyPrincipalPV()
  290.     {
  291.         return _dblCreditRiskyPrincipalPV;
  292.     }

  293.     /**
  294.      * Retrieve the Credit Risk-less Principal PV
  295.      *
  296.      * @return The Credit Risk-less Principal PV
  297.      */

  298.     public double creditRisklessPrincipalPV()
  299.     {
  300.         return _dblCreditRisklessPrincipalPV;
  301.     }

  302.     /**
  303.      * Retrieve the Recovery PV
  304.      *
  305.      * @return The Recovery PV
  306.      */

  307.     public double recoveryPV()
  308.     {
  309.         return _dblRecoveryPV;
  310.     }

  311.     /**
  312.      * Retrieve the Expected Recovery
  313.      *
  314.      * @return The Expected Recovery
  315.      */

  316.     public double expectedRecovery()
  317.     {
  318.         return _dblExpectedRecovery;
  319.     }

  320.     /**
  321.      * Retrieve Default Exposure - Same as PV on instantaneous default
  322.      *
  323.      * @return The Default Exposure
  324.      */

  325.     public double defaultExposure()
  326.     {
  327.         return _dblDefaultExposure;
  328.     }

  329.     /**
  330.      * Retrieve the Default Exposure without recovery - Same as PV on instantaneous default without recovery
  331.      *
  332.      * @return The Default Exposure without recovery
  333.      */

  334.     public double defaultExposureNoRec()
  335.     {
  336.         return _dblDefaultExposureNoRec;
  337.     }

  338.     /**
  339.      * Retrieve the Loss On Instantaneous Default
  340.      *
  341.      * @return Loss On Instantaneous Default
  342.      */

  343.     public double lossOnInstantaneousDefault()
  344.     {
  345.         return _dblLossOnInstantaneousDefault;
  346.     }

  347.     /**
  348.      * Return the state as a measure map
  349.      *
  350.      * @param strPrefix Measure name prefix
  351.      *
  352.      * @return Map of the measures
  353.      */

  354.     public org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double> toMap (
  355.         final java.lang.String strPrefix)
  356.     {
  357.         org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double> mapMeasures = new
  358.             org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double>();

  359.         mapMeasures.put (strPrefix + "Accrued", _dblAccrued01 * _dblFirstCouponRate);

  360.         mapMeasures.put (strPrefix + "Accrued01", _dblAccrued01);

  361.         mapMeasures.put (strPrefix + "CleanCouponPV", _bcmCreditRisklessClean.couponPV());

  362.         mapMeasures.put (strPrefix + "CleanDV01", _bcmCreditRisklessClean.dv01());

  363.         mapMeasures.put (strPrefix + "CleanIndexCouponPV", _bcmCreditRisklessClean.indexCouponPV());

  364.         mapMeasures.put (strPrefix + "CleanPrice", _bcmCreditRisklessClean.pv());

  365.         mapMeasures.put (strPrefix + "CleanPV", _bcmCreditRisklessClean.pv());

  366.         mapMeasures.put (strPrefix + "CreditRisklessParPV", _dblCreditRisklessParPV);

  367.         mapMeasures.put (strPrefix + "CreditRisklessPrincipalPV", _dblCreditRisklessPrincipalPV);

  368.         mapMeasures.put (strPrefix + "CreditRiskyParPV", _dblCreditRiskyParPV);

  369.         mapMeasures.put (strPrefix + "CreditRiskyPrincipalPV", _dblCreditRiskyPrincipalPV);

  370.         mapMeasures.put (strPrefix + "DefaultExposure", _dblDefaultExposure);

  371.         mapMeasures.put (strPrefix + "DefaultExposureNoRec", _dblDefaultExposureNoRec);

  372.         mapMeasures.put (strPrefix + "DirtyCouponPV", _bcmCreditRisklessDirty.couponPV());

  373.         mapMeasures.put (strPrefix + "DirtyDV01", _bcmCreditRisklessDirty.dv01());

  374.         mapMeasures.put (strPrefix + "DirtyIndexCouponPV", _bcmCreditRisklessDirty.indexCouponPV());

  375.         mapMeasures.put (strPrefix + "DirtyPrice", _bcmCreditRisklessDirty.pv());

  376.         mapMeasures.put (strPrefix + "DirtyPV", _bcmCreditRisklessDirty.pv());

  377.         mapMeasures.put (strPrefix + "DV01", _bcmCreditRisklessClean.dv01());

  378.         mapMeasures.put (strPrefix + "ExpectedRecovery", _dblExpectedRecovery);

  379.         mapMeasures.put (strPrefix + "FirstCouponRate", _dblFirstCouponRate);

  380.         mapMeasures.put (strPrefix + "FirstIndexRate", _dblFirstIndexRate);

  381.         mapMeasures.put (strPrefix + "LossOnInstantaneousDefault", _dblLossOnInstantaneousDefault);

  382.         mapMeasures.put (strPrefix + "ParPV", _dblCreditRisklessParPV);

  383.         mapMeasures.put (strPrefix + "PrincipalPV", _dblCreditRisklessPrincipalPV);

  384.         mapMeasures.put (strPrefix + "PV", _bcmCreditRisklessClean.pv());

  385.         mapMeasures.put (strPrefix + "RecoveryPV", _dblRecoveryPV);

  386.         org.drip.numerical.common.CollectionUtil.MergeWithMain (mapMeasures, _bcmCreditRisklessDirty.toMap
  387.             (strPrefix + "RisklessDirty"));

  388.         org.drip.numerical.common.CollectionUtil.MergeWithMain (mapMeasures, _bcmCreditRisklessClean.toMap
  389.             (strPrefix + "RisklessClean"));

  390.         if (null != _bcmCreditRiskyDirty) {
  391.             mapMeasures.put (strPrefix + "CleanCouponPV", _bcmCreditRiskyClean.couponPV());

  392.             mapMeasures.put (strPrefix + "CleanDV01", _bcmCreditRiskyClean.dv01());

  393.             mapMeasures.put (strPrefix + "CleanIndexCouponPV", _bcmCreditRiskyClean.indexCouponPV());

  394.             mapMeasures.put (strPrefix + "CleanPrice", _bcmCreditRiskyClean.pv());

  395.             mapMeasures.put (strPrefix + "CleanPV", _bcmCreditRiskyClean.pv());

  396.             mapMeasures.put (strPrefix + "DirtyCouponPV", _bcmCreditRiskyDirty.couponPV());

  397.             mapMeasures.put (strPrefix + "DirtyDV01", _bcmCreditRiskyDirty.dv01());

  398.             mapMeasures.put (strPrefix + "DirtyIndexCouponPV", _bcmCreditRiskyDirty.indexCouponPV());

  399.             mapMeasures.put (strPrefix + "DirtyPrice", _bcmCreditRiskyDirty.pv());

  400.             mapMeasures.put (strPrefix + "DirtyPV", _bcmCreditRiskyDirty.pv());

  401.             mapMeasures.put (strPrefix + "DV01", _bcmCreditRiskyClean.dv01());

  402.             mapMeasures.put (strPrefix + "ParPV", _dblCreditRiskyParPV);

  403.             mapMeasures.put (strPrefix + "PrincipalPV", _dblCreditRiskyPrincipalPV);

  404.             mapMeasures.put (strPrefix + "PV", _bcmCreditRiskyClean.pv());

  405.             org.drip.numerical.common.CollectionUtil.MergeWithMain (mapMeasures, _bcmCreditRiskyDirty.toMap
  406.                 (strPrefix + "RiskyDirty"));

  407.             org.drip.numerical.common.CollectionUtil.MergeWithMain (mapMeasures, _bcmCreditRiskyClean.toMap
  408.                 (strPrefix + "RiskyClean"));
  409.         }

  410.         return mapMeasures;
  411.     }
  412. }