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

  79. /**
  80.  * <i>CompositePeriodCouponMetrics</i> holds the results of the compounded Composed period Full Coupon
  81.  * Metrics Estimate Output.
  82.  *
  83.  *  <br><br>
  84.  *  <ul>
  85.  *      <li><b>Module </b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/ProductCore.md">Product Core Module</a></li>
  86.  *      <li><b>Library</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/FixedIncomeAnalyticsLibrary.md">Fixed Income Analytics</a></li>
  87.  *      <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>
  88.  *      <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>
  89.  *  </ul>
  90.  *
  91.  * @author Lakshmi Krishnamurthy
  92.  */

  93. public class CompositePeriodCouponMetrics {
  94.     private double _dblDCF = 0.;
  95.     private double _dblRate = 0.;
  96.     private double _dblCreditFX = 0.;
  97.     private double _dblForwardFX = 0.;
  98.     private double _dblFundingFX = 0.;
  99.     private double _dblCollateralFX = 0.;
  100.     private double _dblCreditForward = 0.;
  101.     private double _dblCreditFunding = 0.;
  102.     private double _dblForwardFunding = 0.;
  103.     private double _dblCollateralCredit = 0.;
  104.     private double _dblCollateralForward = 0.;
  105.     private double _dblCollateralFunding = 0.;
  106.     private java.util.List<org.drip.analytics.output.UnitPeriodMetrics> _lsUPM = null;

  107.     /**
  108.      * CompositePeriodCouponMetrics Instance from the list of the composite period metrics
  109.      *
  110.      * @param lsUPM List of Unit Period Metrics
  111.      *
  112.      * @return Instance of CompositePeriodCouponMetrics
  113.      */

  114.     public static final CompositePeriodCouponMetrics Create (
  115.         final java.util.List<org.drip.analytics.output.UnitPeriodMetrics> lsUPM)
  116.     {
  117.         try {
  118.             CompositePeriodCouponMetrics cpm = new CompositePeriodCouponMetrics (lsUPM);

  119.             return cpm.initialize() ? cpm : null;
  120.         } catch (java.lang.Exception e) {
  121.             e.printStackTrace();
  122.         }

  123.         return null;
  124.     }

  125.     protected CompositePeriodCouponMetrics (
  126.         final java.util.List<org.drip.analytics.output.UnitPeriodMetrics> lsUPM)
  127.         throws java.lang.Exception
  128.     {
  129.         if (null == (_lsUPM = lsUPM) || 0 == _lsUPM.size())
  130.             throw new java.lang.Exception ("CompositePeriodCouponMetrics ctr: Invalid Inputs");
  131.     }

  132.     protected boolean initialize()
  133.     {
  134.         double dblAmount = 0.;

  135.         for (org.drip.analytics.output.UnitPeriodMetrics upm : _lsUPM) {
  136.             org.drip.analytics.output.ConvexityAdjustment convAdj = upm.convAdj();

  137.             double dblUnitRate = upm.rate();

  138.             double dblUnitDCF = upm.dcf();

  139.             double dblUnitAmount = dblUnitDCF * dblUnitRate;
  140.             dblAmount += dblUnitAmount;
  141.             _dblDCF += dblUnitDCF;

  142.             _dblCollateralCredit += convAdj.collateralCredit() * dblUnitDCF;

  143.             _dblCollateralForward += convAdj.collateralForward() * dblUnitDCF;

  144.             _dblCollateralFunding += convAdj.collateralFunding() * dblUnitDCF;

  145.             _dblCollateralFX += convAdj.collateralFX() * dblUnitDCF;

  146.             _dblCreditForward += convAdj.creditForward() * dblUnitDCF;

  147.             _dblCreditFunding += convAdj.creditFunding() * dblUnitDCF;

  148.             _dblCreditFX += convAdj.creditFX() * dblUnitDCF;

  149.             _dblForwardFunding += convAdj.forwardFunding() * dblUnitDCF;

  150.             _dblForwardFX += convAdj.forwardFX() * dblUnitDCF;

  151.             _dblFundingFX += convAdj.fundingFX() * dblUnitDCF;
  152.         }

  153.         _dblCollateralCredit /= _dblDCF;
  154.         _dblCollateralForward /= _dblDCF;
  155.         _dblCollateralFunding /= _dblDCF;
  156.         _dblCollateralFX /= _dblDCF;
  157.         _dblCreditForward /= _dblDCF;
  158.         _dblCreditFunding /= _dblDCF;
  159.         _dblCreditFX /= _dblDCF;
  160.         _dblForwardFunding /= _dblDCF;
  161.         _dblForwardFX /= _dblDCF;
  162.         _dblFundingFX /= _dblDCF;
  163.         _dblRate = dblAmount / _dblDCF;
  164.         return true;
  165.     }

  166.     /**
  167.      * Retrieve the Composite DCF
  168.      *
  169.      * @return The Composite DCF
  170.      */

  171.     public double dcf()
  172.     {
  173.         return _dblDCF;
  174.     }

  175.     /**
  176.      * Retrieve the Composite Rate
  177.      *
  178.      * @return The Composite Rate
  179.      */

  180.     public double rate()
  181.     {
  182.         return _dblRate;
  183.     }

  184.     /**
  185.      * Retrieve the Collateral/Credit Convexity Adjustment
  186.      *
  187.      * @return The Collateral/Credit Convexity Adjustment
  188.      */

  189.     public double collateralCredit()
  190.     {
  191.         return _dblCollateralCredit;
  192.     }

  193.     /**
  194.      * Retrieve the Collateral/Forward Convexity Adjustment
  195.      *
  196.      * @return The Collateral/Forward Convexity Adjustment
  197.      */

  198.     public double collateralForward()
  199.     {
  200.         return _dblCollateralForward;
  201.     }

  202.     /**
  203.      * Retrieve the Collateral/Funding Convexity Adjustment
  204.      *
  205.      * @return The Collateral/Funding Convexity Adjustment
  206.      */

  207.     public double collateralFunding()
  208.     {
  209.         return _dblCollateralFunding;
  210.     }

  211.     /**
  212.      * Retrieve the Collateral/FX Convexity Adjustment
  213.      *
  214.      * @return The Collateral/FX Convexity Adjustment
  215.      */

  216.     public double collateralFX()
  217.     {
  218.         return _dblCollateralFX;
  219.     }

  220.     /**
  221.      * Retrieve the Credit/Forward Convexity Adjustment
  222.      *
  223.      * @return The Credit/Forward Convexity Adjustment
  224.      */

  225.     public double creditForward()
  226.     {
  227.         return _dblCreditForward;
  228.     }

  229.     /**
  230.      * Retrieve the Credit/Funding Convexity Adjustment
  231.      *
  232.      * @return The Credit/Funding Convexity Adjustment
  233.      */

  234.     public double creditFunding()
  235.     {
  236.         return _dblCreditFunding;
  237.     }

  238.     /**
  239.      * Retrieve the Credit/FX Convexity Adjustment
  240.      *
  241.      * @return The Credit/FX Convexity Adjustment
  242.      */

  243.     public double creditFX()
  244.     {
  245.         return _dblCreditFX;
  246.     }

  247.     /**
  248.      * Retrieve the Forward/Funding Convexity Adjustment
  249.      *
  250.      * @return The Forward/Funding Convexity Adjustment
  251.      */

  252.     public double forwardFunding()
  253.     {
  254.         return _dblForwardFunding;
  255.     }

  256.     /**
  257.      * Retrieve the Forward/FX Convexity Adjustment
  258.      *
  259.      * @return The Forward/FX Convexity Adjustment
  260.      */

  261.     public double forwardFX()
  262.     {
  263.         return _dblForwardFX;
  264.     }

  265.     /**
  266.      * Retrieve the Funding/FX Convexity Adjustment
  267.      *
  268.      * @return The Funding/FX Convexity Adjustment
  269.      */

  270.     public double fundingFX()
  271.     {
  272.         return _dblFundingFX;
  273.     }

  274.     /**
  275.      * Retrieve the Compounding Convexity Correction
  276.      *
  277.      * @return The Compounding Convexity Correction
  278.      */

  279.     public double compounding()
  280.     {
  281.         return _dblCollateralForward * _dblCreditForward * _dblForwardFunding * _dblForwardFX;
  282.     }

  283.     /**
  284.      * Retrieve the Cumulative Convexity Correction
  285.      *
  286.      * @return The Cumulative Convexity Correction
  287.      */

  288.     public double cumulative()
  289.     {
  290.         return _dblCollateralCredit * _dblCollateralForward * _dblCollateralFunding * _dblCollateralFX *
  291.             _dblCreditForward * _dblCreditFunding * _dblCreditFX * _dblForwardFunding * _dblForwardFX *
  292.                 _dblFundingFX;
  293.     }

  294.     /**
  295.      * Retrieve the List of the Unit Period Metrics
  296.      *
  297.      * @return The List of the Unit Period Metrics
  298.      */

  299.     public java.util.List<org.drip.analytics.output.UnitPeriodMetrics> unitMetrics()
  300.     {
  301.         return _lsUPM;
  302.     }
  303. }