BulletMetrics.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>BulletMetrics</i> holds the results of the Bullet Cash flow metrics estimate output.
  81.  *
  82.  *  <br><br>
  83.  *  <ul>
  84.  *      <li><b>Module </b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/ProductCore.md">Product Core Module</a></li>
  85.  *      <li><b>Library</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/FixedIncomeAnalyticsLibrary.md">Fixed Income Analytics</a></li>
  86.  *      <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>
  87.  *      <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>
  88.  *  </ul>
  89.  *
  90.  * @author Lakshmi Krishnamurthy
  91.  */

  92. public class BulletMetrics {

  93.     /*
  94.      * Bullet Latent State Identification Support Fields
  95.      */

  96.     private org.drip.state.identifier.EntityCDSLabel _creditLabel = null;
  97.     private org.drip.state.identifier.FundingLabel _fundingLabel = null;
  98.     private org.drip.state.identifier.FXLabel _fxLabel = null;

  99.     /*
  100.      * Bullet Parameters Specification Fields
  101.      */

  102.     private int _iTerminalDate = java.lang.Integer.MIN_VALUE;
  103.     private int _iPayDate = java.lang.Integer.MIN_VALUE;
  104.     private double _dblNotional = java.lang.Double.NaN;

  105.     /*
  106.      * Bullet State Point Value Fields
  107.      */

  108.     private double _dblSurvival = java.lang.Double.NaN;
  109.     private double _dblDF = java.lang.Double.NaN;
  110.     private double _dblFX = java.lang.Double.NaN;

  111.     /*
  112.      * Bullet Convexity Adjustment Fields
  113.      */

  114.     private org.drip.analytics.output.ConvexityAdjustment _convAdj = null;

  115.     /**
  116.      * BulletMetrics Constructor
  117.      *
  118.      * @param iTerminalDate Terminal Date
  119.      * @param iPayDate Pay Date
  120.      * @param dblNotional Notional
  121.      * @param dblSurvival Terminal Survival
  122.      * @param dblDF Terminal Discount Factor
  123.      * @param dblFX Terminal FX Rate
  124.      * @param convAdj Terminal Convexity Adjustment
  125.      * @param creditLabel The Credit Label
  126.      * @param fundingLabel The Funding Label
  127.      * @param fxLabel The FX Label
  128.      *
  129.      * @throws java.lang.Exception Thrown if Inputs are invalid
  130.      */

  131.     public BulletMetrics (
  132.         final int iTerminalDate,
  133.         final int iPayDate,
  134.         final double dblNotional,
  135.         final double dblSurvival,
  136.         final double dblDF,
  137.         final double dblFX,
  138.         final org.drip.analytics.output.ConvexityAdjustment convAdj,
  139.         final org.drip.state.identifier.EntityCDSLabel creditLabel,
  140.         final org.drip.state.identifier.FundingLabel fundingLabel,
  141.         final org.drip.state.identifier.FXLabel fxLabel)
  142.         throws java.lang.Exception
  143.     {
  144.         if (!org.drip.numerical.common.NumberUtil.IsValid (_dblNotional = dblNotional) ||
  145.             !org.drip.numerical.common.NumberUtil.IsValid (_dblSurvival = dblSurvival) ||
  146.                 !org.drip.numerical.common.NumberUtil.IsValid (_dblDF = dblDF) ||
  147.                     !org.drip.numerical.common.NumberUtil.IsValid (_dblFX = dblFX) || null == (_convAdj =
  148.                         convAdj) || null == (_fundingLabel = fundingLabel))
  149.             throw new java.lang.Exception ("BulletMetrics ctr: Invalid Inputs");

  150.         _fxLabel = fxLabel;
  151.         _iPayDate = iPayDate;
  152.         _creditLabel = creditLabel;
  153.         _iTerminalDate = iTerminalDate;
  154.     }

  155.     /**
  156.      * Retrieve the Terminal Date
  157.      *
  158.      * @return The Terminal Date
  159.      */

  160.     public int terminalDate()
  161.     {
  162.         return _iTerminalDate;
  163.     }

  164.     /**
  165.      * Retrieve the Pay Date
  166.      *
  167.      * @return The Pay Date
  168.      */

  169.     public int payDate()
  170.     {
  171.         return _iPayDate;
  172.     }

  173.     /**
  174.      * Retrieve the Terminal Notional
  175.      *
  176.      * @return The Terminal Notional
  177.      */

  178.     public double notional()
  179.     {
  180.         return _dblNotional;
  181.     }

  182.     /**
  183.      * Retrieve the Terminal Survival Probability
  184.      *
  185.      * @return The Terminal Survival Probability
  186.      */

  187.     public double survival()
  188.     {
  189.         return _dblSurvival;
  190.     }

  191.     /**
  192.      * Retrieve the Terminal DF
  193.      *
  194.      * @return The Terminal DF
  195.      */

  196.     public double df()
  197.     {
  198.         return _dblDF;
  199.     }

  200.     /**
  201.      * Retrieve the Terminal FX Rate
  202.      *
  203.      * @return The Terminal FX Rate
  204.      */

  205.     public double fx()
  206.     {
  207.         return _dblFX;
  208.     }

  209.     /**
  210.      * Retrieve the Terminal Annuity in the Pay Currency
  211.      *
  212.      * @return The Terminal Annuity in the Pay Currency
  213.      */

  214.     public double annuity()
  215.     {
  216.         return _dblNotional * _dblSurvival * _dblDF * _dblFX;
  217.     }

  218.     /**
  219.      * Retrieve the Terminal Convexity Adjustment
  220.      *
  221.      * @return The Terminal Convexity Adjustment
  222.      */

  223.     public org.drip.analytics.output.ConvexityAdjustment convexityAdjustment()
  224.     {
  225.         return _convAdj;
  226.     }

  227.     /**
  228.      * Retrieve the Terminal Survival Probability Loading Coefficient for the specified Credit Latent State
  229.      *
  230.      * @param creditLabel The Credit Label
  231.      *
  232.      * @return The Terminal Survival Probability Loading Coefficient for the specified Credit Latent State
  233.      */

  234.     public java.util.Map<java.lang.Integer, java.lang.Double> survivalProbabilityCreditLoading (
  235.         final org.drip.state.identifier.EntityCDSLabel creditLabel)
  236.     {
  237.         if (null == creditLabel || !creditLabel.match (_creditLabel)) return null;

  238.         java.util.Map<java.lang.Integer, java.lang.Double> mapSurvivalProbabilityLoading = new
  239.             java.util.TreeMap<java.lang.Integer, java.lang.Double>();

  240.         mapSurvivalProbabilityLoading.put (_iPayDate, _dblNotional * _dblDF * _dblFX *
  241.             _convAdj.cumulative());

  242.         return mapSurvivalProbabilityLoading;
  243.     }

  244.     /**
  245.      * Retrieve the Discount Factor Loading Coefficient for the specified Funding Latent State
  246.      *
  247.      * @param fundingLabel The Funding Label
  248.      *
  249.      * @return The Discount Factor Loading Coefficient for the specified Funding Latent State
  250.      */

  251.     public java.util.Map<java.lang.Integer, java.lang.Double> discountFactorFundingLoading (
  252.         final org.drip.state.identifier.FundingLabel fundingLabel)
  253.     {
  254.         if (null == fundingLabel || !fundingLabel.match (_fundingLabel)) return null;

  255.         java.util.Map<java.lang.Integer, java.lang.Double> mapDiscountFactorLoading = new
  256.             java.util.TreeMap<java.lang.Integer, java.lang.Double>();

  257.         mapDiscountFactorLoading.put (_iPayDate, _dblNotional * _dblSurvival * _dblFX *
  258.             _convAdj.cumulative());

  259.         return mapDiscountFactorLoading;
  260.     }

  261.     /**
  262.      * Retrieve the FX Loading Coefficient for the specified FX Latent State
  263.      *
  264.      * @param fxLabel The FX Label
  265.      *
  266.      * @return The FX Loading Coefficient for the specified FX Latent State
  267.      */

  268.     public java.util.Map<java.lang.Integer, java.lang.Double> fxFXLoading (
  269.         final org.drip.state.identifier.FXLabel fxLabel)
  270.     {
  271.         if (null == fxLabel || !fxLabel.match (_fxLabel)) return null;

  272.         java.util.Map<java.lang.Integer, java.lang.Double> mapFXLoading = new
  273.             java.util.TreeMap<java.lang.Integer, java.lang.Double>();

  274.         mapFXLoading.put (_iPayDate, _dblNotional * _dblSurvival * _dblDF * _convAdj.cumulative());

  275.         return mapFXLoading;
  276.     }

  277.     /**
  278.      * Retrieve the Credit Label
  279.      *
  280.      * @return The Credit Label
  281.      */

  282.     public org.drip.state.identifier.EntityCDSLabel creditLabel()
  283.     {
  284.         return _creditLabel;
  285.     }

  286.     /**
  287.      * Retrieve the Funding Label
  288.      *
  289.      * @return The Funding Label
  290.      */

  291.     public org.drip.state.identifier.FundingLabel fundingLabel()
  292.     {
  293.         return _fundingLabel;
  294.     }

  295.     /**
  296.      * Retrieve the FX Label
  297.      *
  298.      * @return The FX Label
  299.      */

  300.     public org.drip.state.identifier.FXLabel fxLabel()
  301.     {
  302.         return _fxLabel;
  303.     }
  304. }