BootCurveConstructionInput.java

  1. package org.drip.analytics.input;

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

  80. /**
  81.  * <i>BootCurveConstructionInput</i> contains the Parameters needed for the Curve Calibration/Estimation. It
  82.  * contains the following:
  83.  *
  84.  *  <br><br>
  85.  *  <ul>
  86.  *      <li>
  87.  *          Calibration Valuation Parameters
  88.  *      </li>
  89.  *      <li>
  90.  *          Calibration Quoting Parameters
  91.  *      </li>
  92.  *      <li>
  93.  *          Array of Calibration Instruments
  94.  *      </li>
  95.  *      <li>
  96.  *          Map of Calibration Quotes
  97.  *      </li>
  98.  *      <li>
  99.  *          Map of Calibration Measures
  100.  *      </li>
  101.  *      <li>
  102.  *          Latent State Fixings Container
  103.  *      </li>
  104.  *  </ul>
  105.  *
  106.  *  <br><br>
  107.  *  <ul>
  108.  *      <li><b>Module </b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/ProductCore.md">Product Core Module</a></li>
  109.  *      <li><b>Library</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/FixedIncomeAnalyticsLibrary.md">Fixed Income Analytics</a></li>
  110.  *      <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>
  111.  *      <li><b>Package</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/analytics/input/README.md">Curve Surface Construction Customization Inputs</a></li>
  112.  *  </ul>
  113.  *
  114.  * @author Lakshmi Krishnamurthy
  115.  */

  116. public class BootCurveConstructionInput implements org.drip.analytics.input.CurveConstructionInputSet {
  117.     private org.drip.param.valuation.ValuationParams _valParam = null;
  118.     private org.drip.param.market.LatentStateFixingsContainer _lsfc = null;
  119.     private org.drip.param.valuation.ValuationCustomizationParams _quotingParam = null;
  120.     private org.drip.product.definition.CalibratableComponent[] _aCalibInst = null;
  121.     private org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.String[]> _mapMeasures = null;
  122.     private
  123.         org.drip.analytics.support.CaseInsensitiveTreeMap<org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double>>
  124.             _mapQuote = null;

  125.     /**
  126.      * Create an Instance of BootCurveConstructionInput from the given Calibration Inputs
  127.      *
  128.      * @param valParam Valuation Parameters
  129.      * @param quotingParam Quoting Parameters
  130.      * @param aCalibInst Array of the Calibration Instruments
  131.      * @param adblCalibQuote Array of the Calibration Quotes
  132.      * @param astrCalibMeasure Array of the Calibration Measures
  133.      * @param lsfc Latent State Fixings Container
  134.      *
  135.      * @return Instance of BootCurveConstructionInput
  136.      */

  137.     public static final BootCurveConstructionInput Create (
  138.         final org.drip.param.valuation.ValuationParams valParam,
  139.         final org.drip.param.valuation.ValuationCustomizationParams quotingParam,
  140.         final org.drip.product.definition.CalibratableComponent[] aCalibInst,
  141.         final double[] adblCalibQuote,
  142.         final java.lang.String[] astrCalibMeasure,
  143.         final org.drip.param.market.LatentStateFixingsContainer lsfc)
  144.     {
  145.         if (null == aCalibInst || null == adblCalibQuote || null == astrCalibMeasure) return null;

  146.         int iNumInst = aCalibInst.length;

  147.         if (0 == iNumInst || adblCalibQuote.length != iNumInst || astrCalibMeasure.length != iNumInst)
  148.             return null;

  149.         org.drip.analytics.support.CaseInsensitiveTreeMap<org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double>>
  150.             mapQuote = new
  151.                 org.drip.analytics.support.CaseInsensitiveTreeMap<org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double>>();

  152.         org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.String[]> mapMeasures = new
  153.             org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.String[]>();

  154.         for (int i = 0; i < iNumInst; ++i) {
  155.             if (null == aCalibInst[i]) return null;

  156.             java.lang.String strInstrumentCode = aCalibInst[i].primaryCode();

  157.             if (null == strInstrumentCode || strInstrumentCode.isEmpty() || null == astrCalibMeasure[i] ||
  158.                 astrCalibMeasure[i].isEmpty() || !org.drip.numerical.common.NumberUtil.IsValid
  159.                     (adblCalibQuote[i]))
  160.                 return null;

  161.             org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double> mapCalibManifestMeasureQuote
  162.                 = new org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double>();

  163.             mapCalibManifestMeasureQuote.put (astrCalibMeasure[i], adblCalibQuote[i]);

  164.             mapMeasures.put (strInstrumentCode, new java.lang.String[] {astrCalibMeasure[i]});

  165.             mapQuote.put (strInstrumentCode, mapCalibManifestMeasureQuote);

  166.             java.lang.String[] astrSecCode = aCalibInst[i].secondaryCode();

  167.             if (null != astrSecCode) {
  168.                 int iNumSecCode = astrSecCode.length;

  169.                 for (int j = 0; j < iNumSecCode; ++j) {
  170.                     java.lang.String strSecCode = astrSecCode[j];

  171.                     if (null == strSecCode || strSecCode.isEmpty())
  172.                         mapQuote.put (strSecCode, mapCalibManifestMeasureQuote);
  173.                 }
  174.             }
  175.         }

  176.         try {
  177.             return new BootCurveConstructionInput (valParam, quotingParam, aCalibInst, mapQuote, mapMeasures,
  178.                 lsfc);
  179.         } catch (java.lang.Exception e) {
  180.             e.printStackTrace();
  181.         }

  182.         return null;
  183.     }

  184.     /**
  185.      * BootCurveConstructionInput constructor
  186.      *
  187.      * @param valParam Valuation Parameter
  188.      * @param quotingParam Quoting Parameter
  189.      * @param aCalibInst Array of Calibration Instruments
  190.      * @param mapQuote Map of the Calibration Instrument Quotes
  191.      * @param mapMeasures Map containing the Array of the Calibration Instrument Measures
  192.      * @param lsfc Latent State Fixings Container
  193.      *
  194.      * @throws java.lang.Exception Thrown if Inputs are Invalid
  195.      */

  196.     public BootCurveConstructionInput (
  197.         final org.drip.param.valuation.ValuationParams valParam,
  198.         final org.drip.param.valuation.ValuationCustomizationParams quotingParam,
  199.         final org.drip.product.definition.CalibratableComponent[] aCalibInst,
  200.         final
  201.             org.drip.analytics.support.CaseInsensitiveTreeMap<org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double>>
  202.                 mapQuote,
  203.         final org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.String[]> mapMeasures,
  204.         final org.drip.param.market.LatentStateFixingsContainer lsfc)
  205.         throws java.lang.Exception
  206.     {
  207.         if (null == (_valParam = valParam) || null == (_aCalibInst = aCalibInst) || null == (_mapQuote =
  208.             mapQuote) || null == (_mapMeasures = mapMeasures))
  209.             throw new java.lang.Exception ("BootCurveConstructionInput ctr: Invalid Inputs");

  210.         _lsfc = lsfc;
  211.         _quotingParam = quotingParam;
  212.         int iNumInst = _aCalibInst.length;

  213.         if (0 == iNumInst || iNumInst > _mapQuote.size() || iNumInst > _mapMeasures.size())
  214.             throw new java.lang.Exception ("BootCurveConstructionInput ctr: Invalid Inputs");
  215.     }

  216.     @Override public org.drip.param.valuation.ValuationParams valuationParameter()
  217.     {
  218.         return _valParam;
  219.     }

  220.     @Override public org.drip.param.pricer.CreditPricerParams pricerParameter()
  221.     {
  222.         return null;
  223.     }

  224.     @Override public org.drip.param.market.CurveSurfaceQuoteContainer marketParameters()
  225.     {
  226.         return null;
  227.     }

  228.     @Override public org.drip.param.valuation.ValuationCustomizationParams quotingParameter()
  229.     {
  230.         return _quotingParam;
  231.     }

  232.     @Override public org.drip.product.definition.CalibratableComponent[] components()
  233.     {
  234.         return _aCalibInst;
  235.     }

  236.     @Override public
  237.         org.drip.analytics.support.CaseInsensitiveTreeMap<org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double>>
  238.             quoteMap()
  239.     {
  240.         return _mapQuote;
  241.     }

  242.     @Override public org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.String[]> measures()
  243.     {
  244.         return _mapMeasures;
  245.     }

  246.     @Override public org.drip.param.market.LatentStateFixingsContainer fixing()
  247.     {
  248.         return _lsfc;
  249.     }
  250. }