BasketProduct.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>BasketProduct</i> abstract class extends MarketParamRef. It provides methods for getting the basket’s
  84.  * components, notional, coupon, effective date, maturity date, coupon amount, and list of coupon periods.
  85.  *
  86.  *  <br><br>
  87.  *  <ul>
  88.  *      <li><b>Module </b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/ProductCore.md">Product Core Module</a></li>
  89.  *      <li><b>Library</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/FixedIncomeAnalyticsLibrary.md">Fixed Income Analytics</a></li>
  90.  *      <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>
  91.  *      <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>
  92.  *  </ul>
  93.  * <br><br>
  94.  *  
  95.  * @author Lakshmi Krishnamurthy
  96.  */

  97. public abstract class BasketProduct implements org.drip.product.definition.BasketMarketParamRef {
  98.     protected static final int MEASURE_AGGREGATION_TYPE_CUMULATIVE = 1;
  99.     protected static final int MEASURE_AGGREGATION_TYPE_WEIGHTED_CUMULATIVE = 2;
  100.     protected static final int MEASURE_AGGREGATION_TYPE_UNIT_ACCUMULATE = 4;
  101.     protected static final int MEASURE_AGGREGATION_TYPE_IGNORE = 4;

  102.     class ComponentCurve {
  103.         java.lang.String _strName = null;
  104.         org.drip.state.credit.CreditCurve _cc = null;

  105.         ComponentCurve (
  106.             final java.lang.String strName,
  107.             final org.drip.state.credit.CreditCurve cc)
  108.         {
  109.             _cc = cc;
  110.             _strName = strName;
  111.         }
  112.     }

  113.     class FlatDeltaGammaMeasureMap {
  114.         org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double> _mapDelta = null;
  115.         org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double> _mapGamma = null;

  116.         FlatDeltaGammaMeasureMap (
  117.             final org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double> mapDelta,
  118.             final org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double> mapGamma)
  119.         {
  120.             _mapDelta = mapDelta;
  121.             _mapGamma = mapGamma;
  122.         }
  123.     }

  124.     class TenorDeltaGammaMeasureMap {
  125.         org.drip.analytics.support.CaseInsensitiveTreeMap<org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double>>
  126.             _mmDelta = null;
  127.         org.drip.analytics.support.CaseInsensitiveTreeMap<org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double>>
  128.             _mmGamma = null;

  129.         TenorDeltaGammaMeasureMap (
  130.             final
  131.                 org.drip.analytics.support.CaseInsensitiveTreeMap<org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double>>
  132.                     mmDelta,
  133.             final
  134.                 org.drip.analytics.support.CaseInsensitiveTreeMap<org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double>>
  135.                     mmGamma)
  136.         {
  137.             _mmDelta = mmDelta;
  138.             _mmGamma = mmGamma;
  139.         }
  140.     }

  141.     class ComponentFactorTenorDeltaGammaMeasureMap {
  142.         org.drip.analytics.support.CaseInsensitiveTreeMap<org.drip.analytics.support.CaseInsensitiveTreeMap<org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double>>>
  143.             _mmmDelta = null;
  144.         org.drip.analytics.support.CaseInsensitiveTreeMap<org.drip.analytics.support.CaseInsensitiveTreeMap<org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double>>>
  145.             _mmmGamma = null;

  146.         ComponentFactorTenorDeltaGammaMeasureMap (
  147.             final
  148.                 org.drip.analytics.support.CaseInsensitiveTreeMap<org.drip.analytics.support.CaseInsensitiveTreeMap<org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double>>>
  149.                     mmmDelta,
  150.             final
  151.                 org.drip.analytics.support.CaseInsensitiveTreeMap<org.drip.analytics.support.CaseInsensitiveTreeMap<org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double>>>
  152.                     mmmGamma)
  153.         {
  154.             _mmmDelta = mmmDelta;
  155.             _mmmGamma = mmmGamma;
  156.         }
  157.     }

  158.     private FlatDeltaGammaMeasureMap accumulateDeltaGammaMeasures (
  159.         final org.drip.param.valuation.ValuationParams valParams,
  160.         final org.drip.param.pricer.CreditPricerParams pricerParams,
  161.         final org.drip.param.market.CurveSurfaceQuoteContainer csqsUp,
  162.         final org.drip.param.market.CurveSurfaceQuoteContainer csqsDown,
  163.         final org.drip.param.valuation.ValuationCustomizationParams vcp,
  164.         final org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double> mapBaseMeasures)
  165.     {
  166.         if (null == csqsUp) return null;

  167.         org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double> mapUpMeasures = value (valParams,
  168.             pricerParams, csqsUp, vcp);

  169.         if (null == mapUpMeasures || 0 == mapUpMeasures.size()) return null;

  170.         java.util.Set<java.util.Map.Entry<java.lang.String, java.lang.Double>> mapUpMeasuresES =
  171.             mapUpMeasures.entrySet();

  172.         if (null == mapUpMeasuresES) return null;

  173.         org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double> mapDeltaMeasures = new
  174.             org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double>();

  175.         for (java.util.Map.Entry<java.lang.String, java.lang.Double> meUp : mapUpMeasuresES) {
  176.             if (null == meUp) continue;

  177.             java.lang.String strKey = meUp.getKey();

  178.             if (null == strKey || strKey.isEmpty()) continue;

  179.             java.lang.Double dblBase = mapBaseMeasures.get (strKey);

  180.             java.lang.Double dblUp = meUp.getValue();

  181.             mapDeltaMeasures.put (strKey, (null == dblUp ? 0. : dblUp) - (null == dblBase ? 0. : dblBase));
  182.         }

  183.         if (null == csqsDown) return new FlatDeltaGammaMeasureMap (mapDeltaMeasures, null);

  184.         org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double> mapDownMeasures = value
  185.             (valParams, pricerParams, csqsDown, vcp);

  186.         if (null == mapDownMeasures || 0 == mapDownMeasures.size())
  187.             return new FlatDeltaGammaMeasureMap (mapDeltaMeasures, null);

  188.         java.util.Set<java.util.Map.Entry<java.lang.String, java.lang.Double>> mapDownMeasuresES =
  189.             mapDownMeasures.entrySet();

  190.         if (null == mapDownMeasuresES) return new FlatDeltaGammaMeasureMap (mapDeltaMeasures, null);

  191.         org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double> mapGammaMeasures = new
  192.             org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double>();

  193.         for (java.util.Map.Entry<java.lang.String, java.lang.Double> meDown : mapDownMeasuresES) {
  194.             if (null == meDown) continue;

  195.             java.lang.String strKey = meDown.getKey();

  196.             if (null == strKey || strKey.isEmpty()) continue;

  197.             java.lang.Double dblBase = mapBaseMeasures.get (strKey);

  198.             java.lang.Double dblUp = mapUpMeasures.get (strKey);

  199.             java.lang.Double dblDown = meDown.getValue();

  200.             mapGammaMeasures.put (strKey, (null == dblUp ? 0. : dblUp) + (null == dblDown ? 0. : dblDown) -
  201.                 (null == dblBase ? 0. : 2. * dblBase));
  202.         }

  203.         return new FlatDeltaGammaMeasureMap (mapDeltaMeasures, mapGammaMeasures);
  204.     }

  205.     private TenorDeltaGammaMeasureMap accumulateTenorDeltaGammaMeasures (
  206.         final org.drip.param.valuation.ValuationParams valParams,
  207.         final org.drip.param.pricer.CreditPricerParams pricerParams,
  208.         final org.drip.analytics.support.CaseInsensitiveTreeMap<org.drip.param.market.CurveSurfaceQuoteContainer>
  209.             mapTenorUpCSQS,
  210.         final org.drip.analytics.support.CaseInsensitiveTreeMap<org.drip.param.market.CurveSurfaceQuoteContainer>
  211.             mapTenorDownCSQS,
  212.         final org.drip.param.valuation.ValuationCustomizationParams vcp,
  213.         final org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double> mapBaseMeasures,
  214.         final ComponentCurve compCurve)
  215.     {
  216.         if (null == mapTenorUpCSQS || 0 == mapTenorUpCSQS.size()) return null;

  217.         java.util.Set<java.util.Map.Entry<java.lang.String, org.drip.param.market.CurveSurfaceQuoteContainer>>
  218.             mapESTenorUpCSQS = mapTenorUpCSQS.entrySet();

  219.         if (null == mapESTenorUpCSQS || 0 == mapESTenorUpCSQS.size()) return null;

  220.         org.drip.analytics.support.CaseInsensitiveTreeMap<FlatDeltaGammaMeasureMap> mapTenorDGMM = new
  221.             org.drip.analytics.support.CaseInsensitiveTreeMap<FlatDeltaGammaMeasureMap>();

  222.         for (java.util.Map.Entry<java.lang.String, org.drip.param.market.CurveSurfaceQuoteContainer> meTenorUpCSQS
  223.             : mapESTenorUpCSQS) {
  224.             if (null == meTenorUpCSQS) continue;

  225.             java.lang.String strTenorKey = meTenorUpCSQS.getKey();

  226.             if (null == strTenorKey || strTenorKey.isEmpty()) continue;

  227.             org.drip.param.market.CurveSurfaceQuoteContainer csqsTenorUp = meTenorUpCSQS.getValue();

  228.             org.drip.param.market.CurveSurfaceQuoteContainer csqsTenorDown = mapTenorDownCSQS.get (strTenorKey);

  229.             org.drip.state.credit.CreditCurve ccVirginUp = null;
  230.             org.drip.state.credit.CreditCurve ccVirginDown = null;

  231.             if (null != csqsTenorUp && null != compCurve && null != compCurve._cc && null !=
  232.                 compCurve._strName && !compCurve._strName.isEmpty()) {
  233.                 ccVirginUp = csqsTenorUp.creditState (org.drip.state.identifier.EntityCDSLabel.Standard
  234.                     (compCurve._strName, couponCurrency()[0]));

  235.                 csqsTenorUp.setCreditState (compCurve._cc);

  236.                 if (null != csqsTenorDown) {
  237.                     ccVirginDown = csqsTenorDown.creditState (org.drip.state.identifier.EntityCDSLabel.Standard
  238.                         (compCurve._strName, couponCurrency()[0]));

  239.                     csqsTenorDown.setCreditState (compCurve._cc);
  240.                 }
  241.             }

  242.             mapTenorDGMM.put (strTenorKey, accumulateDeltaGammaMeasures (valParams, pricerParams,
  243.                 csqsTenorUp, csqsTenorDown, vcp, mapBaseMeasures));

  244.             if (null != csqsTenorUp && null != compCurve && null != compCurve._strName &&
  245.                 !compCurve._strName.isEmpty() && null != ccVirginUp)
  246.                 csqsTenorUp.setCreditState (ccVirginUp);

  247.             if (null != csqsTenorDown && null != compCurve && null != compCurve._strName &&
  248.                 !compCurve._strName.isEmpty() && null != ccVirginDown)
  249.                 csqsTenorDown.setCreditState (ccVirginDown);
  250.         }

  251.         if (0 == mapTenorDGMM.size()) return null;

  252.         org.drip.analytics.support.CaseInsensitiveTreeMap<org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double>>
  253.             mmDelta = new
  254.                 org.drip.analytics.support.CaseInsensitiveTreeMap<org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double>>();

  255.         org.drip.analytics.support.CaseInsensitiveTreeMap<org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double>>
  256.             mmGamma = new
  257.                 org.drip.analytics.support.CaseInsensitiveTreeMap<org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double>>();

  258.         for (java.util.Map.Entry<java.lang.String, FlatDeltaGammaMeasureMap> meTenorDGMM :
  259.             mapTenorDGMM.entrySet()) {
  260.             if (null == meTenorDGMM) continue;

  261.             FlatDeltaGammaMeasureMap dgmmTenorDelta = meTenorDGMM.getValue();

  262.             if (null != dgmmTenorDelta) {
  263.                 java.lang.String strKey = meTenorDGMM.getKey();

  264.                 mmDelta.put (strKey, dgmmTenorDelta._mapDelta);

  265.                 mmGamma.put (strKey, dgmmTenorDelta._mapGamma);
  266.             }
  267.         }

  268.         return new TenorDeltaGammaMeasureMap (mmDelta, mmGamma);
  269.     }

  270.     private ComponentFactorTenorDeltaGammaMeasureMap accumulateComponentWiseTenorDeltaGammaMeasures (
  271.         final org.drip.param.valuation.ValuationParams valParams,
  272.         final org.drip.param.pricer.CreditPricerParams pricerParams,
  273.         final org.drip.analytics.support.CaseInsensitiveTreeMap<org.drip.param.market.CurveSurfaceQuoteContainer>
  274.             mapCSQS,
  275.         final org.drip.analytics.support.CaseInsensitiveTreeMap<org.drip.param.market.CurveSurfaceQuoteContainer>
  276.             mapTenorUpCSQS,
  277.         final org.drip.analytics.support.CaseInsensitiveTreeMap<org.drip.param.market.CurveSurfaceQuoteContainer>
  278.             mapTenorDownCSQS,
  279.         final org.drip.param.valuation.ValuationCustomizationParams vcp,
  280.         final org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double> mapBaseMeasures)
  281.     {
  282.         if (null == mapCSQS || 0 == mapCSQS.size()) return null;

  283.         java.util.Set<java.util.Map.Entry<java.lang.String, org.drip.param.market.CurveSurfaceQuoteContainer>>
  284.             mapESCSQS = mapCSQS.entrySet();

  285.         if (null == mapESCSQS || 0 == mapESCSQS.size()) return null;

  286.         org.drip.analytics.support.CaseInsensitiveTreeMap<TenorDeltaGammaMeasureMap> mapComponentTenorDGMM =
  287.             new org.drip.analytics.support.CaseInsensitiveTreeMap<TenorDeltaGammaMeasureMap>();

  288.         for (java.util.Map.Entry<java.lang.String, org.drip.param.market.CurveSurfaceQuoteContainer> meCSQS :
  289.             mapESCSQS) {
  290.             if (null == meCSQS) continue;

  291.             java.lang.String strComponentName = meCSQS.getKey();

  292.             if (null == strComponentName || strComponentName.isEmpty()) continue;

  293.             org.drip.param.market.CurveSurfaceQuoteContainer csqs = meCSQS.getValue();

  294.             if (null != csqs)
  295.                 mapComponentTenorDGMM.put (strComponentName, accumulateTenorDeltaGammaMeasures (valParams,
  296.                     pricerParams, mapTenorUpCSQS, mapTenorDownCSQS, vcp, mapBaseMeasures, new ComponentCurve
  297.                         (strComponentName, csqs.creditState (org.drip.state.identifier.EntityCDSLabel.Standard
  298.                             (strComponentName, couponCurrency()[0])))));
  299.         }

  300.         if (0 == mapComponentTenorDGMM.size()) return null;

  301.         org.drip.analytics.support.CaseInsensitiveTreeMap<org.drip.analytics.support.CaseInsensitiveTreeMap<org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double>>>
  302.             mmmCompRatesDelta = new
  303.                 org.drip.analytics.support.CaseInsensitiveTreeMap<org.drip.analytics.support.CaseInsensitiveTreeMap<org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double>>>();

  304.         org.drip.analytics.support.CaseInsensitiveTreeMap<org.drip.analytics.support.CaseInsensitiveTreeMap<org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double>>>
  305.             mmmCompRatesGamma = new
  306.                 org.drip.analytics.support.CaseInsensitiveTreeMap<org.drip.analytics.support.CaseInsensitiveTreeMap<org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double>>>();

  307.         for (java.util.Map.Entry<java.lang.String, TenorDeltaGammaMeasureMap> meCompTenorDGMM :
  308.             mapComponentTenorDGMM.entrySet()) {
  309.             if (null == meCompTenorDGMM) continue;

  310.             TenorDeltaGammaMeasureMap dgmmCompTenorDeltaGamma = meCompTenorDGMM.getValue();

  311.             if (null != dgmmCompTenorDeltaGamma) {
  312.                 java.lang.String strKey = meCompTenorDGMM.getKey();

  313.                 mmmCompRatesDelta.put (strKey, dgmmCompTenorDeltaGamma._mmDelta);

  314.                 mmmCompRatesGamma.put (strKey, dgmmCompTenorDeltaGamma._mmGamma);
  315.             }
  316.         }

  317.         return new ComponentFactorTenorDeltaGammaMeasureMap (mmmCompRatesDelta, mmmCompRatesGamma);
  318.     }

  319.     protected double measureValue (
  320.         final java.lang.String strMeasure,
  321.         final org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double> mapCalc)
  322.         throws java.lang.Exception
  323.     {
  324.         if (null == strMeasure || strMeasure.isEmpty() || null == mapCalc || null == mapCalc.entrySet())
  325.             throw new java.lang.Exception ("BasketProduct::measureValue => Invalid Params");

  326.         for (java.util.Map.Entry<java.lang.String, java.lang.Double> me : mapCalc.entrySet()) {
  327.             if (null != me && null != me.getKey() && me.getKey().equalsIgnoreCase (strMeasure))
  328.                 return me.getValue();
  329.         }

  330.         throw new java.lang.Exception ("BasketProduct::getMeasure => " + strMeasure +
  331.             " is an invalid measure!");
  332.     }

  333.     /**
  334.      * Return the basket name
  335.      *
  336.      * @return Name of the basket product
  337.      */

  338.     public abstract java.lang.String name();

  339.     /**
  340.      * Return the Components in the Basket
  341.      *
  342.      * @return Components in the Basket
  343.      */

  344.     public abstract org.drip.product.definition.Component[] components();

  345.     /**
  346.      * Retrieve the Aggregation Type for the specified Measure
  347.      *
  348.      * @param strMeasureName The Specified Measure Name
  349.      *
  350.      * @return The Aggregation Type
  351.      */

  352.     public abstract int measureAggregationType (
  353.         final java.lang.String strMeasureName);

  354.     /**
  355.      * Retrieve the component Weights
  356.      *
  357.      * @return Array Containing the Component Weights
  358.      */

  359.     public double[] weights()
  360.     {
  361.         org.drip.product.definition.Component[] aComp = components();

  362.         double dblTotalWeight = 0.;
  363.         int iNumComp = aComp.length;
  364.         double[] adblWeight = new double[iNumComp];

  365.         for (int i = 0; i < iNumComp; ++i) {
  366.             try {
  367.                 dblTotalWeight += (adblWeight[i] = aComp[i].initialNotional());
  368.             } catch (java.lang.Exception e) {
  369.                 e.printStackTrace();

  370.                 return null;
  371.             }
  372.         }

  373.         if (0. == dblTotalWeight) return null;

  374.         for (int i = 0; i < iNumComp; ++i)
  375.             adblWeight[i] /= dblTotalWeight;

  376.         return adblWeight;
  377.     }

  378.     @Override public java.lang.String[] couponCurrency()
  379.     {
  380.         org.drip.product.definition.Component[] aComp = components();

  381.         if (null == aComp) return null;

  382.         int iNumComp = aComp.length;

  383.         if (0 == iNumComp) return null;

  384.         java.util.Set<java.lang.String> setCouponCurrency = new java.util.HashSet<java.lang.String>();

  385.         for (int i = 0; i < iNumComp; ++i) {
  386.             if (null == aComp[i]) return null;

  387.             org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.String> mapComponentCouponCurrency =
  388.                 aComp[i].couponCurrency();

  389.             if (null != mapComponentCouponCurrency && 0 != mapComponentCouponCurrency.size()) {
  390.                 for (java.util.Map.Entry<java.lang.String, java.lang.String> meCouponCurrency :
  391.                     mapComponentCouponCurrency.entrySet())
  392.                     setCouponCurrency.add (meCouponCurrency.getValue());
  393.             }
  394.         }

  395.         int iNumCouponCurrency = setCouponCurrency.size();

  396.         if (0 == iNumCouponCurrency) return null;

  397.         int i = 0;
  398.         java.lang.String[] astrCouponCurrency = new java.lang.String[iNumCouponCurrency];

  399.         for (java.lang.String strCouponCurrency : astrCouponCurrency)
  400.             astrCouponCurrency[i++] = strCouponCurrency;

  401.         return astrCouponCurrency;
  402.     }

  403.     @Override public java.lang.String[] payCurrency()
  404.     {
  405.         org.drip.product.definition.Component[] aComp = components();

  406.         if (null == aComp) return null;

  407.         int iNumComp = aComp.length;

  408.         if (0 == iNumComp) return null;

  409.         java.util.Set<java.lang.String> setPayCurrency = new java.util.HashSet<java.lang.String>();

  410.         for (int i = 0; i < iNumComp; ++i) {
  411.             if (null == aComp[i]) return null;

  412.             setPayCurrency.add (aComp[i].payCurrency());
  413.         }

  414.         int iNumPayCurrency = setPayCurrency.size();

  415.         if (0 == iNumPayCurrency) return null;

  416.         int i = 0;
  417.         java.lang.String[] astrPayCurrency = new java.lang.String[iNumPayCurrency];

  418.         for (java.lang.String strPayCurrency : astrPayCurrency)
  419.             astrPayCurrency[i++] = strPayCurrency;

  420.         return astrPayCurrency;
  421.     }

  422.     @Override public java.lang.String[] principalCurrency()
  423.     {
  424.         org.drip.product.definition.Component[] aComp = components();

  425.         if (null == aComp) return null;

  426.         int iNumComp = aComp.length;

  427.         if (0 == iNumComp) return null;

  428.         java.util.Set<java.lang.String> setPrincipalCurrency = new java.util.HashSet<java.lang.String>();

  429.         for (int i = 0; i < iNumComp; ++i) {
  430.             if (null == aComp[i]) return null;

  431.             setPrincipalCurrency.add (aComp[i].principalCurrency());
  432.         }

  433.         int iNumPrincipalCurrency = setPrincipalCurrency.size();

  434.         if (0 == iNumPrincipalCurrency) return null;

  435.         int i = 0;
  436.         java.lang.String[] astrPrincipalCurrency = new java.lang.String[iNumPrincipalCurrency];

  437.         for (java.lang.String strPrincipalCurrency : astrPrincipalCurrency)
  438.             astrPrincipalCurrency[i++] = strPrincipalCurrency;

  439.         return astrPrincipalCurrency;
  440.     }

  441.     @Override public org.drip.state.identifier.EntityCDSLabel[] creditLabel()
  442.     {
  443.         org.drip.product.definition.Component[] aComp = components();

  444.         if (null == aComp) return null;

  445.         int iNumComp = aComp.length;

  446.         if (0 == iNumComp) return null;

  447.         java.util.Set<org.drip.state.identifier.EntityCDSLabel> sLSLCredit = new
  448.             java.util.HashSet<org.drip.state.identifier.EntityCDSLabel>();

  449.         for (int i = 0; i < iNumComp; ++i) {
  450.             if (null == aComp[i]) return null;

  451.             org.drip.state.identifier.EntityCDSLabel lslCredit = aComp[i].creditLabel();

  452.             if (null != lslCredit) sLSLCredit.add (lslCredit);
  453.         }

  454.         int iNumCreditCurve = sLSLCredit.size();

  455.         if (0 == iNumCreditCurve) return null;

  456.         int i = 0;
  457.         org.drip.state.identifier.EntityCDSLabel[] aLSLCredit = new
  458.             org.drip.state.identifier.EntityCDSLabel[iNumCreditCurve];

  459.         for (org.drip.state.identifier.EntityCDSLabel lslCredit : sLSLCredit)
  460.             aLSLCredit[i++] = lslCredit;

  461.         return aLSLCredit;
  462.     }

  463.     @Override public org.drip.state.identifier.ForwardLabel[] forwardLabel()
  464.     {
  465.         org.drip.product.definition.Component[] aComp = components();

  466.         if (null == aComp) return null;

  467.         int iNumComp = aComp.length;

  468.         if (0 == iNumComp) return null;

  469.         java.util.Set<org.drip.state.identifier.ForwardLabel> setLSLForward = new
  470.             java.util.HashSet<org.drip.state.identifier.ForwardLabel>();

  471.         for (int i = 0; i < iNumComp; ++i) {
  472.             if (null == aComp[i]) return null;

  473.             org.drip.analytics.support.CaseInsensitiveTreeMap<org.drip.state.identifier.ForwardLabel>
  474.                 aLSLForward = aComp[i].forwardLabel();

  475.             if (null == aLSLForward) continue;

  476.             int iNumForwardCurve = aLSLForward.size();

  477.             if (0 == iNumForwardCurve) continue;

  478.             java.util.Set<java.lang.String> forwardLabelSet = aLSLForward.keySet();

  479.             for (java.lang.String forwardLabelKey : forwardLabelSet) {
  480.                 org.drip.state.identifier.ForwardLabel lslForward = aLSLForward.get (forwardLabelKey);

  481.                 if (null != lslForward) setLSLForward.add (lslForward);
  482.             }
  483.         }

  484.         int iNumForward = setLSLForward.size();

  485.         if (0 == iNumForward) return null;

  486.         int i = 0;
  487.         org.drip.state.identifier.ForwardLabel[] aLSLForward = new
  488.             org.drip.state.identifier.ForwardLabel[iNumForward];

  489.         for (org.drip.state.identifier.ForwardLabel lslForward : setLSLForward)
  490.             aLSLForward[i++] = lslForward;

  491.         return aLSLForward;
  492.     }

  493.     @Override public org.drip.state.identifier.FundingLabel[] fundingLabel()
  494.     {
  495.         org.drip.product.definition.Component[] aComp = components();

  496.         if (null == aComp) return null;

  497.         int iNumComp = aComp.length;

  498.         if (0 == iNumComp) return null;

  499.         java.util.Set<org.drip.state.identifier.FundingLabel> sLSLFunding = new
  500.             java.util.HashSet<org.drip.state.identifier.FundingLabel>();

  501.         for (int i = 0; i < iNumComp; ++i) {
  502.             if (null == aComp[i]) return null;

  503.             org.drip.state.identifier.FundingLabel lslFunding = aComp[i].fundingLabel();

  504.             if (null == lslFunding) continue;

  505.             sLSLFunding.add (lslFunding);
  506.         }

  507.         int iNumFundingCurve = sLSLFunding.size();

  508.         if (0 == iNumFundingCurve) return null;

  509.         int i = 0;
  510.         org.drip.state.identifier.FundingLabel[] aLSLFunding = new
  511.             org.drip.state.identifier.FundingLabel[iNumFundingCurve];

  512.         for (org.drip.state.identifier.FundingLabel lslFunding : sLSLFunding)
  513.             aLSLFunding[i++] = lslFunding;

  514.         return aLSLFunding;
  515.     }

  516.     @Override public org.drip.state.identifier.FXLabel[] fxLabel()
  517.     {
  518.         org.drip.product.definition.Component[] aComp = components();

  519.         if (null == aComp) return null;

  520.         int iNumComp = aComp.length;

  521.         if (0 == iNumComp) return null;

  522.         java.util.Set<org.drip.state.identifier.FXLabel> setLabel = new
  523.             java.util.HashSet<org.drip.state.identifier.FXLabel>();

  524.         for (int i = 0; i < iNumComp; ++i) {
  525.             if (null == aComp[i]) return null;

  526.             org.drip.analytics.support.CaseInsensitiveTreeMap<org.drip.state.identifier.FXLabel> aLabel =
  527.                 aComp[i].fxLabel();

  528.             if (null == aLabel) continue;

  529.             int iNumLabel = aLabel.size();

  530.             if (0 == iNumLabel) continue;

  531.             java.util.Set<java.lang.String> fxLabelSet = aLabel.keySet();

  532.             for (java.lang.String fxLabelKey : fxLabelSet) {
  533.                 org.drip.state.identifier.FXLabel label = aLabel.get (fxLabelKey);

  534.                 if (null != label) setLabel.add (label);
  535.             }
  536.         }

  537.         int iNumLabel = setLabel.size();

  538.         if (0 == iNumLabel) return null;

  539.         int i = 0;
  540.         org.drip.state.identifier.FXLabel[] aLabel = new org.drip.state.identifier.FXLabel[iNumLabel];

  541.         for (org.drip.state.identifier.FXLabel label : setLabel)
  542.             aLabel[i++] = label;

  543.         return aLabel;
  544.     }

  545.     /**
  546.      * Return the initial notional of the basket product
  547.      *
  548.      * @return Initial notional of the basket product
  549.      *
  550.      * @throws java.lang.Exception Thrown if inputs are invalid
  551.      */

  552.     public double initialNotional()
  553.         throws java.lang.Exception
  554.     {
  555.         org.drip.product.definition.Component[] aComp = components();

  556.         int iNumComp = aComp.length;
  557.         double dblInitialNotional = 0.;

  558.         for (int i = 0; i < iNumComp; ++i)
  559.             dblInitialNotional += aComp[i].initialNotional();

  560.         return dblInitialNotional;
  561.     }

  562.     /**
  563.      * Retrieve the notional at the given date
  564.      *
  565.      * @param iDate JulianDate
  566.      *
  567.      * @return Notional
  568.      *
  569.      * @throws java.lang.Exception Thrown if inputs are invalid
  570.      */

  571.     public double notional (
  572.         final int iDate)
  573.         throws java.lang.Exception
  574.     {
  575.         org.drip.product.definition.Component[] aComp = components();

  576.         double dblNotional = 0.;
  577.         int iNumComp = aComp.length;

  578.         for (int i = 0; i < iNumComp; ++i)
  579.             dblNotional += aComp[i].notional (iDate);

  580.         return dblNotional;
  581.     }

  582.     /**
  583.      * Retrieve the time-weighted notional between 2 given dates
  584.      *
  585.      * @param iDate1 JulianDate first
  586.      * @param iDate2 JulianDate second
  587.      *
  588.      * @return Notional
  589.      *
  590.      * @throws java.lang.Exception Thrown if inputs are invalid
  591.      */

  592.     public double notional (
  593.         final int iDate1,
  594.         final int iDate2)
  595.         throws java.lang.Exception
  596.     {
  597.         org.drip.product.definition.Component[] aComp = components();

  598.         double dblNotional = 0.;
  599.         int iNumComp = aComp.length;

  600.         for (int i = 0; i < iNumComp; ++i)
  601.             dblNotional += aComp[i].notional (iDate1, iDate2);

  602.         return dblNotional;
  603.     }

  604.     /**
  605.      * Retrieve the basket product's coupon amount at the given date
  606.      *
  607.      * @param iDate JulianDate
  608.      * @param csqs Market Parameters
  609.      *
  610.      * @return Coupon Amount
  611.      *
  612.      * @throws java.lang.Exception Thrown if coupon cannot be calculated
  613.      */

  614.     public double coupon (
  615.         final int iDate,
  616.         final org.drip.param.market.CurveSurfaceQuoteContainer csqs)
  617.         throws java.lang.Exception
  618.     {
  619.         double dblNotional = notional (iDate);

  620.         if (null == csqs || 0. == dblNotional || !org.drip.numerical.common.NumberUtil.IsValid (dblNotional))
  621.             throw new java.lang.Exception ("BasketProduct::coupon => Cannot extract basket notional");

  622.         org.drip.product.definition.Component[] aComp = components();

  623.         double dblCoupon = 0.;
  624.         int iNumComp = aComp.length;

  625.         for (int i = 0; i < iNumComp; ++i)
  626.             dblCoupon += aComp[i].couponMetrics (iDate, null, csqs).rate();

  627.         return dblCoupon / dblNotional;
  628.     }

  629.     /**
  630.      * Returns the effective date of the basket product
  631.      *
  632.      * @return Effective date of the basket product
  633.      */

  634.     public org.drip.analytics.date.JulianDate effective()
  635.     {
  636.         org.drip.product.definition.Component[] aComp = components();

  637.         int iNumComp = aComp.length;

  638.         org.drip.analytics.date.JulianDate dtEffective = aComp[0].effectiveDate();

  639.         for (int i = 1; i < iNumComp; ++i) {
  640.             org.drip.analytics.date.JulianDate dtCompEffective = aComp[i].effectiveDate();

  641.             if (dtCompEffective.julian() < dtEffective.julian()) dtEffective = dtCompEffective;
  642.         }

  643.         return dtEffective;
  644.     }

  645.     /**
  646.      * Return the maturity date of the basket product
  647.      *
  648.      * @return Maturity date of the basket product
  649.      */

  650.     public org.drip.analytics.date.JulianDate maturity()
  651.     {
  652.         org.drip.product.definition.Component[] aComp = components();

  653.         int iNumComp = aComp.length;

  654.         org.drip.analytics.date.JulianDate dtMaturity = aComp[0].maturityDate();

  655.         for (int i = 1; i < iNumComp; ++i) {
  656.             org.drip.analytics.date.JulianDate dtCompMaturity = aComp[i].maturityDate();

  657.             if (dtCompMaturity.julian() < dtMaturity.julian()) dtMaturity = dtCompMaturity;
  658.         }

  659.         return dtMaturity;
  660.     }

  661.     /**
  662.      * Get the basket product's coupon periods
  663.      *
  664.      * @return List of CouponPeriods
  665.      */

  666.     public java.util.List<org.drip.analytics.cashflow.CompositePeriod> couponPeriod()
  667.     {
  668.         java.util.Set<org.drip.analytics.cashflow.CompositePeriod> setPeriod =
  669.             org.drip.analytics.support.Helper.AggregateComponentPeriods (components());

  670.         if (null == setPeriod || 0 == setPeriod.size()) return null;

  671.         java.util.List<org.drip.analytics.cashflow.CompositePeriod> lsCouponPeriod = new
  672.             java.util.ArrayList<org.drip.analytics.cashflow.CompositePeriod>();

  673.         for (org.drip.analytics.cashflow.CompositePeriod p : setPeriod) {
  674.             if (null != p) lsCouponPeriod.add (p);
  675.         }

  676.         return lsCouponPeriod;
  677.     }

  678.     /**
  679.      * Get the first coupon date
  680.      *
  681.      * @return First Coupon Date
  682.      */

  683.     public org.drip.analytics.date.JulianDate firstCouponDate()
  684.     {
  685.         org.drip.product.definition.Component[] aComp = components();

  686.         int iNumComp = aComp.length;

  687.         org.drip.analytics.date.JulianDate dtFirstCoupon = aComp[0].firstCouponDate();

  688.         for (int i = 1; i < iNumComp; ++i) {
  689.             if (dtFirstCoupon.julian() > aComp[i].firstCouponDate().julian())
  690.                 dtFirstCoupon = aComp[i].firstCouponDate();
  691.         }

  692.         return dtFirstCoupon;
  693.     }

  694.     /**
  695.      * Generate a full list of the basket product measures for the full input set of market parameters
  696.      *
  697.      * @param valParams ValuationParams
  698.      * @param pricerParams PricerParams
  699.      * @param csqs Market Parameters
  700.      * @param vcp Valuation Customization Parameters
  701.      *
  702.      * @return Map of measure name and value
  703.      */

  704.     public org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double> value (
  705.         final org.drip.param.valuation.ValuationParams valParams,
  706.         final org.drip.param.pricer.CreditPricerParams pricerParams,
  707.         final org.drip.param.market.CurveSurfaceQuoteContainer csqs,
  708.         final org.drip.param.valuation.ValuationCustomizationParams vcp)
  709.     {
  710.         long lStart = System.nanoTime();

  711.         org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double> mapBasketOP = new
  712.             org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double>();

  713.         org.drip.product.definition.Component[] aComp = components();

  714.         double[] adblWeight = weights();

  715.         int iNumComp = aComp.length;

  716.         for (int i = 0; i < iNumComp; ++i) {
  717.             org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double> mapCompOP = aComp[i].value
  718.                 (valParams, pricerParams, csqs, vcp);

  719.             if (null == mapCompOP || 0 == mapCompOP.size()) continue;

  720.             java.util.Set<java.util.Map.Entry<java.lang.String, java.lang.Double>> mapCompOPES =
  721.                 mapCompOP.entrySet();

  722.             if (null == mapCompOPES) continue;

  723.             for (java.util.Map.Entry<java.lang.String, java.lang.Double> meCompOP : mapCompOPES) {
  724.                 if (null == meCompOP) continue;

  725.                 java.lang.String strKey = meCompOP.getKey();

  726.                 if (null == strKey || strKey.isEmpty()) continue;

  727.                 java.lang.Double dblCompValue = mapCompOP.get (strKey);

  728.                 java.lang.Double dblBasketValue = mapBasketOP.get (strKey);

  729.                 if (MEASURE_AGGREGATION_TYPE_CUMULATIVE == measureAggregationType (strKey))
  730.                     mapBasketOP.put (strKey, (null == dblCompValue ? 0. : dblCompValue) + (null ==
  731.                         dblBasketValue ? 0. : dblBasketValue));
  732.                 else if (MEASURE_AGGREGATION_TYPE_WEIGHTED_CUMULATIVE == measureAggregationType (strKey) &&
  733.                     null != adblWeight)
  734.                     mapBasketOP.put (strKey, (null == dblCompValue ? 0. : adblWeight[i] * dblCompValue) +
  735.                         (null == dblBasketValue ? 0. : dblBasketValue));
  736.                 else if (MEASURE_AGGREGATION_TYPE_UNIT_ACCUMULATE == measureAggregationType (strKey))
  737.                     mapBasketOP.put (aComp[i].name() + "[" + strKey + "]", (null == dblCompValue ? 0. :
  738.                         dblCompValue));
  739.             }
  740.         }

  741.         mapBasketOP.put ("CalcTime", (System.nanoTime() - lStart) * 1.e-09);

  742.         return mapBasketOP;
  743.     }

  744.     /**
  745.      * Calculate the value of the given basket product measure
  746.      *
  747.      * @param valParams ValuationParams
  748.      * @param pricerParams PricerParams
  749.      * @param csqs Market Parameters
  750.      * @param vcp Valuation Customization Parameters
  751.      * @param strMeasure Measure String
  752.      *
  753.      * @return Double measure value
  754.      *
  755.      * @throws java.lang.Exception Thrown if the measure cannot be calculated
  756.      */

  757.     public double measureValue (
  758.         final org.drip.param.valuation.ValuationParams valParams,
  759.         final org.drip.param.pricer.CreditPricerParams pricerParams,
  760.         final org.drip.param.market.CurveSurfaceQuoteContainer csqs,
  761.         final org.drip.param.valuation.ValuationCustomizationParams vcp,
  762.         final java.lang.String strMeasure)
  763.         throws java.lang.Exception
  764.     {
  765.         return measureValue (strMeasure, value (valParams, pricerParams, csqs, vcp));
  766.     }

  767.     /**
  768.      * Generate a full list of the basket product measures for the set of scenario market parameters present
  769.      *  in the org.drip.param.definition.MarketParams
  770.      *
  771.      * @param valParams ValuationParams
  772.      * @param pricerParams PricerParams
  773.      * @param mpc org.drip.param.definition.MarketParams
  774.      * @param vcp Valuation Customization Parameters
  775.      *
  776.      * @return BasketOutput object
  777.      */

  778.     public org.drip.analytics.output.BasketMeasures measures (
  779.         final org.drip.param.valuation.ValuationParams valParams,
  780.         final org.drip.param.pricer.CreditPricerParams pricerParams,
  781.         final org.drip.param.definition.ScenarioMarketParams mpc,
  782.         final org.drip.param.valuation.ValuationCustomizationParams vcp)
  783.     {
  784.         if (null == valParams || null == mpc) return null;

  785.         long lStart = System.nanoTime();

  786.         org.drip.analytics.output.BasketMeasures bkop = new org.drip.analytics.output.BasketMeasures();

  787.         if (!bkop.setBaseMeasures (value (valParams, pricerParams, mpc.scenarioMarketParams (this, "Base"),
  788.             vcp)))
  789.             return null;

  790.         FlatDeltaGammaMeasureMap dgmmCredit = accumulateDeltaGammaMeasures (valParams, pricerParams,
  791.             mpc.scenarioMarketParams (this, "FlatCreditBumpUp"), mpc.scenarioMarketParams (this, "FlatCreditBumpDn"),
  792.                 vcp, bkop.baseMeasures());

  793.         if (null != dgmmCredit && !bkop.setFlatCreditDeltaMeasures (dgmmCredit._mapDelta))
  794.             bkop.setFlatCreditGammaMeasures (dgmmCredit._mapGamma);

  795.         FlatDeltaGammaMeasureMap dgmmRates = accumulateDeltaGammaMeasures (valParams, pricerParams,
  796.             mpc.scenarioMarketParams (this, "FlatIRBumpUp"), mpc.scenarioMarketParams (this, "FlatIRBumpDn"), vcp,
  797.                 bkop.baseMeasures());

  798.         if (null != dgmmRates && bkop.setFlatIRDeltaMeasures (dgmmRates._mapDelta))
  799.             bkop.setFlatIRGammaMeasures (dgmmRates._mapGamma);

  800.         FlatDeltaGammaMeasureMap dgmmRecovery = accumulateDeltaGammaMeasures (valParams, pricerParams,
  801.             mpc.scenarioMarketParams (this, "FlatRRBumpUp"), mpc.scenarioMarketParams (this, "FlatRRBumpDn"), vcp,
  802.                 bkop.baseMeasures());

  803.         if (null != dgmmRecovery && bkop.setFlatRRDeltaMeasures (dgmmRates._mapDelta))
  804.             bkop.setFlatRRGammaMeasures (dgmmRates._mapGamma);

  805.         org.drip.analytics.support.CaseInsensitiveTreeMap<org.drip.param.market.CurveSurfaceQuoteContainer>
  806.             mapCSQSIRTenorUp = mpc.fundingFlatBump (this, true);

  807.         org.drip.analytics.support.CaseInsensitiveTreeMap<org.drip.param.market.CurveSurfaceQuoteContainer>
  808.             mapCSQSIRTenorDown = mpc.fundingFlatBump (this, false);

  809.         TenorDeltaGammaMeasureMap mapDGMMRatesTenor = accumulateTenorDeltaGammaMeasures (valParams,
  810.             pricerParams, mapCSQSIRTenorUp, mapCSQSIRTenorDown, vcp, bkop.baseMeasures(), null);

  811.         if (null != mapDGMMRatesTenor) {
  812.             bkop.setComponentIRDeltaMeasures (mapDGMMRatesTenor._mmDelta);

  813.             bkop.setComponentIRGammaMeasures (mapDGMMRatesTenor._mmGamma);
  814.         }

  815.         org.drip.analytics.support.CaseInsensitiveTreeMap<org.drip.param.market.CurveSurfaceQuoteContainer>
  816.             mapCSQSCreditTenorUp = mpc.creditFlatBump (this, true);

  817.         org.drip.analytics.support.CaseInsensitiveTreeMap<org.drip.param.market.CurveSurfaceQuoteContainer>
  818.             mapCSQSCreditTenorDown = mpc.creditFlatBump (this, false);

  819.         TenorDeltaGammaMeasureMap mapDGMMCreditComp = accumulateTenorDeltaGammaMeasures (valParams,
  820.             pricerParams, mapCSQSCreditTenorUp, mapCSQSCreditTenorDown, vcp, bkop.baseMeasures(), null);

  821.         if (null != mapDGMMCreditComp) {
  822.             bkop.setComponentCreditDeltaMeasures (mapDGMMCreditComp._mmDelta);

  823.             bkop.setComponentCreditGammaMeasures (mapDGMMCreditComp._mmGamma);
  824.         }

  825.         TenorDeltaGammaMeasureMap mapDGMMRecoveryTenor = accumulateTenorDeltaGammaMeasures (valParams,
  826.             pricerParams, mpc.recoveryFlatBump (this, true), mpc.recoveryFlatBump (this, false), vcp,
  827.                 bkop.baseMeasures(), null);

  828.         if (null != mapDGMMRecoveryTenor) {
  829.             bkop.setComponentRRDeltaMeasures (mapDGMMRecoveryTenor._mmDelta);

  830.             bkop.setComponentRRGammaMeasures (mapDGMMRecoveryTenor._mmGamma);
  831.         }

  832.         ComponentFactorTenorDeltaGammaMeasureMap mapCompRatesTenorDGMM =
  833.             accumulateComponentWiseTenorDeltaGammaMeasures (valParams, pricerParams, mapCSQSCreditTenorUp,
  834.                 mapCSQSIRTenorUp, mapCSQSIRTenorDown, vcp, bkop.baseMeasures());

  835.         if (null != mapCompRatesTenorDGMM) {
  836.             bkop.setComponentTenorIRDeltaMeasures (mapCompRatesTenorDGMM._mmmDelta);

  837.             bkop.setComponentTenorIRGammaMeasures (mapCompRatesTenorDGMM._mmmGamma);
  838.         }

  839.         ComponentFactorTenorDeltaGammaMeasureMap mapCompCreditTenorDGMM =
  840.             accumulateComponentWiseTenorDeltaGammaMeasures (valParams, pricerParams, mapCSQSCreditTenorUp,
  841.                 mapCSQSCreditTenorUp, mapCSQSCreditTenorDown, vcp, bkop.baseMeasures());

  842.         if (null != mapCompCreditTenorDGMM) {
  843.             bkop.setComponentTenorCreditDeltaMeasures (mapCompCreditTenorDGMM._mmmDelta);

  844.             bkop.setComponentTenorCreditGammaMeasures (mapCompCreditTenorDGMM._mmmGamma);
  845.         }

  846.         bkop.setCalcTime ((System.nanoTime() - lStart) * 1.e-09);

  847.         return bkop;
  848.     }

  849.     /**
  850.      * Compute Basket's Custom Scenario Measures
  851.      *
  852.      * @param valParams Valuation Parameters
  853.      * @param pricerParams Pricer Parameters
  854.      * @param mpc Market Parameters Container
  855.      * @param strCustomScenName Custom Scenario Name
  856.      * @param vcp Valuation Customization Parameters
  857.      * @param mapBase Map of Base Measures
  858.      *
  859.      * @return Basket's Custom Scenario Measures
  860.      */

  861.     public org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double> customScenarioMeasures (
  862.         final org.drip.param.valuation.ValuationParams valParams,
  863.         final org.drip.param.pricer.CreditPricerParams pricerParams,
  864.         final org.drip.param.definition.ScenarioMarketParams mpc,
  865.         final java.lang.String strCustomScenName,
  866.         final org.drip.param.valuation.ValuationCustomizationParams vcp,
  867.         org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double> mapBase)
  868.     {
  869.         if (null == valParams || null == mpc) return null;

  870.         if (null == mapBase) {
  871.             org.drip.param.market.CurveSurfaceQuoteContainer csqsBase = mpc.scenarioMarketParams (this, "Base");

  872.             if (null == csqsBase || null == (mapBase = value (valParams, pricerParams, csqsBase, vcp)))
  873.                 return null;
  874.         }

  875.         org.drip.param.market.CurveSurfaceQuoteContainer csqsScen = mpc.scenarioMarketParams (this, strCustomScenName);

  876.         if (null == csqsScen) return null;

  877.         org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double> mapScenMeasures = value
  878.             (valParams, pricerParams, csqsScen, vcp);

  879.         if (null == mapScenMeasures || null != mapScenMeasures.entrySet()) return null;

  880.         org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double> mapOP = new
  881.             org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double>();

  882.         for (java.util.Map.Entry<java.lang.String, java.lang.Double> me : mapScenMeasures.entrySet()) {
  883.             if (null == me || null == me.getKey()) continue;

  884.             mapOP.put (me.getKey(), me.getValue() - mapBase.get (me.getKey()));
  885.         }

  886.         return mapOP;
  887.     }
  888. }