Tirunelveli.java

  1. package org.drip.sample.bondmetrics;

  2. import org.drip.analytics.date.*;
  3. import org.drip.param.valuation.ValuationParams;
  4. import org.drip.product.creator.BondBuilder;
  5. import org.drip.product.credit.BondComponent;
  6. import org.drip.service.env.EnvManager;
  7. import org.drip.service.scenario.*;

  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.  *
  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>Tirunelveli</i> generates the Full Suite of Replication Metrics for Bond Tirunelveli.
  84.  *  
  85.  * <br><br>
  86.  *  <ul>
  87.  *      <li><b>Module </b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/ProductCore.md">Product Core Module</a></li>
  88.  *      <li><b>Library</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/FixedIncomeAnalyticsLibrary.md">Fixed Income Analytics</a></li>
  89.  *      <li><b>Project</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/sample/README.md">DROP API Construction and Usage</a></li>
  90.  *      <li><b>Package</b> = <a href = "https://github.com/lakshmiDRIP/DROP/tree/master/src/main/java/org/drip/sample/bondmetrics/README.md">Bond Relative Value Replication Demonstration</a></li>
  91.  *  </ul>
  92.  * <br><br>
  93.  *
  94.  * @author Lakshmi Krishnamurthy
  95.  */

  96. public class Tirunelveli {

  97.     public static final void main (
  98.         final String[] astArgs)
  99.         throws Exception
  100.     {
  101.         EnvManager.InitEnv (
  102.             "",
  103.             true
  104.         );

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

  110.         String[] astrDepositTenor = new String[] {
  111.             "2D"
  112.         };

  113.         double[] adblDepositQuote = new double[] {
  114.             0.0130411 // 2D
  115.         };

  116.         double[] adblFuturesQuote = new double[] {
  117.             0.01345,    // 98.655
  118.             0.01470,    // 98.530
  119.             0.01575,    // 98.425
  120.             0.01660,    // 98.340
  121.             0.01745,    // 98.255
  122.             0.01845     // 98.155
  123.         };

  124.         String[] astrFixFloatTenor = new String[] {
  125.             "02Y",
  126.             "03Y",
  127.             "04Y",
  128.             "05Y",
  129.             "06Y",
  130.             "07Y",
  131.             "08Y",
  132.             "09Y",
  133.             "10Y",
  134.             "11Y",
  135.             "12Y",
  136.             "15Y",
  137.             "20Y",
  138.             "25Y",
  139.             "30Y",
  140.             "40Y",
  141.             "50Y"
  142.         };

  143.         String[] astrGovvieTenor = new String[] {
  144.             "1Y",
  145.             "2Y",
  146.             "3Y",
  147.             "5Y",
  148.             "7Y",
  149.             "10Y",
  150.             "20Y",
  151.             "30Y"
  152.         };

  153.         double[] adblFixFloatQuote = new double[] {
  154.             0.016410, //  2Y
  155.             0.017863, //  3Y
  156.             0.019030, //  4Y
  157.             0.020035, //  5Y
  158.             0.020902, //  6Y
  159.             0.021660, //  7Y
  160.             0.022307, //  8Y
  161.             0.022879, //  9Y
  162.             0.023363, // 10Y
  163.             0.023820, // 11Y
  164.             0.024172, // 12Y
  165.             0.024934, // 15Y
  166.             0.025581, // 20Y
  167.             0.025906, // 25Y
  168.             0.025973, // 30Y
  169.             0.025838, // 40Y
  170.             0.025560  // 50Y
  171.         };

  172.         double[] adblGovvieYield = new double[] {
  173.             0.01219, //  1Y
  174.             0.01391, //  2Y
  175.             0.01590, //  3Y
  176.             0.01937, //  5Y
  177.             0.02200, //  7Y
  178.             0.02378, // 10Y
  179.             0.02677, // 20Y
  180.             0.02927  // 30Y
  181.         };

  182.         String[] astrCreditTenor = new String[] {
  183.             "06M",
  184.             "01Y",
  185.             "02Y",
  186.             "03Y",
  187.             "04Y",
  188.             "05Y",
  189.             "07Y",
  190.             "10Y"
  191.         };

  192.         double[] adblCreditQuote = new double[] {
  193.              60.,   //  6M
  194.              68.,   //  1Y
  195.              88.,   //  2Y
  196.             102.,   //  3Y
  197.             121.,   //  4Y
  198.             138.,   //  5Y
  199.             168.,   //  7Y
  200.             188.    // 10Y
  201.         };

  202.         double dblFX = 1.;
  203.         int iSettleLag = 3;
  204.         int iCouponFreq = 2;
  205.         String strName = "Tirunelveli";
  206.         double dblCleanPrice = 1.09683;
  207.         double dblIssuePrice = 1.;
  208.         String strCurrency = "USD";
  209.         double dblSpreadBump = 20.;
  210.         double dblCouponRate = 0.0691;
  211.         double dblIssueAmount = 7.50e8;
  212.         String strTreasuryCode = "UST";
  213.         String strCouponDayCount = "30/360";
  214.         double dblSpreadDurationMultiplier = 5.;

  215.         JulianDate dtEffective = DateUtil.CreateFromYMD (
  216.             2009,
  217.             9,
  218.             24
  219.         );

  220.         JulianDate dtMaturity = DateUtil.CreateFromYMD (
  221.             2039,
  222.             7,
  223.             1
  224.         );

  225.         BondComponent bond = BondBuilder.CreateSimpleFixed (
  226.             strName,
  227.             strCurrency,
  228.             strName,
  229.             dblCouponRate,
  230.             iCouponFreq,
  231.             strCouponDayCount,
  232.             dtEffective,
  233.             dtMaturity,
  234.             null,
  235.             null
  236.         );

  237.         double dblYield = bond.yieldFromPrice (
  238.             ValuationParams.Spot (dtSpot.julian()),
  239.             null,
  240.             null,
  241.             dblCleanPrice
  242.         );

  243.         System.out.println ("Price In  : " + dblCleanPrice);

  244.         System.out.println ("Yield Out : " + dblYield);

  245.         System.out.println ("Price Out : " +
  246.             bond.priceFromYield (
  247.                 ValuationParams.Spot (dtSpot.julian()),
  248.                 null,
  249.                 null,
  250.                 dblYield
  251.             )
  252.         );

  253.         /* SetEOS (
  254.             bond,
  255.             null,
  256.             null
  257.         ); */

  258.         BondReplicator abr = BondReplicator.CorporateSenior (
  259.             dblCleanPrice,
  260.             dblIssuePrice,
  261.             dblIssueAmount,
  262.             dtSpot,
  263.             astrDepositTenor,
  264.             adblDepositQuote,
  265.             adblFuturesQuote,
  266.             astrFixFloatTenor,
  267.             adblFixFloatQuote,
  268.             dblSpreadBump,
  269.             dblSpreadDurationMultiplier,
  270.             strTreasuryCode,
  271.             astrGovvieTenor,
  272.             adblGovvieYield,
  273.             astrCreditTenor,
  274.             adblCreditQuote,
  275.             dblFX,
  276.             Double.NaN,
  277.             iSettleLag,
  278.             bond
  279.         );

  280.         BondReplicationRun abrr = abr.generateRun();

  281.         System.out.println (abrr.display());

  282.         EnvManager.TerminateEnv();
  283.     }
  284. }