DiscountCurveScenarioContainer.java

  1. package org.drip.param.market;

  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>DiscountCurveScenarioContainer</i> implements the RatesScenarioCurve abstract class that exposes the
  84.  * interface the constructs scenario discount curves. The following curve construction scenarios are
  85.  * supported:
  86.  *
  87.  * <br><br>
  88.  *  <ul>
  89.  *      <li>
  90.  *          Base, flat/tenor up/down by arbitrary bumps
  91.  *      </li>
  92.  *      <li>
  93.  *          Tenor bumped discount curve set - keyed using the tenor
  94.  *      </li>
  95.  *      <li>
  96.  *          NTP-based custom scenario curves
  97.  *      </li>
  98.  *  </ul>
  99.  *
  100.  *  <br><br>
  101.  *  <ul>
  102.  *      <li><b>Module </b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/ProductCore.md">Product Core Module</a></li>
  103.  *      <li><b>Library</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/FixedIncomeAnalyticsLibrary.md">Fixed Income Analytics</a></li>
  104.  *      <li><b>Project</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/param/README.md">Product Cash Flow, Valuation, Market, Pricing, and Quoting Parameters</a></li>
  105.  *      <li><b>Package</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/param/market/README.md">Curves Surfaces Quotes Fixings Container</a></li>
  106.  *  </ul>
  107.  *
  108.  * @author Lakshmi Krishnamurthy
  109.  */

  110. public class DiscountCurveScenarioContainer {

  111.     /**
  112.      * Base Discount Curve
  113.      */

  114.     public static final int DC_BASE = 0;

  115.     /**
  116.      * Discount Curve Parallel Bump Up
  117.      */

  118.     public static final int DC_FLAT_UP = 1;

  119.     /**
  120.      * Discount Curve Parallel Bump Down
  121.      */

  122.     public static final int DC_FLAT_DN = 2;

  123.     /**
  124.      * Discount Curve Tenor Bump Up
  125.      */

  126.     public static final int DC_TENOR_UP = 4;

  127.     /**
  128.      * Discount Curve Tenor Bump Down
  129.      */

  130.     public static final int DC_TENOR_DN = 8;

  131.     private org.drip.state.discount.MergedDiscountForwardCurve _dcBase = null;
  132.     private org.drip.state.discount.MergedDiscountForwardCurve _dcBumpUp = null;
  133.     private org.drip.state.discount.MergedDiscountForwardCurve _dcBumpDn = null;
  134.     private org.drip.product.definition.CalibratableComponent[] _aCalibInst = null;
  135.     private org.drip.analytics.support.CaseInsensitiveTreeMap<org.drip.state.discount.MergedDiscountForwardCurve>
  136.         _mapDCCustom = null;
  137.     private org.drip.analytics.support.CaseInsensitiveTreeMap<org.drip.state.discount.MergedDiscountForwardCurve>
  138.         _mapDCBumpUp = null;
  139.     private org.drip.analytics.support.CaseInsensitiveTreeMap<org.drip.state.discount.MergedDiscountForwardCurve>
  140.         _mapDCBumpDn = null;

  141.     /**
  142.      * Constructs an DiscountCurveScenarioContainer instance from the corresponding
  143.      *  DiscountCurveScenarioGenerator
  144.      *
  145.      * @param aCalibInst Array of calibration instruments
  146.      *
  147.      * @throws java.lang.Exception Thrown if the IRCurveScenarioGenerator instance is invalid
  148.      */

  149.     public DiscountCurveScenarioContainer (
  150.         final org.drip.product.definition.CalibratableComponent[] aCalibInst)
  151.         throws java.lang.Exception
  152.     {
  153.         if (null == (_aCalibInst = aCalibInst) || 0 == _aCalibInst.length)
  154.             throw new java.lang.Exception ("DiscountCurveScenarioContainer ctr => Invalid Inputs");
  155.     }

  156.     /**
  157.      * Generate the set of discount curves from the scenario specified, and the instrument quotes
  158.      *
  159.      * @param valParams Valuation Parameters
  160.      * @param gc The Govvie Curve
  161.      * @param adblCalibQuote Matched array of the calibration instrument quotes
  162.      * @param astrCalibMeasure Matched array of the calibration instrument measures
  163.      * @param dblBump Amount of bump to be applied
  164.      * @param lsfc Latent State Fixings Container
  165.      * @param vcp Valuation Customization Parameters
  166.      * @param iDCMode One of the values in the DC_ enum listed above.
  167.      *
  168.      * @return Success (true), failure (false)
  169.      */

  170.     public boolean cookScenarioDC (
  171.         final org.drip.param.valuation.ValuationParams valParams,
  172.         final org.drip.state.govvie.GovvieCurve gc,
  173.         final double[] adblCalibQuote,
  174.         final java.lang.String[] astrCalibMeasure,
  175.         final double dblBump,
  176.         final org.drip.param.market.LatentStateFixingsContainer lsfc,
  177.         final org.drip.param.valuation.ValuationCustomizationParams vcp,
  178.         final int iDCMode)
  179.     {
  180.         if (null == (_dcBase = org.drip.state.boot.DiscountCurveScenario.Standard (valParams, _aCalibInst,
  181.             adblCalibQuote, astrCalibMeasure, 0., gc, lsfc, vcp)))
  182.             return false;

  183.         if (0 != (org.drip.param.market.DiscountCurveScenarioContainer.DC_FLAT_UP & iDCMode)) {
  184.             if (null == (_dcBumpUp = org.drip.state.boot.DiscountCurveScenario.Standard (valParams,
  185.                 _aCalibInst, adblCalibQuote, astrCalibMeasure, dblBump, gc, lsfc, vcp)))
  186.                 return false;
  187.         }

  188.         if (0 != (org.drip.param.market.DiscountCurveScenarioContainer.DC_FLAT_DN & iDCMode)) {
  189.             if (null == (_dcBumpDn = org.drip.state.boot.DiscountCurveScenario.Standard (valParams,
  190.                 _aCalibInst, adblCalibQuote, astrCalibMeasure, -dblBump, gc, lsfc, vcp)))
  191.                 return false;
  192.         }

  193.         if (0 != (org.drip.param.market.DiscountCurveScenarioContainer.DC_TENOR_UP & iDCMode)) {
  194.             if (null == (_mapDCBumpUp = org.drip.state.boot.DiscountCurveScenario.TenorMap (valParams,
  195.                 _aCalibInst, adblCalibQuote, astrCalibMeasure, dblBump, gc, lsfc, vcp)))
  196.                 return false;
  197.         }

  198.         if (0 != (org.drip.param.market.DiscountCurveScenarioContainer.DC_TENOR_DN & iDCMode)) {
  199.             if (null == (_mapDCBumpDn = org.drip.state.boot.DiscountCurveScenario.TenorMap (valParams,
  200.                 _aCalibInst, adblCalibQuote, astrCalibMeasure, -dblBump, gc, lsfc, vcp)))
  201.                 return false;
  202.         }

  203.         return true;
  204.     }

  205.     /**
  206.      * Return the base Discount Curve
  207.      *
  208.      * @return The base Discount Curve
  209.      */

  210.     public org.drip.state.discount.MergedDiscountForwardCurve base()
  211.     {
  212.         return _dcBase;
  213.     }

  214.     /**
  215.      * Return the Bump Up Discount Curve
  216.      *
  217.      * @return The Bump Up Discount Curve
  218.      */

  219.     public org.drip.state.discount.MergedDiscountForwardCurve bumpUp()
  220.     {
  221.         return _dcBumpUp;
  222.     }

  223.     /**
  224.      * Return the Bump Down Discount Curve
  225.      *
  226.      * @return The Bump Down Discount Curve
  227.      */

  228.     public org.drip.state.discount.MergedDiscountForwardCurve bumpDown()
  229.     {
  230.         return _dcBumpDn;
  231.     }

  232.     /**
  233.      * Return the map of the tenor Bump Up Discount Curve
  234.      *
  235.      * @return The map of the tenor Bump Up Discount Curve
  236.      */

  237.     public org.drip.analytics.support.CaseInsensitiveTreeMap<org.drip.state.discount.MergedDiscountForwardCurve>
  238.         tenorBumpUp()
  239.     {
  240.         return _mapDCBumpUp;
  241.     }

  242.     /**
  243.      * Return the map of the tenor Bump Down Discount Curve
  244.      *
  245.      * @return The map of the tenor Bump Down Discount Curve
  246.      */

  247.     public org.drip.analytics.support.CaseInsensitiveTreeMap<org.drip.state.discount.MergedDiscountForwardCurve>
  248.         tenorBumpDown()
  249.     {
  250.         return _mapDCBumpDn;
  251.     }

  252.     /**
  253.      * Return the Custom Discount curve map
  254.      *
  255.      * @return The Custom Discount curve Map
  256.      */

  257.     public org.drip.analytics.support.CaseInsensitiveTreeMap<org.drip.state.discount.MergedDiscountForwardCurve> custom()
  258.     {
  259.         return _mapDCCustom;
  260.     }
  261. }