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

  79. /**
  80.  * <i>LatentStateShapePreservingCCIS</i> contains the Parameters needed for the Curve Calibration/Estimation.
  81.  * It contains the following:
  82.  *
  83.  *  <br><br>
  84.  *  <ul>
  85.  *      <li>
  86.  *          Calibration Valuation Parameters
  87.  *      </li>
  88.  *      <li>
  89.  *          Calibration Quoting Parameters
  90.  *      </li>
  91.  *      <li>
  92.  *          Calibration Market Parameters
  93.  *      </li>
  94.  *      <li>
  95.  *          Calibration Pricing Parameters
  96.  *      </li>
  97.  *      <li>
  98.  *          Array of Calibration Span Representation
  99.  *      </li>
  100.  *      <li>
  101.  *          Map of Calibration Quotes
  102.  *      </li>
  103.  *      <li>
  104.  *          Map of Calibration Measures
  105.  *      </li>
  106.  *      <li>
  107.  *          Double Map of the Date/Index Fixings
  108.  *      </li>
  109.  *      <li>
  110.  *          The Shape Preserving Linear Latent State Calibrator
  111.  *      </li>
  112.  *  </ul>
  113.  *  <br><br>
  114.  *
  115.  * Additional functions provide for retrieval of the above and specific instrument quotes.
  116.  *
  117.  *  <br><br>
  118.  *  <ul>
  119.  *      <li><b>Module </b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/ProductCore.md">Product Core Module</a></li>
  120.  *      <li><b>Library</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/FixedIncomeAnalyticsLibrary.md">Fixed Income Analytics</a></li>
  121.  *      <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>
  122.  *      <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>
  123.  *  </ul>
  124.  *
  125.  * @author Lakshmi Krishnamurthy
  126.  */

  127. public class LatentStateShapePreservingCCIS implements
  128.     org.drip.analytics.input.CurveConstructionInputSet {
  129.     private org.drip.param.valuation.ValuationParams _valParam = null;
  130.     private org.drip.param.pricer.CreditPricerParams _pricerParam = null;
  131.     private org.drip.param.market.CurveSurfaceQuoteContainer _csqs = null;
  132.     private org.drip.param.market.LatentStateFixingsContainer _lsfc = null;
  133.     private org.drip.param.valuation.ValuationCustomizationParams _vcp = null;
  134.     private org.drip.state.inference.LatentStateStretchSpec[] _aStretchSpec = null;
  135.     private org.drip.state.inference.LinearLatentStateCalibrator _llscShapePreserving = null;

  136.     /**
  137.      * LatentStateShapePreservingCCIS constructor
  138.      *
  139.      * @param llscShapePreserving Shape Preserving LinearLatentStateCalibrator instance
  140.      * @param aStretchSpec Array of the Latent State Stretch Representation Specifications
  141.      * @param valParam Valuation Parameters
  142.      * @param pricerParam Pricer Parameters
  143.      * @param vcp Valuation Customization Parameters
  144.      * @param csqs Market Parameters
  145.      *
  146.      * @throws java.lang.Exception Thrown if Inputs are invalid
  147.      */

  148.     public LatentStateShapePreservingCCIS (
  149.         final org.drip.state.inference.LinearLatentStateCalibrator llscShapePreserving,
  150.         final org.drip.state.inference.LatentStateStretchSpec[] aStretchSpec,
  151.         final org.drip.param.valuation.ValuationParams valParam,
  152.         final org.drip.param.pricer.CreditPricerParams pricerParam,
  153.         final org.drip.param.valuation.ValuationCustomizationParams vcp,
  154.         final org.drip.param.market.CurveSurfaceQuoteContainer csqs)
  155.         throws java.lang.Exception
  156.     {
  157.         if (null == (_llscShapePreserving = llscShapePreserving) || null == (_aStretchSpec = aStretchSpec) ||
  158.             null == (_valParam = valParam))
  159.             throw new java.lang.Exception ("LatentStateShapePreservingCCIS ctr: Invalid Inputs");

  160.         _vcp = vcp;
  161.         _csqs = csqs;
  162.         int iNumStretchNULL = 0;
  163.         _pricerParam = pricerParam;
  164.         int iNumStretch = _aStretchSpec.length;

  165.         if (0 == iNumStretch)
  166.             throw new java.lang.Exception ("LatentStateShapePreservingCCIS ctr: Invalid Inputs");

  167.         for (int i = 0; i < iNumStretch; ++i) {
  168.             if (null == _aStretchSpec[i]) ++iNumStretchNULL;
  169.         }

  170.         if (iNumStretchNULL == iNumStretch)
  171.             throw new java.lang.Exception ("LatentStateShapePreservingCCIS ctr: Invalid Inputs");
  172.     }

  173.     @Override public org.drip.param.valuation.ValuationParams valuationParameter()
  174.     {
  175.         return _valParam;
  176.     }

  177.     @Override public org.drip.param.valuation.ValuationCustomizationParams quotingParameter()
  178.     {
  179.         return _vcp;
  180.     }

  181.     @Override public org.drip.product.definition.CalibratableComponent[] components()
  182.     {
  183.         java.util.List<org.drip.product.definition.CalibratableComponent> lsComp = new
  184.             java.util.ArrayList<org.drip.product.definition.CalibratableComponent>();

  185.         for (org.drip.state.inference.LatentStateStretchSpec stretchSpec : _aStretchSpec) {
  186.             if (null == stretchSpec) continue;

  187.             org.drip.state.inference.LatentStateSegmentSpec[] aSegmentSpec = stretchSpec.segmentSpec();

  188.             if (null == aSegmentSpec) continue;

  189.             int iNumComp = aSegmentSpec.length;

  190.             if (0 == iNumComp) continue;

  191.             for (int i = 0; i < iNumComp; ++i) {
  192.                 if (null == aSegmentSpec[i]) continue;

  193.                 org.drip.product.definition.CalibratableComponent comp = aSegmentSpec[i].component();

  194.                 if (null != comp) lsComp.add (comp);
  195.             }
  196.         }

  197.         int iNumComp = lsComp.size();

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

  199.         org.drip.product.definition.CalibratableComponent[] aComp = new
  200.             org.drip.product.definition.CalibratableComponent[iNumComp];

  201.         for (int i = 0; i < iNumComp; ++i)
  202.             aComp[i] = lsComp.get (i);

  203.         return aComp;
  204.     }

  205.     @Override public
  206.         org.drip.analytics.support.CaseInsensitiveTreeMap<org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double>>
  207.             quoteMap()
  208.     {
  209.         org.drip.analytics.support.CaseInsensitiveTreeMap<org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double>>
  210.             mapInstrumentQuote = new
  211.                 org.drip.analytics.support.CaseInsensitiveTreeMap<org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double>>();

  212.         for (org.drip.state.inference.LatentStateStretchSpec stretchSpec : _aStretchSpec) {
  213.             if (null == stretchSpec) continue;

  214.             org.drip.state.inference.LatentStateSegmentSpec[] aSegmentSpec = stretchSpec.segmentSpec();

  215.             for (org.drip.state.inference.LatentStateSegmentSpec segmentSpec : aSegmentSpec) {
  216.                 org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double> mapMeasureQuote = new
  217.                     org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.Double>();

  218.                 org.drip.product.calib.ProductQuoteSet pqs = segmentSpec.manifestMeasures();

  219.                 for (java.lang.String strManifestMeasure : pqs.fields()) {
  220.                     try {
  221.                         mapMeasureQuote.put (strManifestMeasure, pqs.get (strManifestMeasure));
  222.                     } catch (java.lang.Exception e) {
  223.                         e.printStackTrace();
  224.                     }
  225.                 }

  226.                 mapInstrumentQuote.put (segmentSpec.component().primaryCode(), mapMeasureQuote);
  227.             }
  228.         }

  229.         return mapInstrumentQuote;
  230.     }

  231.     @Override public org.drip.analytics.support.CaseInsensitiveTreeMap<java.lang.String[]> measures()
  232.     {
  233.         return null;
  234.     }

  235.     @Override public org.drip.param.market.LatentStateFixingsContainer fixing()
  236.     {
  237.         return _lsfc;
  238.     }

  239.     /**
  240.      * Retrieve the Pricer Parameters
  241.      *
  242.      * @return The Pricer Parameters
  243.      */

  244.     public org.drip.param.pricer.CreditPricerParams pricerParameter()
  245.     {
  246.         return _pricerParam;
  247.     }

  248.     /**
  249.      * Retrieve the Market Parameters
  250.      *
  251.      * @return The Market Parameters
  252.      */

  253.     public org.drip.param.market.CurveSurfaceQuoteContainer marketParameters()
  254.     {
  255.         return _csqs;
  256.     }

  257.     /**
  258.      * Retrieve the Array of Latent State Stretch Representation Specifications
  259.      *
  260.      * @return The Array of Latent State Stretch Representation Specifications
  261.      */

  262.     public org.drip.state.inference.LatentStateStretchSpec[] stretchSpec()
  263.     {
  264.         return _aStretchSpec;
  265.     }

  266.     /**
  267.      * Retrieve the Shape Preserving Linear Latent State Calibrator
  268.      *
  269.      * @return The Shape Preserving Linear Latent State Calibrator
  270.      */

  271.     public org.drip.state.estimator.GlobalControlCurveParams shapePreservingLLSC()
  272.     {
  273.         return _llscShapePreserving;
  274.     }
  275. }