FundingState.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.discount.MergedDiscountForwardCurve;

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

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

  83. /**
  84.  * <i>FundingState</i> sets up the Calibration of the Funding Latent State and examine the Emitted Metrics.
  85.  *
  86.  *  <br><br>
  87.  *  <ul>
  88.  *      <li><b>Module </b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/ProductCore.md">Product Core Module</a></li>
  89.  *      <li><b>Library</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/FixedIncomeAnalyticsLibrary.md">Fixed Income Analytics</a></li>
  90.  *      <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>
  91.  *      <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>
  92.  *  </ul>
  93.  * <br><br>
  94.  *
  95.  * @author Lakshmi Krishnamurthy
  96.  */

  97. public class FundingState {

  98.     public static final void main (
  99.         final String[] astrArgs)
  100.         throws Exception
  101.     {
  102.         EnvManager.InitEnv ("");

  103.         String strCurrency = "USD";

  104.         JulianDate dtSpot = DateUtil.Today().addBusDays (
  105.             0,
  106.             strCurrency
  107.         );

  108.         String[] astrDepositMaturityTenor = new String[] {
  109.             "01D",
  110.             "04D",
  111.             "07D",
  112.             "14D",
  113.             "30D",
  114.             "60D"
  115.         };

  116.         double[] adblDepositQuote = new double[] {
  117.             0.0013,     //  1D
  118.             0.0017,     //  2D
  119.             0.0017,     //  7D
  120.             0.0018,     // 14D
  121.             0.0020,     // 30D
  122.             0.0023      // 60D
  123.         };

  124.         double[] adblFuturesQuote = new double[] {
  125.             0.0027,
  126.             0.0032,
  127.             0.0041,
  128.             0.0054,
  129.             0.0077,
  130.             0.0104,
  131.             0.0134,
  132.             0.0160
  133.         };

  134.         String[] astrFixFloatMaturityTenor = new String[] {
  135.             "04Y",
  136.             "05Y",
  137.             "06Y",
  138.             "07Y",
  139.             "08Y",
  140.             "09Y",
  141.             "10Y",
  142.             "11Y",
  143.             "12Y",
  144.             "15Y",
  145.             "20Y",
  146.             "25Y",
  147.             "30Y",
  148.             "40Y",
  149.             "50Y"
  150.         };

  151.         double[] adblFixFloatQuote = new double[] {
  152.             0.0166,     //   4Y
  153.             0.0206,     //   5Y
  154.             0.0241,     //   6Y
  155.             0.0269,     //   7Y
  156.             0.0292,     //   8Y
  157.             0.0311,     //   9Y
  158.             0.0326,     //  10Y
  159.             0.0340,     //  11Y
  160.             0.0351,     //  12Y
  161.             0.0375,     //  15Y
  162.             0.0393,     //  20Y
  163.             0.0402,     //  25Y
  164.             0.0407,     //  30Y
  165.             0.0409,     //  40Y
  166.             0.0409      //  50Y
  167.         };

  168.         MergedDiscountForwardCurve dcFunding = LatentMarketStateBuilder.SmoothFundingCurve (
  169.             dtSpot,
  170.             strCurrency,
  171.             astrDepositMaturityTenor,
  172.             adblDepositQuote,
  173.             "ForwardRate",
  174.             adblFuturesQuote,
  175.             "ForwardRate",
  176.             astrFixFloatMaturityTenor,
  177.             adblFixFloatQuote,
  178.             "SwapRate"
  179.         );

  180.         String strLatentStateLabel = dcFunding.label().fullyQualifiedName();

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

  182.         for (int i = 0; i < adblDepositQuote.length; ++i)
  183.             System.out.println (
  184.                 "\t||  " + strLatentStateLabel +
  185.                 " |  DEPOSIT  | " + astrDepositMaturityTenor[i] + "  | " +
  186.                 FormatUtil.FormatDouble (adblDepositQuote[i], 1, 4, 1.) +
  187.                 " | Forward Rate | " +
  188.                 FormatUtil.FormatDouble (dcFunding.df (astrDepositMaturityTenor[i]), 1, 6, 1.) +
  189.                 "  ||"
  190.             );

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

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

  193.         for (int i = 0; i < adblFuturesQuote.length; ++i)
  194.             System.out.println (
  195.                 "\t||  " + strLatentStateLabel + " |  FUTURES  | " +
  196.                 FormatUtil.FormatDouble (adblFuturesQuote[i], 1, 4, 1.) +
  197.                 " | Forward Rate | " +
  198.                 FormatUtil.FormatDouble (dcFunding.df ((3 + 3 * i) + "M"), 1, 6, 1.) +
  199.                 "  ||"
  200.             );

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

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

  203.         for (int i = 0; i < adblFixFloatQuote.length; ++i)
  204.             System.out.println (
  205.                 "\t||  " + strLatentStateLabel +
  206.                 " |  FIX FLOAT  | " + astrFixFloatMaturityTenor[i] + "  | " +
  207.                 FormatUtil.FormatDouble (adblFixFloatQuote[i], 1, 4, 1.) +
  208.                 " | Swap Rate | " +
  209.                 FormatUtil.FormatDouble (dcFunding.df (astrFixFloatMaturityTenor[i]), 1, 6, 1.) +
  210.                 "  ||"
  211.             );

  212.         System.out.println ("\t||--------------------------------------------------------------||\n");
  213.     }
  214. }