DiscountCurveScenario.java

  1. package org.drip.state.boot;

  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>DiscountCurveScenario</i> uses the interest rate calibration instruments along with the component
  84.  * calibrator to produce scenario interest rate curves. DiscountCurveScenario typically first constructs the
  85.  * actual curve calibrator instance to localize the intelligence around curve construction. It then uses this
  86.  * curve calibrator instance to build individual curves or the sequence of node bumped scenario curves. The
  87.  * curves in the set may be an array, or tenor-keyed.
  88.  *
  89.  *  <br><br>
  90.  *  <ul>
  91.  *      <li><b>Module </b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/ProductCore.md">Product Core Module</a></li>
  92.  *      <li><b>Library</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/FixedIncomeAnalyticsLibrary.md">Fixed Income Analytics</a></li>
  93.  *      <li><b>Project</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/state/README.md">Latent State Inference and Creation Utilities</a></li>
  94.  *      <li><b>Package</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/state/boot/README.md">Bootable Discount, Credit, Volatility States</a></li>
  95.  *  </ul>
  96.  * <br><br>
  97.  *
  98.  * @author Lakshmi Krishnamurthy
  99.  */

  100. public class DiscountCurveScenario {

  101.     /**
  102.      * Calibrate a discount curve
  103.      *
  104.      * @param valParams ValuationParams
  105.      * @param aCalibInst Array of Calibratable Components
  106.      * @param adblCalibQuote Array of component quotes
  107.      * @param astrCalibMeasure Array of the calibration measures
  108.      * @param dblBump Quote bump
  109.      * @param gc Govvie Curve
  110.      * @param lsfc Latent State Fixings Container
  111.      * @param vcp Valuation Customization Parameters
  112.      *
  113.      * @return DiscountCurve Instance
  114.      */

  115.     public static final org.drip.state.discount.MergedDiscountForwardCurve Standard (
  116.         final org.drip.param.valuation.ValuationParams valParams,
  117.         final org.drip.product.definition.CalibratableComponent[] aCalibInst,
  118.         final double[] adblCalibQuote,
  119.         final java.lang.String[] astrCalibMeasure,
  120.         final double dblBump,
  121.         final org.drip.state.govvie.GovvieCurve gc,
  122.         final org.drip.param.market.LatentStateFixingsContainer lsfc,
  123.         final org.drip.param.valuation.ValuationCustomizationParams vcp)
  124.     {
  125.         if (null == valParams || null == aCalibInst || null == adblCalibQuote || null == astrCalibMeasure)
  126.             return null;

  127.         int iNumComp = aCalibInst.length;
  128.         int aiDate[] = new int[iNumComp];
  129.         double adblRate[] = new double[iNumComp];

  130.         if (0 == iNumComp || adblCalibQuote.length != iNumComp || astrCalibMeasure.length != iNumComp)
  131.             return null;

  132.         java.lang.String strCurrency = aCalibInst[0].payCurrency();

  133.         for (int i = 0; i < iNumComp; ++i) {
  134.             if (null == aCalibInst[i] || !strCurrency.equalsIgnoreCase (aCalibInst[i].payCurrency()))
  135.                 return null;

  136.             adblRate[i] = 0.02;

  137.             aiDate[i] = aCalibInst[i].maturityDate().julian();
  138.         }

  139.         org.drip.state.discount.ExplicitBootDiscountCurve ebdc =
  140.             org.drip.state.creator.ScenarioDiscountCurveBuilder.PiecewiseForward (new
  141.                 org.drip.analytics.date.JulianDate (valParams.valueDate()), strCurrency, aiDate, adblRate);

  142.         if (!org.drip.state.nonlinear.NonlinearCurveBuilder.DiscountCurve (valParams, aCalibInst,
  143.             adblCalibQuote, astrCalibMeasure, dblBump, false, ebdc, gc, lsfc, vcp))
  144.             return null;

  145.         ebdc.setCCIS (org.drip.analytics.input.BootCurveConstructionInput.Create (valParams, vcp, aCalibInst,
  146.             adblCalibQuote, astrCalibMeasure, lsfc));

  147.         return ebdc;
  148.     }

  149.     /**
  150.      * Calibrate an array of tenor bumped discount curves
  151.      *
  152.      * @param valParams Valuation Parameters
  153.      * @param aCalibInst Array of Calibratable Components
  154.      * @param adblCalibQuote Array of component quotes
  155.      * @param astrCalibMeasure Array of the calibration measures
  156.      * @param dblBump Quote bump
  157.      * @param gc Govvie Curve
  158.      * @param lsfc Latent State Fixings Container
  159.      * @param vcp Valuation Customization Parameters
  160.      *
  161.      * @return Array of tenor bumped discount curves
  162.      */

  163.     public static final org.drip.state.discount.MergedDiscountForwardCurve[] Tenor (
  164.         final org.drip.param.valuation.ValuationParams valParams,
  165.         final org.drip.product.definition.CalibratableComponent[] aCalibInst,
  166.         final double[] adblCalibQuote,
  167.         final java.lang.String[] astrCalibMeasure,
  168.         final double dblBump,
  169.         final org.drip.state.govvie.GovvieCurve gc,
  170.         final org.drip.param.market.LatentStateFixingsContainer lsfc,
  171.         final org.drip.param.valuation.ValuationCustomizationParams vcp)
  172.     {
  173.         if (null == aCalibInst || !org.drip.numerical.common.NumberUtil.IsValid (dblBump)) return null;

  174.         int iNumComp = aCalibInst.length;
  175.         org.drip.state.discount.MergedDiscountForwardCurve[] aDiscountCurve = new
  176.             org.drip.state.discount.MergedDiscountForwardCurve[iNumComp];

  177.         if (0 == iNumComp || adblCalibQuote.length != iNumComp || astrCalibMeasure.length != iNumComp)
  178.             return null;

  179.         for (int i = 0; i < iNumComp; ++i) {
  180.             double[] adblTenorQuote = new double [iNumComp];

  181.             for (int j = 0; j < iNumComp; ++j)
  182.                 adblTenorQuote[j] = adblCalibQuote[j] + (j == i ? dblBump : 0.);

  183.             if (null == (aDiscountCurve[i] = Standard (valParams, aCalibInst, adblTenorQuote,
  184.                 astrCalibMeasure, 0., gc, lsfc, vcp)))
  185.                 return null;
  186.         }

  187.         return aDiscountCurve;
  188.     }

  189.     /**
  190.      * Calibrate a tenor map of tenor bumped discount curves
  191.      *
  192.      * @param valParams ValuationParams
  193.      * @param aCalibInst Array of Calibratable Components
  194.      * @param adblCalibQuote Array of component quotes
  195.      * @param astrCalibMeasure Array of the calibration measures
  196.      * @param dblBump Quote bump
  197.      * @param gc Govvie Curve
  198.      * @param lsfc Latent State Fixings Container
  199.      * @param vcp Valuation Customization Parameters
  200.      *
  201.      * @return Tenor map of tenor bumped discount curves
  202.      */

  203.     public static final
  204.         org.drip.analytics.support.CaseInsensitiveTreeMap<org.drip.state.discount.MergedDiscountForwardCurve> TenorMap (
  205.             final org.drip.param.valuation.ValuationParams valParams,
  206.             final org.drip.product.definition.CalibratableComponent[] aCalibInst,
  207.             final double[] adblCalibQuote,
  208.             final java.lang.String[] astrCalibMeasure,
  209.             final double dblBump,
  210.             final org.drip.state.govvie.GovvieCurve gc,
  211.             final org.drip.param.market.LatentStateFixingsContainer lsfc,
  212.             final org.drip.param.valuation.ValuationCustomizationParams vcp)
  213.     {
  214.         if (null == aCalibInst || null == adblCalibQuote || !org.drip.numerical.common.NumberUtil.IsValid
  215.             (dblBump))
  216.             return null;

  217.         int iNumComp = aCalibInst.length;

  218.         if (0 == iNumComp || adblCalibQuote.length != iNumComp) return null;

  219.         org.drip.analytics.support.CaseInsensitiveTreeMap<org.drip.state.discount.MergedDiscountForwardCurve>
  220.             mapTenorDiscountCurve = new
  221.                 org.drip.analytics.support.CaseInsensitiveTreeMap<org.drip.state.discount.MergedDiscountForwardCurve>();

  222.         for (int i = 0; i < iNumComp; ++i) {
  223.             double[] adblTenorQuote = new double [iNumComp];

  224.             for (int j = 0; j < iNumComp; ++j)
  225.                 adblTenorQuote[j] = adblCalibQuote[j] + (j == i ? dblBump : 0.);

  226.             mapTenorDiscountCurve.put (org.drip.analytics.date.DateUtil.YYYYMMDD
  227.                 (aCalibInst[i].maturityDate().julian()), Standard (valParams, aCalibInst, adblTenorQuote,
  228.                     astrCalibMeasure, 0., gc, lsfc, vcp));
  229.         }

  230.         return mapTenorDiscountCurve;
  231.     }
  232. }