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

  98. public class OvernightState {

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

  104.         String strCurrency = "EUR";

  105.         JulianDate dtSpot = DateUtil.CreateFromYMD (
  106.             2017,
  107.             DateUtil.DECEMBER,
  108.             21
  109.         );

  110.         String[] astrDepositMaturityTenor = new String[] {
  111.             "1D",
  112.             // "2D",
  113.             "3D"
  114.         };

  115.         double[] adblDepositQuote = new double[] {
  116.             0.0004,     // 1D
  117.             // 0.0004,      // 2D
  118.             0.0004      // 3D
  119.         };

  120.         String[] astrShortEndOISMaturityTenor = new String[] {
  121.             "1W",
  122.             "2W",
  123.             "3W",
  124.             "1M"
  125.         };

  126.         double[] adblShortEndOISQuote = new double[] {
  127.             0.00070,    //   1W
  128.             0.00069,    //   2W
  129.             0.00078,    //   3W
  130.             0.00074     //   1M
  131.         };

  132.         String[] astrOISFuturesEffectiveTenor = new String[] {
  133.             "1M",
  134.             "2M",
  135.             "3M",
  136.             "4M",
  137.             "5M"
  138.         };

  139.         String[] astrOISFuturesMaturityTenor = new String[] {
  140.             "1M",
  141.             "1M",
  142.             "1M",
  143.             "1M",
  144.             "1M"
  145.         };

  146.         double[] adblOISFuturesQuote = new double[] {
  147.              0.00046,    //   1M x 1M
  148.              0.00016,    //   2M x 1M
  149.             -0.00007,    //   3M x 1M
  150.             -0.00013,    //   4M x 1M
  151.             -0.00014     //   5M x 1M
  152.         };

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

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

  193.         MergedDiscountForwardCurve dcOvernight = LatentMarketStateBuilder.SmoothOvernightCurve (
  194.             dtSpot,
  195.             strCurrency,
  196.             astrDepositMaturityTenor,
  197.             adblDepositQuote,
  198.             "Rate",
  199.             astrShortEndOISMaturityTenor,
  200.             adblShortEndOISQuote,
  201.             "SwapRate",
  202.             astrOISFuturesEffectiveTenor,
  203.             astrOISFuturesMaturityTenor,
  204.             adblOISFuturesQuote,
  205.             "SwapRate",
  206.             astrLongEndOISMaturityTenor,
  207.             adblLongEndOISQuote,
  208.             "SwapRate"
  209.         );

  210.         String strLatentStateLabel = dcOvernight.label().fullyQualifiedName();

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

  212.         for (int i = 0; i < adblDepositQuote.length; ++i)
  213.             System.out.println (
  214.                 "\t||  " + strLatentStateLabel +
  215.                 " |  DEPOSIT  | " + astrDepositMaturityTenor[i] + "  | " +
  216.                 FormatUtil.FormatDouble (adblDepositQuote[i], 1, 4, 1.) +
  217.                 " | Forward Rate | " +
  218.                 FormatUtil.FormatDouble (dcOvernight.df (astrDepositMaturityTenor[i]), 1, 10, 1.) +
  219.                 "  ||"
  220.             );

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

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

  223.         for (int i = 0; i < adblShortEndOISQuote.length; ++i)
  224.             System.out.println (
  225.                 "\t||  " + strLatentStateLabel + " |  SHORT END OIS  | " +
  226.                 astrShortEndOISMaturityTenor[i] + "  | " + FormatUtil.FormatDouble (adblShortEndOISQuote[i], 1, 5, 1.) +
  227.                 " | Swap Rate | " +
  228.                 FormatUtil.FormatDouble (dcOvernight.df (astrShortEndOISMaturityTenor[i]), 1, 6, 1.) +
  229.                 "  ||"
  230.             );

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

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

  233.         for (int i = 0; i < adblOISFuturesQuote.length; ++i)
  234.             System.out.println (
  235.                 "\t||  " + strLatentStateLabel + " |  OIS FUTURES  | " +
  236.                 FormatUtil.FormatDouble (adblOISFuturesQuote[i], 1, 6, 1.) +
  237.                 " | " + astrOISFuturesEffectiveTenor[i] + " x " + astrOISFuturesMaturityTenor[i] +
  238.                 " | Swap Rate | " +
  239.                 FormatUtil.FormatDouble (
  240.                     dcOvernight.df (dtSpot.addTenor (astrOISFuturesEffectiveTenor[i]).addTenor (astrOISFuturesMaturityTenor[i])
  241.                 ), 1, 6, 1.) +
  242.                 "  ||"
  243.             );

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

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

  246.         for (int i = 0; i < adblLongEndOISQuote.length; ++i)
  247.             System.out.println (
  248.                 "\t||  " + strLatentStateLabel + " |  LONG END OIS  | " +
  249.                 astrLongEndOISMaturityTenor[i] + " | " + FormatUtil.FormatDouble (adblLongEndOISQuote[i], 1, 5, 1.) +
  250.                 " | Swap Rate | " +
  251.                 FormatUtil.FormatDouble (dcOvernight.df (astrLongEndOISMaturityTenor[i]), 1, 4, 1.) +
  252.                 "  ||"
  253.             );

  254.         System.out.println ("\t||---------------------------------------------------------------||\n");
  255.     }
  256. }