BondCouponMeasures.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>BondCouponMeasures</i> encapsulates the parsimonious but complete set of the cash-flow oriented coupon
  83.  * measures generated out of a full bond analytics run to a given work-out. These are:
  84.  *
  85.  *  <br><br>
  86.  *  <ul>
  87.  *      <li>
  88.  *          DV01
  89.  *      </li>
  90.  *      <li>
  91.  *          PV Measures (Coupon PV, Index Coupon PV, PV)
  92.  *      </li>
  93.  *  </ul>
  94.  *
  95.  *  <br><br>
  96.  *  <ul>
  97.  *      <li><b>Module </b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/ProductCore.md">Product Core Module</a></li>
  98.  *      <li><b>Library</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/FixedIncomeAnalyticsLibrary.md">Fixed Income Analytics</a></li>
  99.  *      <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>
  100.  *      <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>
  101.  *  </ul>
  102.  *
  103.  * @author Lakshmi Krishnamurthy
  104.  */

  105. public class BondCouponMeasures {
  106.     private double _dblDV01 = java.lang.Double.NaN;
  107.     private double _dblIndexCouponPV = java.lang.Double.NaN;
  108.     private double _dblCouponPV = java.lang.Double.NaN;
  109.     private double _dblPV = java.lang.Double.NaN;

  110.     /**
  111.      * BondCouponMeasures constructor
  112.      *
  113.      * @param dblDV01 DV01
  114.      * @param dblIndexCouponPV Index Coupon PV
  115.      * @param dblCouponPV Coupon PV
  116.      * @param dblPV PV
  117.      *
  118.      * @throws java.lang.Exception Thrown if inputs are invalid
  119.      */

  120.     public BondCouponMeasures (
  121.         final double dblDV01,
  122.         final double dblIndexCouponPV,
  123.         final double dblCouponPV,
  124.         final double dblPV)
  125.         throws java.lang.Exception
  126.     {
  127.         if (!org.drip.numerical.common.NumberUtil.IsValid (_dblDV01 = dblDV01) ||
  128.             !org.drip.numerical.common.NumberUtil.IsValid (_dblCouponPV = dblCouponPV) ||
  129.                 !org.drip.numerical.common.NumberUtil.IsValid (_dblPV = dblPV))
  130.             throw new java.lang.Exception ("BondCouponMeasures ctr: Invalid Inputs!");

  131.         _dblIndexCouponPV = dblIndexCouponPV;
  132.     }

  133.     /**
  134.      * Adjust the bond coupon measures by a cash settlement discount factor
  135.      *
  136.      * @param dblCashPayDF Cash Pay discount factor
  137.      *
  138.      * @return TRUE - if the adjustment has been successfully applied
  139.      */

  140.     public boolean adjustForSettlement (
  141.         final double dblCashPayDF)
  142.     {
  143.         if (!org.drip.numerical.common.NumberUtil.IsValid (dblCashPayDF)) return false;

  144.         _dblDV01 /= dblCashPayDF;
  145.         _dblIndexCouponPV /= dblCashPayDF;
  146.         _dblCouponPV /= dblCashPayDF;
  147.         _dblPV /= dblCashPayDF;
  148.         return true;
  149.     }

  150.     /**
  151.      * Retrieve the DV01
  152.      *
  153.      * @return DV01
  154.      */

  155.     public double dv01()
  156.     {
  157.         return _dblDV01;
  158.     }

  159.     /**
  160.      * Retrieve the Index Coupon PV
  161.      *
  162.      * @return Index Coupon PV
  163.      */

  164.     public double indexCouponPV()
  165.     {
  166.         return _dblIndexCouponPV;
  167.     }

  168.     /**
  169.      * Retrieve the Coupon PV
  170.      *
  171.      * @return Coupon PV
  172.      */

  173.     public double couponPV()
  174.     {
  175.         return _dblCouponPV;
  176.     }

  177.     /**
  178.      * Retrieve the PV
  179.      *
  180.      * @return PV
  181.      */

  182.     public double pv()
  183.     {
  184.         return _dblPV;
  185.     }

  186.     /**
  187.      * Adjust Measures for accrued
  188.      *
  189.      * @param dblAccrued01 Accrued 01
  190.      * @param dblCoupon Coupon during the accrued phase
  191.      * @param dblIndex Index Rate during the accrued phase
  192.      * @param bDirtyFromClean True - Change measures from Clean to Dirty
  193.      *
  194.      * @return True - if the adjustment has been successfully applied
  195.      */

  196.     public boolean adjustForAccrual (
  197.         final double dblAccrued01,
  198.         final double dblCoupon,
  199.         final double dblIndex,
  200.         final boolean bDirtyFromClean)
  201.     {
  202.         if (!org.drip.numerical.common.NumberUtil.IsValid (dblAccrued01) ||
  203.             !org.drip.numerical.common.NumberUtil.IsValid (dblCoupon))
  204.             return false;

  205.         if (bDirtyFromClean)
  206.             _dblDV01 -= dblAccrued01;
  207.         else
  208.             _dblDV01 += dblAccrued01;

  209.         if (bDirtyFromClean)
  210.             _dblIndexCouponPV -= dblAccrued01 * dblIndex;
  211.         else
  212.             _dblIndexCouponPV += dblAccrued01 * dblIndex;

  213.         if (bDirtyFromClean)
  214.             _dblCouponPV -= dblAccrued01 * dblCoupon;
  215.         else
  216.             _dblCouponPV += dblAccrued01 * dblCoupon;

  217.         if (bDirtyFromClean)
  218.             _dblPV -= dblAccrued01 * dblCoupon;
  219.         else
  220.             _dblPV += dblAccrued01 * dblCoupon;

  221.         return true;
  222.     }

  223.     /**
  224.      * Return the state as a named measure map
  225.      *
  226.      * @param strPrefix Measure name prefix
  227.      *
  228.      * @return Map of the measures
  229.      */

  230.     public org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double> toMap (
  231.         final java.lang.String strPrefix)
  232.     {
  233.         org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double> mapMeasures = new
  234.             org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double>();

  235.         mapMeasures.put (strPrefix + "DV01", _dblDV01);

  236.         mapMeasures.put (strPrefix + "IndexCouponPV", _dblIndexCouponPV);

  237.         mapMeasures.put (strPrefix + "CouponPV", _dblCouponPV);

  238.         mapMeasures.put (strPrefix + "PV", _dblPV);

  239.         return mapMeasures;
  240.     }
  241. }