SurvivalRecoveryState.java

  1. package org.drip.template.state;

  2. import org.drip.analytics.date.*;
  3. import org.drip.numerical.common.FormatUtil;
  4. import org.drip.service.env.EnvManager;
  5. import org.drip.service.template.LatentMarketStateBuilder;
  6. import org.drip.state.credit.CreditCurve;
  7. import org.drip.state.discount.MergedDiscountForwardCurve;

  8. /*
  9.  * -*- mode: java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
  10.  */

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

  84. /**
  85.  * <i>SurvivalRecoveryState</i> sets up the Calibration and the Construction of the Survival and the Recovery
  86.  * Latent States and examine the Emitted Metrics.
  87.  *
  88.  *  <br><br>
  89.  *  <ul>
  90.  *      <li><b>Module </b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/ProductCore.md">Product Core Module</a></li>
  91.  *      <li><b>Library</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/FixedIncomeAnalyticsLibrary.md">Fixed Income Analytics</a></li>
  92.  *      <li><b>Project</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/template/README.md">Pricing/Risk Templates for Fixed Income Component Products</a></li>
  93.  *      <li><b>Package</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/template/state/README.md">Standard Latent State Construction Template</a></li>
  94.  *  </ul>
  95.  * <br><br>
  96.  *
  97.  * @author Lakshmi Krishnamurthy
  98.  */

  99. public class SurvivalRecoveryState {

  100.     private static final MergedDiscountForwardCurve OvernightCurve (
  101.         final JulianDate dtSpot,
  102.         final String strCurrency)
  103.         throws Exception
  104.     {
  105.         EnvManager.InitEnv ("");

  106.         String[] astrDepositMaturityTenor = new String[] {
  107.             "1D",
  108.             // "2D",
  109.             "3D"
  110.         };

  111.         double[] adblDepositQuote = new double[] {
  112.             0.0004,     // 1D
  113.             // 0.0004,      // 2D
  114.             0.0004      // 3D
  115.         };

  116.         String[] astrShortEndOISMaturityTenor = new String[] {
  117.             "1W",
  118.             "2W",
  119.             "3W",
  120.             "1M"
  121.         };

  122.         double[] adblShortEndOISQuote = new double[] {
  123.             0.00070,    //   1W
  124.             0.00069,    //   2W
  125.             0.00078,    //   3W
  126.             0.00074     //   1M
  127.         };

  128.         String[] astrOISFuturesEffectiveTenor = new String[] {
  129.             "1M",
  130.             "2M",
  131.             "3M",
  132.             "4M",
  133.             "5M"
  134.         };

  135.         String[] astrOISFuturesMaturityTenor = new String[] {
  136.             "1M",
  137.             "1M",
  138.             "1M",
  139.             "1M",
  140.             "1M"
  141.         };

  142.         double[] adblOISFuturesQuote = new double[] {
  143.              0.00046,    //   1M x 1M
  144.              0.00016,    //   2M x 1M
  145.             -0.00007,    //   3M x 1M
  146.             -0.00013,    //   4M x 1M
  147.             -0.00014     //   5M x 1M
  148.         };

  149.         String[] astrLongEndOISMaturityTenor = new String[] {
  150.             "15M",
  151.             "18M",
  152.             "21M",
  153.             "02Y",
  154.             "03Y",
  155.             "04Y",
  156.             "05Y",
  157.             "06Y",
  158.             "07Y",
  159.             "08Y",
  160.             "09Y",
  161.             "10Y",
  162.             "11Y",
  163.             "12Y",
  164.             "15Y",
  165.             "20Y",
  166.             "25Y",
  167.             "30Y"
  168.         };

  169.         double[] adblLongEndOISQuote = new double[] {
  170.             0.00002,    //  15M
  171.             0.00008,    //  18M
  172.             0.00021,    //  21M
  173.             0.00036,    //   2Y
  174.             0.00127,    //   3Y
  175.             0.00274,    //   4Y
  176.             0.00456,    //   5Y
  177.             0.00647,    //   6Y
  178.             0.00827,    //   7Y
  179.             0.00996,    //   8Y
  180.             0.01147,    //   9Y
  181.             0.01280,    //  10Y
  182.             0.01404,    //  11Y
  183.             0.01516,    //  12Y
  184.             0.01764,    //  15Y
  185.             0.01939,    //  20Y
  186.             0.02003,    //  25Y
  187.             0.02038     //  30Y
  188.         };

  189.         return LatentMarketStateBuilder.SmoothOvernightCurve (
  190.             dtSpot,
  191.             strCurrency,
  192.             astrDepositMaturityTenor,
  193.             adblDepositQuote,
  194.             "Rate",
  195.             astrShortEndOISMaturityTenor,
  196.             adblShortEndOISQuote,
  197.             "SwapRate",
  198.             astrOISFuturesEffectiveTenor,
  199.             astrOISFuturesMaturityTenor,
  200.             adblOISFuturesQuote,
  201.             "SwapRate",
  202.             astrLongEndOISMaturityTenor,
  203.             adblLongEndOISQuote,
  204.             "SwapRate"
  205.         );
  206.     }

  207.     public static final void main (
  208.         final String[] astrArgs)
  209.         throws Exception
  210.     {
  211.         /*
  212.          * Initialize the Credit Analytics Library
  213.          */

  214.         EnvManager.InitEnv ("");

  215.         String strCurrency = "EUR";

  216.         JulianDate dtSpot = DateUtil.CreateFromYMD (
  217.             2017,
  218.             DateUtil.DECEMBER,
  219.             21
  220.         );

  221.         /* JulianDate dtSpot = DateUtil.Today().addBusDays (
  222.             2,
  223.             strCurrency
  224.         ); */

  225.         MergedDiscountForwardCurve dcOvernight = OvernightCurve (
  226.             dtSpot,
  227.             strCurrency
  228.         );

  229.         String[] astrCDSMaturityTenor = new String[] {
  230.             "06M",
  231.             "01Y",
  232.             "02Y",
  233.             "03Y",
  234.             "04Y",
  235.             "05Y",
  236.             "07Y",
  237.             "10Y"
  238.         };

  239.         double[] adblCDSParSpread = new double[] {
  240.              60.,   //  6M
  241.              68.,   //  1Y
  242.              88.,   //  2Y
  243.             102.,   //  3Y
  244.             121.,   //  4Y
  245.             138.,   //  5Y
  246.             168.,   //  7Y
  247.             188.    // 10Y
  248.         };

  249.         CreditCurve cc = LatentMarketStateBuilder.CreditCurve (
  250.             dtSpot,
  251.             "QTX",
  252.             astrCDSMaturityTenor,
  253.             adblCDSParSpread,
  254.             adblCDSParSpread,
  255.             "FairPremium",
  256.             dcOvernight
  257.         );

  258.         String strLatentStateLabel = cc.label().fullyQualifiedName();

  259.         System.out.println ("\n\n\t||----------------------------------------------------------||");

  260.         for (int i = 0; i < adblCDSParSpread.length; ++i)
  261.             System.out.println (
  262.                 "\t||  " + strLatentStateLabel +
  263.                 " |  CDS  | " + astrCDSMaturityTenor[i] + "  | " +
  264.                 FormatUtil.FormatDouble (adblCDSParSpread[i], 3, 1, 1.) +
  265.                 " | Fair Premium | " +
  266.                 FormatUtil.FormatDouble (cc.survival (astrCDSMaturityTenor[i]), 1, 6, 1.) +
  267.                 "  ||"
  268.             );

  269.         System.out.println ("\t||----------------------------------------------------------||\n");
  270.     }
  271. }