Component.java

  1. package org.drip.product.definition;

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

  82. /**
  83.  * <i>Component</i> abstract class extends the ComponentMarketParamRef and provides the following methods:
  84.  *
  85.  * <br><br>
  86.  *  <ul>
  87.  *      <li>
  88.  *          Get the product's initial notional, notional, and coupon.
  89.  *      </li>
  90.  *      <li>
  91.  *          Get the Effective date, Maturity date, First Coupon Date.
  92.  *      </li>
  93.  *      <li>
  94.  *          List the coupon periods.
  95.  *      </li>
  96.  *      <li>
  97.  *          Set the market curves - discount, TSY, forward, and Credit curves.
  98.  *      </li>
  99.  *      <li>
  100.  *          Retrieve the product's settlement parameters.
  101.  *      </li>
  102.  *      <li>
  103.  *          Value the product's using standard/custom market parameters.
  104.  *      </li>
  105.  *      <li>
  106.  *          Retrieve the product's named measures and named measure values.
  107.  *      </li>
  108.  *  </ul>
  109.  *
  110.  *  <br><br>
  111.  *  <ul>
  112.  *      <li><b>Module </b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/ProductCore.md">Product Core Module</a></li>
  113.  *      <li><b>Library</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/FixedIncomeAnalyticsLibrary.md">Fixed Income Analytics</a></li>
  114.  *      <li><b>Project</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/product/README.md">Product Components/Baskets for Credit, FRA, FX, Govvie, Rates, and Option AssetClasses</a></li>
  115.  *      <li><b>Package</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/product/credit/README.md">Fixed Income Components/Baskets Definitions</a></li>
  116.  *  </ul>
  117.  * <br><br>
  118.  *
  119.  * @author Lakshmi Krishnamurthy
  120.  */

  121. public abstract class Component implements org.drip.product.definition.ComponentMarketParamRef {

  122.     protected double measureValue (
  123.         final java.lang.String strMeasure,
  124.         final org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double> mapCalc)
  125.         throws java.lang.Exception
  126.     {
  127.         if (null == strMeasure || strMeasure.isEmpty() || null == mapCalc || !mapCalc.containsKey
  128.             (strMeasure))
  129.             throw new java.lang.Exception ("Component::measureValue => Invalid Inputs");

  130.         return mapCalc.get (strMeasure);
  131.     }

  132.     protected boolean adjustForCashSettle (
  133.         final int iSettleDate,
  134.         final double dblPV,
  135.         final org.drip.state.discount.MergedDiscountForwardCurve dc,
  136.         final org.drip.numerical.differentiation.WengertJacobian wjPVDFMicroJack)
  137.     {
  138.         org.drip.numerical.differentiation.WengertJacobian wjCashSettleDFDF = dc.jackDDFDManifestMeasure (iSettleDate,
  139.             "Rate");

  140.         if (null == wjCashSettleDFDF) return false;

  141.         double dblDFCashSettle = java.lang.Double.NaN;

  142.         int iNumParameters = wjCashSettleDFDF.numParameters();

  143.         try {
  144.             dblDFCashSettle = dc.df (iSettleDate);
  145.         } catch (java.lang.Exception e) {
  146.             e.printStackTrace();

  147.             return false;
  148.         }

  149.         if (!wjPVDFMicroJack.scale (1. / dblDFCashSettle)) return false;

  150.         double dblSettleJackAdjust = -1. * dblPV / dblDFCashSettle / dblDFCashSettle;

  151.         for (int k = 0; k < iNumParameters; ++k) {
  152.             if (!wjPVDFMicroJack.accumulatePartialFirstDerivative (0, k, dblSettleJackAdjust *
  153.                 wjCashSettleDFDF.firstDerivative (0, k)))
  154.                 return false;
  155.         }

  156.         return true;
  157.     }

  158.     /**
  159.      * Get the Initial Notional for the Product
  160.      *
  161.      * @return Initial Notional
  162.      *
  163.      * @throws java.lang.Exception Thrown if Initial Notional cannot be computed
  164.      */

  165.     public abstract double initialNotional()
  166.         throws java.lang.Exception;

  167.     /**
  168.      * Get the Notional for the Product at the given date
  169.      *
  170.      * @param iDate Date
  171.      *
  172.      * @return Product Notional
  173.      *
  174.      * @throws java.lang.Exception Thrown if Notional cannot be computed
  175.      */

  176.     public abstract double notional (
  177.         final int iDate)
  178.         throws java.lang.Exception;

  179.     /**
  180.      * Get the time-weighted Notional for the Product between 2 dates
  181.      *
  182.      * @param iDate1 Date #1
  183.      * @param iDate2 Date #2
  184.      *
  185.      * @return The Product Notional
  186.      *
  187.      * @throws java.lang.Exception Thrown if Notional cannot be computed
  188.      */

  189.     public abstract double notional (
  190.         final int iDate1,
  191.         final int iDate2)
  192.         throws java.lang.Exception;

  193.     /**
  194.      * Get the Effective Date
  195.      *
  196.      * @return Effective Date
  197.      */

  198.     public abstract org.drip.analytics.date.JulianDate effectiveDate();

  199.     /**
  200.      * Get the Maturity Date
  201.      *
  202.      * @return Maturity Date
  203.      */

  204.     public abstract org.drip.analytics.date.JulianDate maturityDate();

  205.     /**
  206.      * Get the First Coupon Date
  207.      *
  208.      * @return First Coupon Date
  209.      */

  210.     public abstract org.drip.analytics.date.JulianDate firstCouponDate();

  211.     /**
  212.      * Retrieve the Coupon Frequency
  213.      *
  214.      * @return The Coupon Frequency
  215.      */

  216.     public abstract int freq();

  217.     /**
  218.      * Get the Product's Cash Flow Periods
  219.      *
  220.      * @return List of the Product's Cash Flow Periods
  221.      */

  222.     public abstract java.util.List<org.drip.analytics.cashflow.CompositePeriod> couponPeriods();

  223.     /**
  224.      * Get the Product's coupon Metrics at the specified accrual date
  225.      *
  226.      * @param iAccrualEndDate Accrual End Date
  227.      * @param valParams The Valuation Parameters
  228.      * @param csqs Component Market Parameters
  229.      *
  230.      * @return The Product's coupon Nominal/Adjusted Coupon Measures
  231.      */

  232.     public abstract org.drip.analytics.output.CompositePeriodCouponMetrics couponMetrics (
  233.         final int iAccrualEndDate,
  234.         final org.drip.param.valuation.ValuationParams valParams,
  235.         final org.drip.param.market.CurveSurfaceQuoteContainer csqs);

  236.     /**
  237.      * Get the Product's cash settlement parameters
  238.      *
  239.      * @return Cash settlement Parameters
  240.      */

  241.     public abstract org.drip.param.valuation.CashSettleParams cashSettleParams();

  242.     /**
  243.      * Generate a full list of the Product measures for the full input set of market parameters
  244.      *
  245.      * @param valParams ValuationParams
  246.      * @param pricerParams PricerParams
  247.      * @param csqs Market Parameters
  248.      * @param vcp Valuation Customization Parameters
  249.      *
  250.      * @return Map of measure name and value
  251.      */

  252.     public abstract org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double> value (
  253.         final org.drip.param.valuation.ValuationParams valParams,
  254.         final org.drip.param.pricer.CreditPricerParams pricerParams,
  255.         final org.drip.param.market.CurveSurfaceQuoteContainer csqs,
  256.         final org.drip.param.valuation.ValuationCustomizationParams vcp);

  257.     /**
  258.      * Retrieve the ordered set of the measure names whose values will be calculated
  259.      *
  260.      * @return Set of Measure Names
  261.      */

  262.     public abstract java.util.Set<java.lang.String> measureNames();

  263.     /**
  264.      * Compute the PV for the specified Market Parameters
  265.      *
  266.      * @param valParams ValuationParams
  267.      * @param pricerParams PricerParams
  268.      * @param csqc Market Parameters
  269.      * @param vcp Valuation Customization Parameters
  270.      *
  271.      * @return The PV
  272.      *
  273.      * @throws java.lang.Exception Thrown if the PV cannot be computed
  274.      */

  275.     public abstract double pv (
  276.         final org.drip.param.valuation.ValuationParams valParams,
  277.         final org.drip.param.pricer.CreditPricerParams pricerParams,
  278.         final org.drip.param.market.CurveSurfaceQuoteContainer csqc,
  279.         final org.drip.param.valuation.ValuationCustomizationParams vcp)
  280.         throws java.lang.Exception;

  281.     /**
  282.      * Get the Maturity Pay Date
  283.      *
  284.      * @return Maturity Pay Date
  285.      */

  286.     public org.drip.analytics.date.JulianDate maturityPayDate()
  287.     {
  288.         return maturityDate();
  289.     }

  290.     /**
  291.      * Calculate the value of the given Product's measure
  292.      *
  293.      * @param valParams ValuationParams
  294.      * @param pricerParams PricerParams
  295.      * @param csqs ComponentMarketParams
  296.      * @param strMeasure Measure String
  297.      * @param vcp Valuation Customization Parameters
  298.      *
  299.      * @return Double measure value
  300.      *
  301.      * @throws java.lang.Exception Thrown if the measure cannot be calculated
  302.      */

  303.     public double measureValue (
  304.         final org.drip.param.valuation.ValuationParams valParams,
  305.         final org.drip.param.pricer.CreditPricerParams pricerParams,
  306.         final org.drip.param.market.CurveSurfaceQuoteContainer csqs,
  307.         final org.drip.param.valuation.ValuationCustomizationParams vcp,
  308.         final java.lang.String strMeasure)
  309.         throws java.lang.Exception
  310.     {
  311.         return measureValue (strMeasure, value (valParams, pricerParams, csqs, vcp));
  312.     }

  313.     /**
  314.      * Retrieve the Instrument's Imputed Tenor
  315.      *
  316.      * @return The Instrument's Imputed Tenor
  317.      */

  318.     public java.lang.String tenor()
  319.     {
  320.         int iNumDays = maturityDate().julian() - effectiveDate().julian();

  321.         if (365 > iNumDays) {
  322.             int iNumMonth = (int) (0.5 + (iNumDays / 30.));

  323.             return 12 == iNumMonth ? "1Y" : iNumMonth + "M";
  324.         }

  325.          return ((int) (0.5 + (iNumDays / 365.))) + "Y";
  326.     }

  327.     /**
  328.      * Generate a full list of the Product's measures for the set of scenario market parameters present in
  329.      *  the org.drip.param.definition.MarketParams
  330.      *
  331.      * @param valParams ValuationParams
  332.      * @param pricerParams PricerParams
  333.      * @param mpc org.drip.param.definition.MarketParams
  334.      * @param vcp Valuation Customization Parameters
  335.      *
  336.      * @return ComponentOutput object
  337.      */

  338.     public org.drip.analytics.output.ComponentMeasures measures (
  339.         final org.drip.param.valuation.ValuationParams valParams,
  340.         final org.drip.param.pricer.CreditPricerParams pricerParams,
  341.         final org.drip.param.definition.ScenarioMarketParams mpc,
  342.         final org.drip.param.valuation.ValuationCustomizationParams vcp)
  343.     {
  344.         if (null == valParams || null == mpc) return null;

  345.         org.drip.param.market.CurveSurfaceQuoteContainer csqsBase = mpc.scenarioMarketParams (this, "Base");

  346.         if (null == csqsBase) return null;

  347.         org.drip.analytics.output.ComponentMeasures compOp = new
  348.             org.drip.analytics.output.ComponentMeasures();

  349.         long lStart = System.nanoTime();

  350.         org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double> mapBaseMeasures = value
  351.             (valParams, pricerParams, csqsBase, vcp);

  352.         if (!compOp.setBaseMeasures (mapBaseMeasures)) return null;

  353.         org.drip.param.market.CurveSurfaceQuoteContainer csqsFlatCreditBumpUp = mpc.scenarioMarketParams (this,
  354.             "FlatCreditBumpUp");

  355.         if (null != csqsFlatCreditBumpUp) {
  356.             org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double> mapFlatCreditBumpUpMeasures =
  357.                 value (valParams, pricerParams, csqsFlatCreditBumpUp, vcp);

  358.             java.util.Set<java.util.Map.Entry<java.lang.String, java.lang.Double>> mapFlatCreditBumpUpES =
  359.                 null == mapFlatCreditBumpUpMeasures ? null : mapFlatCreditBumpUpMeasures.entrySet();

  360.             if (null != mapFlatCreditBumpUpES && 0 != mapFlatCreditBumpUpES.size()) {
  361.                 org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double>
  362.                     mapFlatCreditDeltaMeasures = new
  363.                         org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double>();

  364.                 for (java.util.Map.Entry<java.lang.String, java.lang.Double> me : mapFlatCreditBumpUpES) {
  365.                     java.lang.String strKey = me.getKey();

  366.                     mapFlatCreditDeltaMeasures.put (strKey, me.getValue() - mapBaseMeasures.get (strKey));
  367.                 }

  368.                 org.drip.param.market.CurveSurfaceQuoteContainer csqsFlatCreditBumpDown = mpc.scenarioMarketParams
  369.                     (this, "FlatCreditBumpDn");

  370.                 if (compOp.setFlatCreditDeltaMeasures (mapFlatCreditDeltaMeasures) && null !=
  371.                     csqsFlatCreditBumpDown) {
  372.                     org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double>
  373.                         mapFlatCreditBumpDownMeasures = value (valParams, pricerParams,
  374.                             csqsFlatCreditBumpDown, vcp);

  375.                     java.util.Set<java.util.Map.Entry<java.lang.String, java.lang.Double>>
  376.                         mapFlatCreditBumpDownES = null == mapFlatCreditBumpDownMeasures ? null :
  377.                             mapFlatCreditBumpDownMeasures.entrySet();

  378.                     if (null != mapFlatCreditBumpDownES && 0 != mapFlatCreditBumpDownES.size()) {
  379.                         org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double>
  380.                             mapFlatCreditGammaMeasures = new
  381.                                 org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double>();

  382.                         for (java.util.Map.Entry<java.lang.String, java.lang.Double> me :
  383.                             mapFlatCreditBumpDownES) {
  384.                             java.lang.String strKey = me.getKey();

  385.                             mapFlatCreditGammaMeasures.put (strKey, me.getValue() +
  386.                                 mapFlatCreditBumpUpMeasures.get (strKey) - 2. * mapBaseMeasures.get
  387.                                     (strKey));
  388.                         }

  389.                         compOp.setFlatCreditGammaMeasures (mapFlatCreditGammaMeasures);
  390.                     }
  391.                 }
  392.             }
  393.         }

  394.         org.drip.param.market.CurveSurfaceQuoteContainer csqsRRBumpUp = mpc.scenarioMarketParams (this, "RRBumpUp");

  395.         if (null != csqsRRBumpUp) {
  396.             org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double> mapRRBumpUpMeasures = value
  397.                 (valParams, pricerParams, csqsRRBumpUp, vcp);

  398.             java.util.Set<java.util.Map.Entry<java.lang.String, java.lang.Double>> mapRRBumpUpES = null ==
  399.                 mapRRBumpUpMeasures ? null : mapRRBumpUpMeasures.entrySet();

  400.             if (null != mapRRBumpUpES && 0 != mapRRBumpUpES.size()) {
  401.                 org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double> mapFlatRRDeltaMeasures =
  402.                     new org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double>();

  403.                 for (java.util.Map.Entry<java.lang.String, java.lang.Double> me : mapRRBumpUpES) {
  404.                     java.lang.String strKey = me.getKey();

  405.                     mapFlatRRDeltaMeasures.put (strKey, me.getValue() - mapBaseMeasures.get (strKey));
  406.                 }

  407.                 org.drip.param.market.CurveSurfaceQuoteContainer csqsRRBumpDown = mpc.scenarioMarketParams (this,
  408.                     "RRBumpDn");

  409.                 if (compOp.setFlatRRDeltaMeasures (mapFlatRRDeltaMeasures) && null != csqsRRBumpDown) {
  410.                     org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double> mapRRBumpDownMeasures
  411.                         = value (valParams, pricerParams, csqsRRBumpDown, vcp);

  412.                     java.util.Set<java.util.Map.Entry<java.lang.String, java.lang.Double>> mapRRBumpDownES =
  413.                         null == mapRRBumpDownMeasures ? null : mapRRBumpDownMeasures.entrySet();

  414.                     if (null != mapRRBumpDownES && 0 != mapRRBumpDownES.size()) {
  415.                         org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double>
  416.                             mapFlatRRGammaMeasures = new
  417.                                 org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double>();

  418.                         for (java.util.Map.Entry<java.lang.String, java.lang.Double> me : mapRRBumpDownES) {
  419.                             java.lang.String strKey = me.getKey();

  420.                             mapFlatRRGammaMeasures.put (strKey, me.getValue() + mapRRBumpUpMeasures.get
  421.                                 (strKey) - 2. * mapBaseMeasures.get (strKey));
  422.                         }

  423.                         compOp.setFlatRRGammaMeasures (mapFlatRRGammaMeasures);
  424.                     }
  425.                 }
  426.             }
  427.         }

  428.         org.drip.param.market.CurveSurfaceQuoteContainer csqsIRCreditBumpUp = mpc.scenarioMarketParams (this,
  429.             "IRCreditBumpUp");

  430.         if (null != csqsIRCreditBumpUp) {
  431.             org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double> mapIRCreditBumpUpMeasures =
  432.                 value (valParams, pricerParams, csqsIRCreditBumpUp, vcp);

  433.             java.util.Set<java.util.Map.Entry<java.lang.String, java.lang.Double>> mapIRCreditBumpUpES = null
  434.                 == mapIRCreditBumpUpMeasures ? null : mapIRCreditBumpUpMeasures.entrySet();

  435.             if (null != mapIRCreditBumpUpES && 0 != mapIRCreditBumpUpES.size()) {
  436.                 org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double> mapFlatIRDeltaMeasures =
  437.                     new org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double>();

  438.                 for (java.util.Map.Entry<java.lang.String, java.lang.Double> me : mapIRCreditBumpUpES) {
  439.                     java.lang.String strKey = me.getKey();

  440.                     mapFlatIRDeltaMeasures.put (strKey, me.getValue() - mapBaseMeasures.get (strKey));
  441.                 }

  442.                 org.drip.param.market.CurveSurfaceQuoteContainer csqsIRCreditBumpDown = mpc.scenarioMarketParams (this,
  443.                     "IRCreditBumpDn");

  444.                 if (compOp.setFlatIRDeltaMeasures (mapFlatIRDeltaMeasures) && null != csqsIRCreditBumpDown) {
  445.                     org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double>
  446.                         mapIRCreditBumpDownMeasures = value (valParams, pricerParams, csqsIRCreditBumpDown,
  447.                             vcp);

  448.                     java.util.Set<java.util.Map.Entry<java.lang.String, java.lang.Double>>
  449.                         mapIRCreditBumpDownES = null == mapIRCreditBumpDownMeasures ? null :
  450.                             mapIRCreditBumpDownMeasures.entrySet();

  451.                     if (null != mapIRCreditBumpDownES && 0 != mapIRCreditBumpDownES.size()) {
  452.                         org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double>
  453.                             mapFlatIRGammaMeasures = new
  454.                                 org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double>();

  455.                         for (java.util.Map.Entry<java.lang.String, java.lang.Double> me :
  456.                             mapIRCreditBumpDownES) {
  457.                             java.lang.String strKey = me.getKey();

  458.                             mapFlatIRGammaMeasures.put (strKey, me.getValue() +
  459.                                 mapIRCreditBumpUpMeasures.get (strKey) - 2. * mapBaseMeasures.get (strKey));
  460.                         }

  461.                         compOp.setFlatIRGammaMeasures (mapFlatIRGammaMeasures);
  462.                     }
  463.                 }
  464.             }
  465.         }

  466.         org.drip.analytics.support.CaseInsensitiveTreeMap<org.drip.param.market.CurveSurfaceQuoteContainer>
  467.             mapCCTenorUpCSQS = mpc.creditTenorMarketParams (this, true);

  468.         if (null != mapCCTenorUpCSQS) {
  469.             compOp.setTenorCreditDeltaMeasures (new
  470.                 org.drip.analytics.support.CaseInsensitiveTreeMap<org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double>>());

  471.             if (null != mapCCTenorUpCSQS && null != mapCCTenorUpCSQS.entrySet()) {
  472.                 for (java.util.Map.Entry<java.lang.String, org.drip.param.market.CurveSurfaceQuoteContainer>
  473.                     meTenorUpMP : mapCCTenorUpCSQS.entrySet()) {
  474.                     if (null == meTenorUpMP || null == meTenorUpMP.getValue()) continue;

  475.                     org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double> mapCCTenorUp = value
  476.                         (valParams, pricerParams, meTenorUpMP.getValue(), vcp);

  477.                     if (null == mapCCTenorUp || null == mapCCTenorUp.entrySet()) continue;

  478.                     org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double> mapCalcUp = new
  479.                         org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double>();

  480.                     for (java.util.Map.Entry<java.lang.String, java.lang.Double> me :
  481.                         mapCCTenorUp.entrySet()) {
  482.                         java.lang.String strKey = me.getKey();

  483.                         mapCalcUp.put (strKey, me.getValue() - mapBaseMeasures.get (strKey));
  484.                     }

  485.                     compOp.tenorCreditDeltaMeasures().put (meTenorUpMP.getKey(), mapCalcUp);
  486.                 }

  487.                 if (null != mpc.creditTenorMarketParams (this, false)) {
  488.                     compOp.setTenorCreditGammaMeasures (new
  489.                         org.drip.analytics.support.CaseInsensitiveTreeMap<org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double>>());

  490.                     org.drip.analytics.support.CaseInsensitiveTreeMap<org.drip.param.market.CurveSurfaceQuoteContainer>
  491.                         mapCCTenorDnCSQS = mpc.creditTenorMarketParams (this, false);

  492.                     if (null != mapCCTenorDnCSQS && null != mapCCTenorDnCSQS.entrySet()) {
  493.                         for (java.util.Map.Entry<java.lang.String,
  494.                             org.drip.param.market.CurveSurfaceQuoteContainer> meTenorDnMP :
  495.                                 mapCCTenorDnCSQS.entrySet()) {
  496.                             if (null == meTenorDnMP || null == meTenorDnMP.getValue()) continue;

  497.                             org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double> mapCCTenorDn
  498.                                 = value (valParams, pricerParams, meTenorDnMP.getValue(), vcp);

  499.                             if (null == mapCCTenorDn || null == mapCCTenorDn.entrySet()) continue;

  500.                             org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double> mapCalcDn =
  501.                                 new org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double>();

  502.                             for (java.util.Map.Entry<java.lang.String, java.lang.Double> me :
  503.                                 mapCCTenorDn.entrySet()) {
  504.                                 java.lang.String strKey = me.getKey();

  505.                                 mapCalcDn.put (strKey, me.getValue() - mapBaseMeasures.get (strKey) +
  506.                                     compOp.tenorCreditDeltaMeasures().get (meTenorDnMP.getKey()).get
  507.                                         (strKey));
  508.                             }

  509.                             compOp.tenorCreditGammaMeasures().put (meTenorDnMP.getKey(), mapCalcDn);
  510.                         }
  511.                     }
  512.                 }
  513.             }
  514.         }

  515.         if (null != mpc.fundingTenorMarketParams (this, true)) {
  516.             compOp.setTenorIRDeltaMeasures (new
  517.                 org.drip.analytics.support.CaseInsensitiveTreeMap<org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double>>());

  518.             org.drip.analytics.support.CaseInsensitiveTreeMap<org.drip.param.market.CurveSurfaceQuoteContainer>
  519.                 mapIRTenorUpCSQS = mpc.fundingTenorMarketParams (this, true);

  520.             if (null != mapIRTenorUpCSQS && null != mapIRTenorUpCSQS.entrySet()) {
  521.                 for (java.util.Map.Entry<java.lang.String, org.drip.param.market.CurveSurfaceQuoteContainer>
  522.                     meTenorUpMP : mapIRTenorUpCSQS.entrySet()) {
  523.                     org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double> mapCCTenorUp = value
  524.                         (valParams, pricerParams, meTenorUpMP.getValue(), vcp);

  525.                     if (null == mapCCTenorUp || null == mapCCTenorUp.entrySet()) continue;

  526.                     org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double> mapCalcUp = new
  527.                         org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double>();

  528.                     for (java.util.Map.Entry<java.lang.String, java.lang.Double> me :
  529.                         mapCCTenorUp.entrySet()) {
  530.                         java.lang.String strKey = me.getKey();

  531.                         mapCalcUp.put (strKey, me.getValue() - mapBaseMeasures.get (strKey));
  532.                     }

  533.                     compOp.tenorIRDeltaMeasures().put (meTenorUpMP.getKey(), mapCalcUp);
  534.                 }
  535.             }

  536.             if (null != mpc.fundingTenorMarketParams (this, false)) {
  537.                 compOp.setTenorIRGammaMeasures (new
  538.                     org.drip.analytics.support.CaseInsensitiveTreeMap<org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double>>());

  539.                 org.drip.analytics.support.CaseInsensitiveTreeMap<org.drip.param.market.CurveSurfaceQuoteContainer>
  540.                     mapIRTenorDnCSQS = mpc.fundingTenorMarketParams (this, false);

  541.                 if (null != mapIRTenorDnCSQS & null != mapIRTenorDnCSQS.entrySet()) {
  542.                     for (java.util.Map.Entry<java.lang.String, org.drip.param.market.CurveSurfaceQuoteContainer>
  543.                         meTenorDnMP : mapIRTenorDnCSQS.entrySet()) {
  544.                         org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double> mapCCTenorDn = value
  545.                             (valParams, pricerParams, meTenorDnMP.getValue(), vcp);

  546.                         org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double> mapCalcDn = new
  547.                             org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double>();

  548.                         if (null == mapCalcDn || null == mapCalcDn.entrySet()) continue;

  549.                         for (java.util.Map.Entry<java.lang.String, java.lang.Double> me :
  550.                             mapCCTenorDn.entrySet()) {
  551.                             java.lang.String strKey = me.getKey();

  552.                             mapCalcDn.put (strKey, me.getValue() - mapBaseMeasures.get (strKey) +
  553.                                 compOp.tenorIRDeltaMeasures().get (meTenorDnMP.getKey()).get (strKey));
  554.                         }

  555.                         compOp.tenorIRGammaMeasures().put (meTenorDnMP.getKey(), mapCalcDn);
  556.                     }
  557.                 }
  558.             }
  559.         }

  560.         compOp.setCalcTime ((System.nanoTime() - lStart) * 1.e-09);

  561.         return compOp;
  562.     }

  563.     /**
  564.      * Generate a full list of custom measures for the set of scenario market parameters present in
  565.      *  the org.drip.param.definition.MarketParams
  566.      *
  567.      * @param valParams ValuationParams
  568.      * @param pricerParams PricerParams
  569.      * @param mpc org.drip.param.definition.MarketParams
  570.      * @param strCustomScenName Custom Scenario Name
  571.      * @param vcp Valuation Customization Parameters
  572.      * @param mapBaseMeasures Base Measures from used to calculate the desired delta measure. If null, the
  573.      *  base measures will be generated.
  574.      *
  575.      * @return Custom Scenarios Measures output set
  576.      */

  577.     public org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double> customScenarioMeasures (
  578.         final org.drip.param.valuation.ValuationParams valParams,
  579.         final org.drip.param.pricer.CreditPricerParams pricerParams,
  580.         final org.drip.param.definition.ScenarioMarketParams mpc,
  581.         final java.lang.String strCustomScenName,
  582.         final org.drip.param.valuation.ValuationCustomizationParams vcp,
  583.         org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double> mapBaseMeasures)
  584.     {
  585.         if (null == strCustomScenName || strCustomScenName.isEmpty() || null == valParams || null == mpc)
  586.             return null;

  587.         org.drip.param.market.CurveSurfaceQuoteContainer csqsCustom = mpc.scenarioMarketParams (this,
  588.             strCustomScenName);

  589.         if (null == csqsCustom) return null;

  590.         if (null == mapBaseMeasures) {
  591.             org.drip.param.market.CurveSurfaceQuoteContainer csqsBase = mpc.scenarioMarketParams (this, "Base");

  592.             if (null == csqsBase || null == (mapBaseMeasures = value (valParams, pricerParams, csqsBase,
  593.                 vcp)))
  594.                 return null;
  595.         }

  596.         org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double> mapCustomMeasures = value
  597.             (valParams, pricerParams, csqsCustom, vcp);

  598.         java.util.Set<java.util.Map.Entry<java.lang.String, java.lang.Double>> mapCustomMeasuresES = null ==
  599.             mapCustomMeasures ? null : mapCustomMeasures.entrySet();

  600.         if (null == mapCustomMeasuresES || 0 == mapCustomMeasuresES.size()) return null;

  601.         org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double> mapCustomDeltaMeasures = new
  602.             org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double>();

  603.         for (java.util.Map.Entry<java.lang.String, java.lang.Double> me : mapCustomMeasuresES) {
  604.             java.lang.String strKey = me.getKey();

  605.             mapCustomDeltaMeasures.put (strKey, me.getValue() - mapBaseMeasures.get (strKey));
  606.         }

  607.         return mapCustomDeltaMeasures;
  608.     }
  609. }